java五子棋代码解析 java五子棋的简单思路( 三 )


"设置完成,是否重新开始游戏?");
if (result == 0) {
for (int i = 0; i19; i++) {
for (int j = 0; j19; j++) {
allChess[i][j] = 0;
}
}
// 另一种方式 allChess = new int[19][19];
message = "黑方先行";
isBlack = true;
blackTime = maxTime;
whiteTime = maxTime;
blackMessage = "无限制";
whiteMessage = "无限制";
this.canPlay = true;
this.repaint();
}
}
if (maxTime0) {
int result = JOptionPane.showConfirmDialog(this,
"设置完成,是否重新开始游戏?");
if (result == 0) {
for (int i = 0; i19; i++) {
for (int j = 0; j19; j++) {
allChess[i][j] = 0;
}
}
// 另一种方式 allChess = new int[19][19];
message = "黑方先行";
isBlack = true;
blackTime = maxTime;
whiteTime = maxTime;
blackMessage = maxTime / 3600 + ":"
+ (maxTime / 60 - maxTime / 3600 * 60) + ":"
+ (maxTime - maxTime / 60 * 60);
whiteMessage = maxTime / 3600 + ":"
+ (maxTime / 60 - maxTime / 3600 * 60) + ":"
+ (maxTime - maxTime / 60 * 60);
t.resume();
this.canPlay = true;
this.repaint();
}
}
} catch (NumberFormatException e1) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(this, "请正确输入信息!");
}
}
// 点击 游戏说明 按钮
if (e.getX() = 400e.getX() = 470e.getY() = 170
e.getY() = 200) {
JOptionPane.showMessageDialog(this,
"这个一个五子棋游戏程序 , 黑白双方轮流下棋,当某一方连到五子时,游戏结束 。");
}
// 点击 认输 按钮
if (e.getX() = 400e.getX() = 470e.getY() = 270
e.getY() = 300) {
int result = JOptionPane.showConfirmDialog(this, "是否确认认输?");
if (result == 0) {
if (isBlack) {
JOptionPane.showMessageDialog(this, "黑方已经认输,游戏结束!");
} else {
JOptionPane.showMessageDialog(this, "白方已经认输,游戏结束!");
}
canPlay = false;
}
}
// 点击 关于 按钮
if (e.getX() = 400e.getX() = 470e.getY() = 320
e.getY() = 350) {
JOptionPane.showMessageDialog(this,
"本游戏由MLDN制作,有相关问题可以访问");
}
// 点击 退出 按钮
if (e.getX() = 400e.getX() = 470e.getY() = 370
e.getY() = 400) {
JOptionPane.showMessageDialog(this, "游戏结束");
System.exit(0);
}
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
private boolean checkWin() {
boolean flag = false;
// 保存共有相同颜色多少棋子相连
int count = 1;
// 判断横向是否有5个棋子相连,特点 纵坐标 是相同 ,  即allChess[x][y]中y值是相同
int color = allChess[x][y];
/*
* if (color == allChess[x+1][y]) { count++; if (color ==
* allChess[x+2][y]) { count++; if (color == allChess[x+3][y]) {
* count++; } } }
*/
// 通过循环来做棋子相连的判断
/*
* int i = 1; while (color == allChess[x + i][y + 0]) { count++; i++; }
* i = 1; while (color == allChess[x - i][y - 0]) { count++; i++; } if
* (count = 5) { flag = true; } // 纵向的判断 int i2 = 1 ; int count2 = 1 ;
* while (color == allChess[x + 0][y + i2]) { count2++; i2++; } i2 = 1;
* while (color == allChess[x - 0][y - i2]) { count2++; i2++; } if
* (count2 = 5) { flag = true ; } // 斜方向的判断(右上 + 左下) int i3 = 1 ; int
* count3 = 1 ; while (color == allChess[x + i3][y - i3]) { count3++;
* i3++; } i3 = 1; while (color == allChess[x - i3][y + i3]) { count3++;
* i3++; } if (count3 = 5) { flag = true ; } // 斜方向的判断(右下 + 左上) int i4 =
* 1 ; int count4 = 1 ; while (color == allChess[x + i4][y + i4]) {

推荐阅读