我正在尝试创建一个简单的井字游戏作为练习数组等。
我知道我想如何在下面对其进行编码,但是我对用户输入有疑问。
问题
如何为 X 或 O 的每个用户输入更改数组输入。
import java.util.Scanner;
public class TicTacToe {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] array;
array = new String [9];
int uInput;
int pCounter=1;
while ( uInput <= 9) {
System.out.println("Enter X coordinate:");
uInput = input.nextInt();
array[uInput] = ("x");
System.out.println("Enter X coordinate:");
uInput = input.nextInt();
array[uInput] = ("o");
for (int yCounter = 0; yCounter < 6; yCounter++) {
System.out.print("--");
}
System.out.println();
for (int fCounter=0; fCounter<(3); fCounter++) {
for (int xCounter=0; xCounter<1; xCounter++) {
for (pCounter=1; pCounter<4; pCounter++) {
System.out.printf(" %d| ", array[pCounter]);
}
}
}
System.out.println();
for (int zCounter=0; zCounter<4; zCounter++) {
System.out.print("---");
}
System.out.println();
}
System.out.print("0 1 2\n3 4 5\n6 7 8\n");
}
}