请帮我写一个java的五子棋
时间: 2023-03-14 08:03:54 浏览: 77
wuziqi.rar_java写的五子棋_五子棋java
很高兴为你写一个java的五子棋!下面是代码:import java.util.Scanner;public class Gomoku { public static void main(String[] args) {
char[][] board = new char[15][15];
int x, y;
int player = 1;
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 15; j++) {
board[i][j] = '.';
}
}
while (true) {
System.out.println("玩家" + player + ",请输入你的落子位置(x,y):");
x = scanner.nextInt();
y = scanner.nextInt();
if (x < 0 || x > 14 || y < 0 || y > 14) {
System.out.println("落子位置不合法,请重新输入!");
continue;
}
if (board[x][y] != '.') {
System.out.println("该位置已经有棋子,请重新输入!");
continue;
}
if (player == 1) {
board[x][y] = 'X';
player = 2;
} else {
board[x][y] = 'O';
player = 1;
}
// 打印棋盘
System.out.println(" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14");
for (int i = 0; i < 15; i++) {
System.out.print(i + " ");
for (int j = 0; j < 15; j++) {
System.out.print(board[i][j] + " ");
}
System.out.println();
}
}
}
}
阅读全文