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]) {
* count4++; i4++; } i4 = 1; while (color == allChess[x - i4][y - i4]) {
* count4++; i4++; } if (count4 = 5) { flag = true ; }
*/
// 判断横向
count = this.checkCount(1, 0, color);
if (count = 5) {
flag = true;
} else {
// 判断纵向
count = this.checkCount(0, 1, color);
if (count = 5) {
flag = true;
} else {
// 判断右上、左下
count = this.checkCount(1, -1, color);
if (count = 5) {
flag = true;
} else {
// 判断右下、左上
count = this.checkCount(1, 1, color);
if (count = 5) {
flag = true;
}
}
}
}
return flag;
}
// 判断棋子连接的数量
private int checkCount(int xChange, int yChange, int color) {
int count = 1;
int tempX = xChange;
int tempY = yChange;
while (x + xChange = 0x + xChange = 18y + yChange = 0
y + yChange = 18
color == allChess[x + xChange][y + yChange]) {
count++;
if (xChange != 0)
xChange++;
if (yChange != 0) {
if (yChange0)
yChange++;
else {
推荐阅读
- 看直播适合用什么手机好,看直播用什么设备好
- python字符串保存到文件,python字符串保留字母和数字
- pg数据库目录大全,pg数据库使用教程
- 单机国产游戏,单机国产游戏虎头人铜虎
- vb.net滚轮问题 vb文字滚动代码
- chatgpt颠覆的行业,颠覆了行业
- 区块链钱包转账卡住,区块链转账成本低,速度快,一般几秒钟就能到账
- 快手直播散打,快手散打哥直播间
- jquery酒店日期选择,javascript 日期选择框