伙计们,我正在用Java编写Gomoku游戏,我有点陷入了一个愚蠢的问题。我希望玩家能够阻止一个字段,所以我制作了两个方法,两个方法都是boolean:
DoYouWishToBlockAField和BlockingField。我想这样做,以便当第一个为真时,我转到第二个,当它是假的时,当然,打破操作并且不阻止任何字段。你能帮帮我吗?
public static void DoYouWishToBlockAField(){
if(true){
BlockingField();
} else (false);
在这里我收到错误消息,我一直想知道如何做对。
}
public static void BlockingField(int theSeed) {
boolean validInput = false; // for input validation
do {
if (theSeed == BlockedField1) {
System.out.print("Player 1: Block a Field: ");
} else{
System.out.print("Player 2: Block a Field: ");
}
int row = in.nextInt() - 1; // array index starts at 0 instead of 1
int col = in.nextInt() - 1;
if (row >= 0 && row < ROWS && col >= 0 && col < COLS && board[row][col] == Empty) {
currentRow = row;
currentCol = col;
board[currentRow][currentCol] = theSeed; // update game-board content
validInput = true; // input okay, exit loop
} else {
System.out.println("The cell at (" + (row + 1) + "," + (col + 1)
+ ") is taken. Try another move.");
}
} while (!validInput); // repeat until input is valid
}
答案 0 :(得分:0)
在调用函数时使用参数名称
BlockingField(parameterName);