Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // functions.cpp
- #include "stdafx.h"
- #include "declare.h"
- //initalizate the board
- void Init(char *arr)
- {
- for(int i = 0;i < 9;i++)
- {
- arr[i] = i+100;
- }
- }
- //prints the board
- void Print(char *arr)
- {
- cout<<"this is the real board"<<endl;
- for(int i = 0;i< 9;i++)
- {
- cout<<arr[i];
- if(i == 2 || i == 5 || i ==8)
- {
- cout<<endl;
- }
- }
- cout<<endl;
- cout<<"this is your keyboard"<<endl;
- for(int count = 1;count <= 9;count++)
- {
- cout<<count;
- if(count == 3 || count == 6 || count ==9)
- cout<<endl;
- }
- cout<<"The numbers represnt each box"<<endl;
- }
- //checking if there is any winner
- int CheckWinnerX(char *arr)
- {
- if(arr[0] = arr[3] && arr[0] == arr[6]== 'X')
- {
- cout<<"the winner is"<<arr[0];
- return 1;
- }
- else if(arr[0] == arr[1] == arr[2]== 'X')
- {
- cout<<"the winner is"<<arr[0];
- return 1;
- }
- else if(arr[2] == arr[5] == arr[8]== 'X')
- {
- cout<<"the winner is"<<arr[2];
- return 1;
- }
- else if(arr[6] == arr[7] == arr[8]== 'X')
- {
- cout<<"the winner is"<<arr[6];
- return 1;
- }
- else if(arr[0] == arr[4] == arr[8]== 'X')
- {
- cout<<"the winner is"<<arr[0];
- return 1;
- }
- else if(arr[2] == arr[4] == arr[6]== 'X')
- {
- cout<<"the winner is"<<arr[2];
- return 1;
- }
- else if(arr[1] == arr[4] == arr[7]== 'X')
- {
- cout<<"the winner is"<<arr[1];
- return 1;
- }
- else if(arr[3] == arr[4] == arr[5]== 'X')
- {
- cout<<"the winner is"<<arr[3];
- return 1;
- }
- else
- return 0;
- }
- //
- int CheckWinner0(char *arr)
- {
- if(arr[0] == arr[3] == arr[6]== '0')
- {
- cout<<"the winner is"<<arr[0];
- return 1;
- }
- else if(arr[0] == arr[1] == arr[2]== '0')
- {
- cout<<"the winner is"<<arr[0];
- return 1;
- }
- else if(arr[2] == arr[5] == arr[8]== '0')
- {
- cout<<"the winner is"<<arr[2];
- return 1;
- }
- else if(arr[6] == arr[7] == arr[8]== '0')
- {
- cout<<"the winner is"<<arr[6];
- return 1;
- }
- else if(arr[0] == arr[4] == arr[8]== '0')
- {
- cout<<"the winner is"<<arr[0];
- return 1;
- }
- else if(arr[2] == arr[4] == arr[6]== '0')
- {
- cout<<"the winner is"<<arr[2];
- return 1;
- }
- else if(arr[1] == arr[4] == arr[7]== '0')
- {
- cout<<"the winner is"<<arr[1];
- return 1;
- }
- else if(arr[3] == arr[4] == arr[5]== '0')
- {
- cout<<"the winner is"<<arr[3];
- return 1;
- }
- else
- return 0;
- }
- //declare.h
- #ifndef DECLARE_H
- #define DECLARE_H
- //headers
- #include <iostream>
- using namespace std;
- //functions
- void Init(char *arr);
- void Print(char *arr);
- int CheckWinnerX(char *arr);
- int CheckWinner0(char *arr);
- #endif
- //main.cpp
- #include "stdafx.h"
- #include "declare.h"
- int main()
- {
- char board[9];
- char *pBoard = &board[0];
- Init(pBoard);
- Print(pBoard);
- int check = 0; //checking if there is any winner
- cout<<"pls, choose between you who is the x anad who is the 0"<<endl; //instructions
- cout<<"after you have chosen,Lets start :)"<<endl;
- while(check == 0)
- {
- cout<<"X pls enter number which represents the box you have chosen"<<endl;
- int numBox;
- cin>>numBox;
- board[numBox-1] = 'X';
- Print(pBoard);
- check = CheckWinnerX(pBoard);
- if(check != 0) continue;
- cout<<"0 pls enter number which represents the box you have chosen"<<endl;
- cin>>numBox;
- board[numBox-1] = '0';
- Print(pBoard);
- check = CheckWinner0(pBoard);
- if(check != 0) continue;
- }
- // cout<<"Nice game,the winner is: "<<
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment