我試圖在正常的tic tac toe遊戲中每轉之後使X和O的交替,但是當我運行它時,發生的只是它在每次轉動後都會繼續輸出X 。這是爲什麼發生?如何使X和O的交替
import java.util.Scanner;
public class TicTacToe{
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
Scanner numreader = new Scanner(System.in);
TicTacToeBoard board = new TicTacToeBoard(620,720);
board.setFiles("X.png", "O.jpeg");
int[][] lines = new int[4][4];
lines[0][0] = 0;
lines[0][1] = 200;
lines[0][2] = 600;
lines[0][3] = 200;
lines[1][0] = 0;
lines[1][1] = 400;
lines[1][2] = 800;
lines[1][3] = 400;
lines[2][0] = 200;
lines[2][1] = 600;
lines[2][2] = 200;
lines[2][3] = 0;
lines[3][0] = 400;
lines[3][1] = 600;
lines[3][2] = 400;
lines[3][3] = 0;
board.defineBoard(lines);
int counter = 0;
char[][] arr= {
{'-','-','-'},
{'-','-','-'},
{'-','-','-'},
};
board.setBoard(arr);
int a = 0;
for(int i = 0; i<9; i++){
System.out.println("Enter what row:");
int y = numreader.nextInt();
System.out.println("Enter what column:");
int z = numreader.nextInt();
if(arr[y][z]=='-'){
arr[y][z]='x';
board.setBoard(arr);
board.repaint();
counter ++;}
else
System.out.println("This is not allowed");
}
}
}
請在下次格式化一些代碼;) – martijnn2008
我懷疑下面提供的答案中的一些回答你的問題。如果他們這樣做,請接受其中之一。如果他們不這樣做,請編輯您的問題。謝謝! – GuiSim