I'm trying to create a classic tic tac toe game using classes. I established my array thru a default constructor, when I try to display the game board from another public function in the class I get random symbols like these '&♥'. (I know I'm missing functions and all but I can't figure this step out!) Here is my program output: OUTPUT and program:
class TicTacToe
{
private:
char board[3][3];
char player;
public:
void getBoard();
char changePlayer(char);
void setPosition(int, int);
TicTacToe();
};
int main ()
{
bool endOfGame = false;
int rows;
int columns;
int test;
TicTacToe ttt;
while (!endOfGame)
{
cout << "Please enter the row number: ";
cin >> rows;
cout << "Please enter the column number: ";
cin >> columns;
ttt.setPosition(rows, columns);
ttt.getBoard();
}
return 0;
}
TicTacToe::TicTacToe()
{
char board[3][3] = {'*','*','*',
'*','*','*',
'*','*','*',};
player = 'x';
}
void TicTacToe::getBoard()
{
for (int i = 0; i < 3; i++)
{
for (int c = 0; c < 3; c++)
{
cout << board[i][c];
}
cout << endl;
}
}
char TicTacToe::changePlayer(char choice)
{
}
void TicTacToe::setPosition(int row, int column)
{
if (player == 'x')
{ board[row][column] = 'x'; }
else
{ board[row][column] = 'o'; }
}