java网络五子棋设计博客_JAVA课设-五子棋-团队博客

1. 团队名称、团队成员介绍

刘海博 网络1814 201821123

鲁俊文 网络1814 201821123

岳小钢 网络1814 201821123109

2. 项目git地址

3 项目git提交记录截图

4. 项目功能架构图与主要功能流程图

架构图:

d361b0f786b3c212cff5b67230081e50.png

流程图:

7a0dcfa1d3b618c278eb77d58aa24e7b.png

5. 项目运行截图

a2d44836cbe14cbc461105e5d22658a2.png

c8f43c7df3f85e0c5ec4a8270713e282.png

6d289ce202df3a013c82467e29bea385.png

72bbf3fcd303be89e0b6656c5cb5ba40.png

6. 项目关键代码

1. 判断赢棋的代码。每下一个棋子都要判断是否有5个连续的棋子连成一条线,一旦5个棋子连成一条线就赢,棋局结束。

向下寻找

for (int y = yIndex + 1; y <= ROWS; y++) {

Color c = isBlack ? Color.black : Color.white;

if (hasChess(xIndex, y, c) != null)

continueCount++;

else

break;

}

if (continueCount >= 5)

return true;

else

continueCount = 1;

// 继续另一种情况的搜索:斜向

// 右上寻找

for (int x = xIndex + 1, y = yIndex - 1; y >= 0 && x <= COLS; x++, y--) {

Color c = isBlack ? Color.black : Color.white;

if (hasChess(x, y, c) != null) {

continueCount++;

} else

break;

}

// 左下寻找

for (int x = xIndex - 1, y = yIndex + 1; x >= 0 && y <= ROWS; x--, y++) {

Color c = isBlack ? Color.black : Color.white;

if (hasChess(x, y, c) != null) {

continueCount++;

} else

break;

}

if (continueCount >= 5)

return true;

else

continueCount = 1;

// 继续另一种情况的搜索:斜向

// 左上西北寻找

for (int x = xIndex - 1, y = yIndex - 1; x >= 0 && y >= 0; x--, y--) {

Color c = isBlack ? Color.black : Color.white;

if (hasChess(x, y, c) != null)

continueCount++;

else

break;

}

// 右下东南寻找

for (int x = xIndex + 1, y = yIndex + 1; x <= COLS && y <= ROWS; x++, y++) {

Color c = isBlack ? Color.black : Color.white;

if (hasChess(x, y, c) != null)

continueCount++;

else

break;

}

if (continueCount >= 5)

return true;

else

continueCount = 1;

return false;

}

2. 判断当前位置有没有黑棋或者白棋

private Chess hasChess(int xIndex, int yIndex, Color color) {

for (Chess p : chessList) {

if (p != null && p.getX() == xIndex && p.getY() == yIndex && p.getColor() == color)

return p;

}

return null;

}

3

public void mousePressed(MouseEvent e) {// 鼠标在组件上按下时调用

// 游戏结束时,不再能下

if (gameOver)

{

return;

}

String colorName = isBlack ? "黑棋" : "白棋";

// 将鼠标点击的坐标位置转换成网格索引

xIndex = (e.getX() - MARGIN + SPAN / 2) / SPAN;

yIndex = (e.getY() - MARGIN + SPAN / 2) / SPAN;

// 落在棋盘外不能下

if (xIndex < 0 || xIndex > ROWS || yIndex < 0 || yIndex > COLS)

return;

// 如果x,y位置已经有棋子存在,不能下

if (findChess(xIndex, yIndex))

return;

// 可以进行时的处理

try {

music.putChess();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

Chess ch = new Chess(xIndex, yIndex, isBlack ? Color.black : Color.white);

chessList[chessCount++] = ch;

repaint();// 通知系统重新绘制

// 如果胜出则给出提示信息,不能继续下棋

if (isWin()) {

String msg = String.format("恭喜,%s赢了!", colorName);

JOptionPane.showMessageDialog(this, msg);

gameOver = true;

}

isBlack = !isBlack;

}

7. 尚待改进或者新的想法

因为时间太仓促,所以界面不够完善。有很多功能没有实现,还有很多可以改进的地方,之后也想做得更精良。例如想尝试做人机版、联机版、等级功能、游戏计时等功能。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值