My tic-tac-tow board maintains the same values as the last game, instead of reinitializing to the values it is supposed to be assigned in the constructor. (123, 456, 789)
Does anyone have a clue why this may be?
Constructor:
ticTacToe:: ticTacToe()
{
for (int i = 0; i < 1; i++)
for (int j = 0; j < 3; j++)
board[i][j] = 49 + (i + j);
for (int i = 1; i < 2; i++)
for (int j = 0; j < 3; j++)
board[i][j] = 51 + (i + j);
for (int i = 2; i < 3; i++)
for (int j = 0; j < 3; j++)
board[i][j] = 53 + (i + j);
player = 1;
validMove = true;
gameOver = false;
winner = 0;
p1win = 0;
p2win = 0;
tie = 0;
}
member function:
void ticTacToe:: gameLoop()
{
do
{
ticTacToe();
print();
getMove();
alternatePlayer();
winGameCheck();
endGameCheck();
}
while (!gameOver);
endPrint();
}
This constructs a temporary
ticTacToeobject then destroys that temporary object. It doesn’t actually “re-call” the constructor of the current object.I think the correct approach here would be to provide a “
reset()” function that redraws the game board. That said, even that doesn’t make sense since you’d be resetting the game every turn.