java写五子棋代码 基于java的五子棋游戏的设计代码( 四 )


int x = sc.nextInt();
int y = sc.nextInt();
if (x == SIZEy == SIZE) {
System.out.println("程序结束");
System.exit(0);
}
if (xSIZE || x0 || ySIZE | y0) {
System.out.println("输入错误,请从新输入");
continue;
}
//如果roles是A玩家 就让A玩家下棋,否则就让B玩家下棋 。
if (wz.board[x][y].equals("╋")roles.equals("A玩家")) {
wz.board[x][y] = "○";
wz.printBoard();
//判断输赢
wz.whoWin(wz);
}else if(wz.board[x][y].equals("╋")roles.equals("B玩家")){
wz.board[x][y] = "●";
wz.printBoard();
//判断输赢
wz.whoWin(wz);
} else {
System.out.println("此处已经有棋子,从新输入");
continue;
}
if(roles.equals("A玩家")){
roles = "B玩家";
}else if(roles.equals("B玩家")){
roles = "A玩家";
}
}
}
}
求五子棋Java代码旁边就注释 让我看的清楚明白一些 , 要详细的解释和思路import java.applet.*;
importt.*;
importt.event.*;
import java.applet.Applet;
importt.Color; //这一段import就不说了,下面要用到的就import进来
public class wuziqi extends Applet implements ActionListener,MouseListener,MouseMotionListener,ItemListener
//继承Applet表明是个applet , 后面的接口必须要实现每个接口的所有方法
{
int color_Qizi=0;//旗子的颜色标识 0:白子 1:黑子
int intGame_Start=0;//游戏开始标志 0未开始 1游戏中
int intGame_Body[][]=new int[16][16]; //设置棋盘棋子状态 0 无子 1 白子 2 黑子
java五子棋源代码我这有算法 不过没做swing界面 DOS下可以直接运行 要不你拿去改改
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
* 五子棋源码
* 所用的符号标识 ○ ● ┼
* 在dos界面下运行效果最佳
* 黑白双方交叉输入落子点坐标 以逗号隔开如 1,1
* 输入空 或者一方胜出 程序停止
*/
public class Chess {
// 定义棋盘大小
private static int SIZE = 15;
private String[][] board;
public static void main(String[] args) throws Exception {
Chess chess = new Chess();
// 初始化棋盘
chess.initBoard();
// 画出棋盘
chess.paintBoard();
// 根据who的奇偶性 判断该谁落子
int who = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = null;
while ((str = br.readLine()) != null) {
// 提取输入的 以","分开的数 分别对应x y坐标
String[] posStr = str.split(",");
int x = Integer.parseInt(posStr[0]);
int y = Integer.parseInt(posStr[1]);
// 判断落子点是否合法
if (!"┼".equals(chess.board[x][y])) {
System.out.println("这里不允许落子,请重下..");
continue;
}
if (who % 2 == 0) {
chess.board[x][y] = "○";
chess.paintBoard();
// 判断是否胜出
if (chess.isWin("○")) {
System.out.println("○获胜");
return;
}
} else {
chess.board[x][y] = "●";
chess.paintBoard();
// 判断是否胜出
if (chess.isWin("●")) {
System.out.println("●获胜");
return;
}
}
who++;
}
}
// 以 "┼" 初始化棋盘
public void initBoard() {
board = new String[SIZE][SIZE];
for (int i = 0; iSIZE; i++) {
for (int j = 0; jSIZE; j++) {
board[i][j] = "┼";
}
}
}
// 描绘出当前棋盘
public void paintBoard() {
// 以下代码 这里为了使得棋盘坐标看的清楚 加入了坐标值
System.out.print("");
for (int i = 0; iSIZE; i++) {
if (i10) {
System.out.print(i + " ");

推荐阅读