public boolean isWinner(char player)
{
if (board[0] == player && board[1] == player && board[2] == player ||
board[3] == player && board[4] == player && board[5] == player ||
board[6] == player && board[7] == player && board[8] == player ||
board[0] == player && board[3] == player && board[6] == player ||
board[1] == player && board[4] == player && board[7] == player ||
board[2] == player && board[5] == player && board[8] == player )
return true;
return false;
}
/* check to see if the player x is the winner or
the player y is the winner or the cat is the winner
or the game is not over yet and then display the result
you need to write conditional statments*/
public void displayResults()
{
if (isWinner = true)
System.out.print("CONGRATUTIONS " + player + " YOU WON!");
}
嘿,我想知道是否有人可以帮助我如何将“isWinner”结果传递给“displayResults”if语句。如果这是我需要帮助的部分之一,那么这是我们获得分配的井字游戏。
答案 0 :(得分:1)
假设player
是可访问的char
对象...
public void displayResults()
{
if (isWinner(player))
System.out.print("CONGRATULATIONS " + player + " YOU WON!");
// ^^^^
// Fix your typo too
}
答案 1 :(得分:0)
首先,isWinner
应该返回true
或false
,而不是1或0。
其次,
if (isWinner = true)
应该是
if (isWinner(player))
假设player
是代表玩家的字符,因为这是isWinner()
所需要的。