私はループ中にこれを終了するように見えません。私は知っているすべての方法を試しましたが、まだ動作していません。変数 "contGame"はすでに "false"に変更されていても "true"に変化し続けています。あなたは私を助けることができます!これはクラスの内部にあることに注意してください。ここに私のコードです:whileループを終了できません(C++)
while (contGame == true)
{
if (turn == 1)
{
cout << Board._player1Name <<"'s turn!!\n";
X = getMoveX();
Y = getMoveY();
Board.Board[X][Y] = player1Sign;
Board.printBoard();
turn = turn + 1;
Board.checkGame(contGame, player1Sign, player2Sign);
if (checkGame(contGame, player1Sign, player2Sign) == false)
{
bool contGame = false;
cout << contGame << endl;
}
}
cout << contGame << endl;
if(turn == 2)
{
cout << Board._player2Name <<"'s turn!!\n";
X = getMoveX();
Y = getMoveY();
Board.Board[X][Y] = player2Sign;
Board.printBoard();
turn = turn - 1;
Board.checkGame(contGame, player1Sign, player2Sign);
if (checkGame(contGame, player1Sign, player2Sign) == false)
{
int contGame = 1;
cout << contGame << endl;
}
}
}
そして、これはcheckGameです:
bool contGameA = true;
for (int k = 0; k < 3; k++)
{
if (Board[k][0] == Board[k][1] && Board[k][1] == Board[k][2] && Board[k][2] == player1Sign)
{
cout << "\\\\" << _player1Name <<" wins!////\n";
contGameA = false;
}
else if (Board[k][0] == Board[k][1] && Board[k][1] == Board[k][2] && Board[k][2] == player2Sign)
{
cout << "\\\\" << _player2Name << " wins!////\n";
contGameA = false;
}
}
for (int r = 0; r < 3; r++)
{
if (Board[0][r] == Board[1][r] && Board[1][r] == Board[2][r] && Board[2][r] == player1Sign)
{
cout << "\\\\" << _player1Name << " wins!////\n";
contGameA = false;
}
else if (Board[0][r] == Board[1][r] && Board[1][r] == Board[2][r] && Board[2][r] == player2Sign)
{
cout << "\\\\" << _player2Name << " wins!////\n";
contGameA = false;
}
}
if (Board[0][0] == Board[1][1] && Board[1][1] == Board[2][2] && Board[2][2] == player1Sign)
{
cout << "\\\\" << _player1Name << " wins!////\n";
contGameA = false;
} else if (Board[0][0] == Board[1][1] && Board[1][1] == Board[2][2] && Board[2][2] == player2Sign)
{
cout << "\\\\" << _player2Name << " wins!////\n";
contGameA = false;
}
if (Board[0][2] == Board[1][1] && Board[1][1] == Board[2][0] && Board[2][0] == player1Sign)
{
cout << "\\\\" << _player1Name << " wins!////\n";
contGameA = false;
} else if (Board[0][2] == Board[1][1] && Board[1][1] == Board[2][0] && Board[2][0] == player2Sign)
{
cout << "\\\\" << _player2Name << " wins!////\n";
contGameA = false;
}
return contGameA;
を置きます「最小」部分のために。転記する前に、可能な限りコードを短くする必要があります(もちろん、エラーを再現してください)。 – Angew