Saturday, May 9, 2009

C++???????

I am trying to make a tic tac toe game for c++ but i don't know how to use an array to make the board. also after i make the board hiw do i code it so each player can take turns picking a square.

C++???????
if you dont know how to use an array in c++ you might want to start with something a little more basic.....
Reply:You will probably want to declare a two-dimensional array... like this...





Int ** board = new int[3][3];





That declares an array of int arrays. 3x3





Then you will want to have a loop that alternates between players and only exits when the game is over.
Reply:I believe you could make an integer array to keep track of who has what place.


0 - Empty space


1 - O


2 - X


Of course you could just leave the initial values of the entries as null.





As for the taking turns you could use simple integers to keep track of whose turn it is. Perhaps do a ++ to some variable then take the mod of that variable to determine whose turn it is. i.e. if # is odd it's X's turn else if # is even it's O's turn
Reply:you should code every square from 1 to 3 and you should add your i %26amp; g


No comments:

Post a Comment