伙计们,我正在用 Java 编写五子棋游戏,但我遇到了一个愚蠢的问题。我希望玩家能够阻止一个字段,所以我做了两种方法,它们都是布尔值:
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
}