java五子棋提示信息重叠_实现五子棋黑白轮流下棋出问题了,大神们都进来看下...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

package zuoye; import java.util.Scanner; public class FiveChess {

// 定义数组为17行17列

public static char[][] chess = new char[17][17];

public static boolean isBlackchess = true;

public static void main(String[] args) {

initGame();// 调用游戏方法

pressChess();// 调用下棋的方法 } public static void initGame() {

chess[0][0] = ' ';

// 对棋盘第一行进行赋值

for (int i = 1; i < chess.length; i++) {

if (i <= 10) {

chess[0][i] = (char) (i + 47); } else {

chess[0][i] = (char) (i + 86);

}

}

// 对棋盘第一列赋值

for (int i = 1; i < chess.length; i++) {

if (i <= 10) {

chess[i][0] = (char) (i + 47); } else {

chess[i][0] = (char) (i + 86);

}

}

for (int i = 1; i < chess.length; i++) {

for (int j = 1; j < chess.length; j++) {

chess[i][j] = '*';

}

}

print();

} // 以下是下棋方法

public static void pressChess() {

Scanner sc = new Scanner(System.in);

while (true) {

if (isBlackchess) {// 判断 如果是黑棋 则打印出黑棋下子

System.out.println("黑棋下子");

String cmd = sc.next();

char i = cmd.charAt(0);

char j = cmd.charAt(1);

int rows = converCharToInt(i);// 吧rows clos转换成int类型

int cols = converCharToInt(j);

// 判断一些出错的地方 例如数组越界问题 有一个旗子了已经

if (!(rows >= 0 && rows <= 15) || cols >= 0 && cols <= 15) {

System.out.println("坐标越界");

continue;// 找出问题后跳出问题继续执行以下代码

}

if (chess[rows + 1][cols + 1] != '*') {// 判断已经有一个旗子了如果这里不是*(*再此是棋盘)

System.out.println("此处有旗子");

continue;

}

chess[rows + 1][cols + 1] = '@';// 要下的是这个子

print(); } else {

System.out.println("白棋下子");

String cmd = sc.next();

char i = cmd.charAt(0);

char j = cmd.charAt(1);

int rows = converCharToInt(i);// 吧rows clos转换成int类型

int cols = converCharToInt(j);

// 判断一些出错的地方 例如数组越界问题 有一个旗子了已经

if (!(rows >= 0 && rows <= 15) || cols >= 0 && cols <= 15) {

System.out.println("数组越界");

continue;// 找出问题后跳出问题继续执行以下代码

}

if (chess[rows + 1][cols + 1] != '*') {// 判断已经有一个旗子了如果这里不是*(*再此是棋盘)

System.out.println("此处有旗子");

continue;

}

chess[rows + 1][cols + 1] = 'o';// 要下的是这个子

print();

}

isBlackchess = !isBlackchess;

}

} // 打印棋盘信息

public static void print() {

for (int i = 0; i < chess.length; i++) {

for (int j = 0; j < chess.length; j++) {

System.out.print(chess[i][j] + " ");

}

System.out.println();

}

} public static int converCharToInt(char ch) {

if (ch >= '0' && ch <= '9') {

return (int) (ch - '0');

} else {

return (int) (ch - 'a' + 10);

}

}

}

希望对你有用 这个代码不能判断输赢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值