こんにちは、この三目並べプロジェクトを仕上げていますが、checkWin メソッドのボード クラスに 1 つのエラーがあります。Int と String の非互換エラーとして表示されます。Integer.toString() コマンドを使用して他のボード ラインでこれを修正しましたが、これでは機能しません。何か案は?checkWin メソッドのコードは次のとおりです。
public boolean checkWin()
{
{
int i; // i = column
int j; // j = row
int count;
int winner;
winner = empty; // nobody has won yet
// Check all rows to see if same player has occupied every square.
for (j = 0; j < boardSize; j ++)
{
count = 0;
if (board[j][0] != Integer.toString(empty))
for (i = 0; i < boardSize; i ++)
if (board[j][0] == board[j][i])
count ++;
if (count == boardSize)
winner = (board[j][0]);
}
// Check all columns to see if same player has occupied every square.
for (i = 0; i < boardSize; i ++)
{
count = 0;
if (board[0][i] != Integer.toString(empty))
for (j = 0; j < boardSize; j ++)
if (board[0][i] == board[j][i])
count ++;
if (count == boardSize)
winner = board[0][i];
}
// Check diagonal from top-left to bottom-right.
count = 0;
if (board[0][0] != Integer.toString(empty))
for (j = 0; j < boardSize; j ++)
if (board[0][0] == board[j][j])
count ++;
if (count == boardSize)
winner = board[0][0];
// Check diagonal from top-right to bottom-left.
count = 0;
if (board[0][boardSize-1] != Integer.toString(empty))
for (j = 0; j < boardSize; j ++)
if (board[0][boardSize-1] == board[j][boardSize-j-1])
count ++;
if (count == boardSize)
winner = board[0][boardSize-1];
// Did we find a winner?
if (winner != empty)
{
if (winner == Xstr)
System.out.println("\nCongratulations! P1 You win!");
else if (winner == Ostr)
System.out.println("\nCongratulations! P2 You win!");
else
return true;
}
}