I need help on a tic tac toe game. I am trying to figure out how to switch between player one and player two each turn.
1 2 3 4 5 6 7 8 9
char playerMark;
// Switch After Each Move
char playerOne;
for (int i = 1; i < 3; i++) {
if (i == 1)
playerMark = 'x';
else
playerMark = 'o';
}
From that code i can get it to switch from x and o, and i was thinking about looping it another 4 times but that does not work.
My other attempt to first just loop my the getmove function 9 times and each time there will be either an odd or even number. When theres an even number the player's number will turn into an X and when theres an odd it will turn into an O. Then i have to figure out how to get it to correspond with the number on the tic tac toe chart i made. My main problem is figuring how to switch players each turn. Any hint will appreciated. Thank You
void Tictac::getMove()
{
cout << "Enter Box: ";
char c;
cin.get(c);
if (c > '9' || c < '0')
{
// Error message here.
cout << "please enter a number between 1-9";
cin.get(c);
}
int number = c - '0';
cout << "your number is " << isnumber;
// Your implementation here...
char playermark;
int playerNumber;
int i = 2;
i = i % 2;
if (i == 0)
{
playermark = 'x';
playerNumber = 1;
}
else{
playermark = 'o';
playerNumber = 1;
}
i++;
}
Then loop ttt.playgame 9 times
1 2 3 4 5 6 7
int main ()
{
TicTacToe ttt;
// you need to do the following in a loop 9 times
ttt.playGame();
}