到目前为止,这是我的代码:
import java.util.Scanner;
import java.util.Arrays;
public class TicTacToeGame {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome to Tic Tac Toe (you are X)!");
String gameBox = new TicTacToe().toString();
System.out.println(gameBox);
userMove(gameBox);
}
public static void userMove(String gameBoard) {
Scanner keyboard = new Scanner (System.in);
int row, column;
String [][] moveX = new String [3][3];
do {
System.out.print("Move location: ");
row = keyboard.nextInt();
column = keyboard.nextInt();
} while (row < 0 || row > 2 || column < 0 || column > 2);
for (int i = 0; i < moveX.length; i++){
for (int j = 0; j < moveX[i].length; j++){
if (row == i && column == j){
moveX[i][j] = "X";
}
else
moveX[i][j] = " ";
}
}
System.out.println(Arrays.deepToString(moveX));
}
我让用户输入他们想要将X放在游戏板上的位置。游戏板gameBox(取自另一个类)看起来像这样:
=============
| | | |
=============
| | | |
=============
| | | |
=============
我怎样才能获得&#34; X&#34;在游戏板里面?