Good evening, I am writing a program in C++ for a Tic tac toe game.
Here are my directions:
Create a C++ console application that allows two players to participate in a tic-tac-toe game. The program will be responsible for deciding who wins the game.
The program should include the following class, properties and methods:
class TicTacToe{
private:
char theBoard [3][3];
public:
TicTacToe(void);
void playOneGame(void);
void switchPlayer(char &);
void showBoard(void);
void postMove(int, int, char);
char determineWinner(void);
};
I have it written and I have a few bugs I cannot figure out. It plays and works just fine except when Player X or Player O chooses a space that is already taken it tells them they have to choose another spot but then switches players so the current player has no chance to choose again. I know this is probably a very simple problem but I can't for the life of me figure it out. Here are my switch user function and my post move function.
void TicTacToe:: switchPlayer(char ¤tPlayer){
if(currentPlayer == 'O'){
currentPlayer = 'X';
}
else
currentPlayer = 'O';
}
void TicTacToe::postMove(int row, int col, char value){
if (theBoard[row][col] == '-'){
theBoard[row][col] = value;
}
else
cout << "Space is already taken, please choose a different one." << endl;
I have tried several different if statements in my switchPlayer function but none seemed to work. Can anyone point me in the right direction?