【发布时间】:2015-05-15 18:31:29
【问题描述】:
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 语句。这是一个井字游戏,如果这是我需要帮助的部分之一,我们会分配给它。
【问题讨论】:
-
你需要看一些java的基础教程。尝试用谷歌搜索类似
get return value of method java -
作为参数传递给
displayResults()方法?来吧,它太基础了,你需要先尝试一些java教程。 -
当方法需要 boolean 时,你如何返回 0 和 1?
-
是的,关于 1 和 0 抱歉,我正在处理我的一些想法,忘记恢复这些想法
-
isWinner = true 与 isWinner == true 不同
标签: java if-statement methods tic-tac-toe