Question
Im trying to create a program to play the game tic tac toe using the visual C++ .Net..Im suppose to contrust a visual representation of the game using the forms and controls in Visual Studio.Net. This should be 2 players. youself and the computer. any choices and desings would work. there should be options to quit and to start all over. You will want to include events for the player making a selection as well as routines to check for the winner, to display a winner, and to change players after a player has taken his or her turn. anyone willing to show how this is done?
Explanation / Answer
Hi Kaumana I have written a code in turbo c++ for tic tac toe.Hope this helps!!! //TIC TAC TOE //include header files #include #include #include //Enum sets human,empty & false as '0' //and machine, full, as '1' enum whoplays{human,machine}; enum cell{empty,full}; enum boolean {false,true}; //recurtion depth int deep=0; //this class represents one border portion class position { private: //cells marked with machine moves cell mcell[9]; //cells marked with human moves cell hcell[9]; //human or machine to play next whoplays player; public: //class constructor position(); //this function checks for win boolean iswin(); //this function checks for legal move boolean islegal(int); //this function is used to make the move void makemove(int); //this function swap player and machine void setplayer(whoplays); //this function displays lines & numbers static void initdisplay(); //this function display board position void display(); //this function scores this position int evaluate(int&); }; //this constructor resets all cells to empty position::position() { for(int j=0;j=0)&&(movestores move //sc->for evaluate() //movecount->no. of move pairs //cursrow-cursor row for text int move,sc,movecout=0,cursrow=0; //creats current position position current; //this displays the board position::initdisplay(); //cycle until game over while(1) { //set player to human current.setplayer(human); current.display(); gotoxy(1,++cursrow); coutmove; if(!current.islegal(move)) { gotoxy(1,++cursrow); cout