Java课程设计--五子棋
1. 团队名称、团队成员介绍
团名:今天你白给了吗
成员姓名 | 成员任务分配 | 成员博客设计链接 |
---|---|---|
陈宇杭(组长) | 网络连接的构建,主机之间的数据发送和接受 | https://www.cnblogs.com/ywk2002/p/15795943.html |
喻文康 | 各小模块的构建,图形界面和按钮事件,算法 | https://www.cnblogs.com/ywk2002/p/15795943.html |
2. 项目git地址
3. 前期调查(主要包含别人做得怎么样、怎么做的内容)
4. 项目功能架构图与主要功能流程图
5. 项目UML图
6. 项目运行截图
7. 项目关键代码(不能太多)
public void mouseReleased(MouseEvent e) {
int choice = JOptionPane.showConfirmDialog(null,"确定要悔棋吗","悔棋",JOptionPane.OK_CANCEL_OPTION);
if(choice == JOptionPane.OK_OPTION && chess[px][py] != 0 && gobang.one) {
if(chess[px][py] != 0) {
if(!danJi) {
Send sendxy = new Send(gobang);
sendxy.sendXY(2, px, py);
}
gobang.chess[px][py] = 0;
//gobang.me = !gobang.me;
gobang.repaint();
}
else {
}
}
}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseClicked(MouseEvent e) {}
});
int chose = JOptionPane.showConfirmDialog(null, "选择联网或者单机", "模式选择", JOptionPane.YES_OPTION, JOptionPane.WARNING_MESSAGE);
if(chose == JOptionPane.YES_OPTION) {
try {
userNameIp = JOptionPane.showInputDialog(null, "请输入对方的IP地址", "模式选择", JOptionPane.WARNING_MESSAGE).trim();
clientPort = Integer.parseInt(JOptionPane.showInputDialog(null, "请输入您的端口号", "端口号范围:1024~65535",JOptionPane.WARNING_MESSAGE).trim());
serverPort = Integer.parseInt(JOptionPane.showInputDialog(null, "请输入对方的端口号", "端口号范围:1024~65535", JOptionPane.WARNING_MESSAGE).trim());
} catch (Exception e) { // 输入错误,或者不输入的情况
JOptionPane.showMessageDialog(null, "输入错误,请重新打开游戏吧!", "错误", JOptionPane.ERROR_MESSAGE);
System.exit(0);
e.printStackTrace();
}
try {
inetAddress =InetAddress.getByName(userNameIp);
} catch (UnknownHostException e) {
e.printStackTrace();
}
if(inetAddress != null) {
JOptionPane.showMessageDialog(null, "开始", "游戏马上开始", JOptionPane.WARNING_MESSAGE);
start = true;
if(clientPort == serverPort) {
danJi = true; //端口号相等,进入单机模式
} else {
danJi = false; // 反之进入联机模式
}
gobang.run1();
}
}
if(chose == JOptionPane.NO_OPTION || chose == JOptionPane.CLOSED_OPTION) { // 选择单机模式,关闭窗口也默认为选择单机模式
JOptionPane.showMessageDialog(null, "您将与您自己进行对弈!", "单机模式", JOptionPane.INFORMATION_MESSAGE);
try {
inetAddress = InetAddress.getLocalHost(); // 获取本地的IP地址
serverPort = clientPort = 7778; // 设置默认端口号
start = true;
danJi = true;
gobang.run1();
} catch (UnknownHostException e) {
JOptionPane.showMessageDialog(null, "本地IP地址错误!", "单机模式启动失败", JOptionPane.ERROR_MESSAGE);
System.exit(0);
e.printStackTrace();
}
}
}
public void doit() {// 判断落子颜色及判断胜方
jGame.x = (jGame.ex - 11) / 30; // 将棋子放置在交叉线上
jGame.y = (jGame.ey - 11) / 30;
if (jGame.chess[jGame.x][jGame.y] == 0) {// 点击位置无棋子
if (jGame.me == true) {
jGame.chess[jGame.x][jGame.y] = 11;// 黑子
jGame.px = jGame.x;
jGame.py = jGame.y;
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
if (jGame.chess[i][j] == 22) {
jGame.chess[i][j] = 2;// 把刚才下的加白框的白子转换为普通白子
}
}
}
jGame.me = false;// 换为白子落子
} else if (jGame.me == false) {
jGame.chess[jGame.x][jGame.y] = 22;// 白子
jGame.px = jGame.x;
jGame.py = jGame.y;
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
if (jGame.chess[i][j] == 11) {
jGame.chess[i][j] = 1;// 把刚才下的加黑框的黑子转换为普通黑子
}
}
}
jGame.me = true;// 换为黑子落子
}
}
jGame.repaint();// 重绘棋盘后判断胜方
}
}