Java数组及引用类型内存分配(三)

2014-11-24 09:56:27 · 作者: · 浏览: 6
ard = new String[BOARD_SIZE][BOARD_SIZE];
for(int i = 0; i < BOARD_SIZE; i++) {
for(int j = 0; j < BOARD_SIZE; j++) {
board[i][j] = "+";
}
}
}
//打印棋盘
private void printBoard() {
for(int i = 0; i < BOARD_SIZE; i++) {
for(int j = 0; j < BOARD_SIZE; j++) {
System.out.print(board[i][j]);
}
System.out.println("");
}
}
//开始下棋
public void play() throws Exception {
initBoard();
printBoard();
//获取键盘输入
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = null;
do {
if(input != null) {
String[] pos = input.split(",");
int x = Integer.parseInt(pos[0]);
int y = Integer.parseInt(pos[1]);
board[x - 1][y - 1] = "●";
printBoard();
}
System.out.print("请输入你下棋的坐标(以x,y的形式):");
} while((input = br.readLine()) != null);
}
public static void main(String[] args) throws Exception {
WZQ wzq = new WZQ();
wzq.play();
}