结合JAVA和中国象棋方面的实践经验,在分析了中国象棋游戏需求基础上,设计并实现了中国象棋系统。该系统为人人对战。人人对战规则明确,包含了中国象棋所有的招法。方便了不同水平人群的不同选择。设计和开发好中国象棋游戏,对与提高Java开发水平和系统的设计能力有极大的帮助。
主要研究基于JAVA技术的中国象棋游戏的分析与设计,对中国象棋游戏特殊的行棋规则给予了细致的分析与理解,设计出了一种实时可行的行棋规则,从移动范围、移动方向和穿越障碍几个方面重新描述行棋规则,基于Java 技术通过计算机模拟实现了中国象棋特殊的行棋规则算法,设计出了一种可行的方法,使每个棋子的行棋路线都严格遵循本身的行棋规则,游戏的实战对弈得以实现。
本软件设计的主要功能如下:(1)实现象棋的规则;(2)能够实现下棋期间保存棋盘,以及读取已有的棋盘;(3)能够在开始游戏时播放背景音乐,以及行棋时播放走棋的音效;(4)任一方获胜后,游戏结束,提示某一方获得胜利。
构建Java程序Main.class来实现棋盘的界面展示与ChessFrame.class来利用棋盘设计框架,利用java.swing中主要的方法如按钮的设计,需要设计多个按钮,如悔棋,新游戏等。利用前面我们设计的棋盘中棋子的大小,从而可以完成棋盘的总体设计。主要依靠java.awt中 Container(容器),GridLayout棋盘的设计框架。设计棋子大小后,棋盘的长于宽分别使用558与676的大小。然后利用我们前面设计的棋子走向来镶嵌入我们所创建出的棋盘。主要需要两个监视器如ActionListener与MouseListener接口来分别观察按钮和观察鼠标。
package com.chess;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
public class ChessMainframe extends JFrame implements ActionListener, MouseListener,Runnable {
ChessManBehavior play[] = new ChessManBehavior[32];
JLabel image;
Container con;
JToolBar jmain;
JButton anew, repent, exit;
JLabel text;
public ChessMainframe(String title) {
con = this.getContentPane();
con.setLayout(null);
this.setTitle(title);
jmain = new JToolBar();
text = new JLabel("欢迎来到象棋荣耀");
text.setToolTipText("信息提示");
anew = new JButton("新游戏");
anew.setToolTipText("重新开始新的一局");
exit = new JButton("退出");
exit.setToolTipText("退出象棋对弈系统");
repent = new JButton("悔棋");
repent.setToolTipText("返回上次走棋的位置");
jmain.setLayout(new GridLayout(0, 4));
jmain.add(anew);
jmain.add(repent);
jmain.add(exit);
jmain.add(text);
jmain.setBounds(0, 0, 558, 30);
con.add(jmain);
draeChessMain();
for(int i=0;i<32;i++)
{
con.add(play[i]);
play[i].addMouseListener(this);
}
con.add(image=new JLabel(new ImageIcon("image/main.gif")));
image.setBounds(0,30,558,620);
image.addMouseListener(this);
Dimension screeSize=Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(screeSize.width/2-228,screeSize.height/2-350);
this.setIconImage(new ImageIcon("image/红将.gif").getImage());
this.setResizable(false);
this.setSize(558,676);
this.setVisible(true);
}
public void draeChessMain() {
int i, k;
Icon in = null;
in = new ImageIcon("image/黑车.gif");
for (i = 0, k = 24; i < 2; i++, k += 456) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 56, 55, 55);
play[i].setName("车1");
}
in = new ImageIcon("image/黑马.gif");
for (i = 4, k = 81; i < 6; i++, k += 342) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 56, 55, 55);
play[i].setName("马1");
}
in = new ImageIcon("image/黑象.gif");
for (i = 8, k = 138; i < 10; i++, k += 228) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 56, 55, 55);
play[i].setName("象1");
}
in = new ImageIcon("image/黑士.gif");
for (i = 12, k = 195; i < 14; i++, k += 114) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 56, 55, 55);
play[i].setName("士1");
}
in = new ImageIcon("image/黑卒.gif");
for (i = 16, k = 24; i < 21; i++, k += 114) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 227, 55, 55);
play[i].setName("卒1" + i);
}
in = new ImageIcon("image/黑炮.gif");
for (i = 26, k = 81; i < 28; i++, k += 342) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 170, 55, 55);
play[i].setName("炮1" + i);
}
in = new ImageIcon("image/黑将.gif");
play[30] = new ChessManBehavior(in);
play[30].setBounds(252, 56, 55, 55);
play[30].setName("将1");
in = new ImageIcon("image/红车.gif");
for (i = 2, k = 24; i < 4; i++, k += 456) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 569, 55, 55);
play[i].setName("车2");
}
in = new ImageIcon("image/红马.gif");
for (i = 6, k = 81; i < 8; i++, k += 342) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 569, 55, 55);
play[i].setName("红马2");
}
in = new ImageIcon("image/红象.gif");
for (i = 10, k = 138; i < 12; i++, k += 228) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 569, 55, 55);
play[i].setName("红象2");
}
in = new ImageIcon("image/红士.gif");
for (i = 14, k = 195; i < 16; i++, k += 114) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 569, 55, 55);
play[i].setName("红士2");
}
in = new ImageIcon("image/红卒.gif");
for (i = 21, k = 24; i < 26; i++, k += 114) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 398, 55, 55);
play[i].setName("红卒" + i);
}
in = new ImageIcon("image/红炮.gif");
for (i = 28, k = 81; i < 30; i++, k += 342) {
play[i] = new ChessManBehavior(in);
play[i].setBounds(k, 455, 55, 55);
play[i].setName("炮2" + i);
}
in=new ImageIcon("image/红将.gif");
play[31] = new ChessManBehavior(in);
play[31].setBounds(252, 569, 55, 55);
play[31].setName("帅");
}
@Override
public void actionPerformed(ActionEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void run() {
}
}
在第一部分(象棋的界面的 )完成后,继而开始规范每一个棋子的走向,利用Runnable接口的方法来实现棋子的周期性闪烁,利用前面界面设计,对每个棋子的步骤都清晰的写出来,利用两个监视器来触动事件的发生,经过精密的坐标计算,从而计算出每个棋子的每一种方法,进而可以将给每一个棋子的运动轨迹做记录。
中国象棋规则介绍:
Ⅰ棋盘
棋子活动的场所叫做“棋盘”,在长方形的平面上,绘有9条平行的竖线和10条平行的横线相交组成,共90个交叉点,棋子摆在这些交叉点上。中间第5根横线和第6根横线之间未画竖线的空白地带,叫做“楚河 汉界”,整个棋盘就以“楚河 汉界”分为相等的两部分;两方将帅坐阵,画有“米”字方格的地方叫做“九宫”。
Ⅱ棋子
象棋的棋子共32个,分为红黑两组,各16个,由对弈双方各执一组,每组兵种是一样的,各分为七种。
红方:帅、仕、相、车、马、炮、兵;
黑方:将、士、象、车、马、炮、卒。
其中帅和将、士和仕、相和象、兵和卒的作用完全相同,仅仅是为了区分红棋和黑棋。
Ⅲ各棋子走法说明
①将或帅
移动范围:它只能在九宫内移动
移动规则:它每一步只可以水平或垂直移动一点
特殊说明:红方帅和黑方将不能直接见面,即帅和将中间必须有其他棋子间隔,否则构成“老将见面”情况;
假如现在是红方执子,此时构成“老将见面”状况,那么玩家可以移动帅直接吃掉对方的将,红方获胜。
②士或仕
移动范围:它只能在九宫内移动
移动规则:它每一步只能沿对角线方向移动一点
③象或相
移动范围:“楚河 汉界”的一侧
移动规则:它每一步只能沿对角线走两点(走田字),另外,移动的对角线方向上一点不能有其他棋子(不能被堵象眼)。
④马
移动范围:任何位置
移动规则:它每一步只能走曰字并且不能被绊马脚(斜着走,横位移量*纵位移量等于2)。
⑤车
移动范围:任何位置
移动规则:它可以水平或垂直方向移动任意个无阻碍的点。
⑥炮
移动范围:任何位置
移动规则:移动跟车很相似,它既可以像车一样水平或垂直方向移动任意无阻碍的点,也可以通过隔一个棋子吃掉对方一个棋子的方式进行移动。
⑦卒或兵
移动范围:过河后可以走过河后的一侧的任何位置,未过河只能走该棋子向上方向的直线区域
移动规则:它每步只能移动一个点,它未过河时只能向前移动,如果它过河了,增加向左向右移动的能力。
Ⅳ胜负说明
对局中,如果一方玩家认输或者该玩家的“将”或“帅”被对方棋子吃掉,该玩家算输,对方算赢
Ⅱ棋子信息存储及显示
棋子设计成对应的类,每种棋子都有自己对应的棋子图案;
中国象棋一共有32个棋子,这里可以将32个棋子对象数组存储到一个棋子对象数组chess。chess[i]中下标i的值如果是前两个表示黑方棋子,紧接着表示的是红方棋子,黑色棋子与红色棋子交替;
棋子初始化时根据玩家执子颜色和棋子上的字获取指定棋子图案,根据x,y的值,将棋子的位置信息初始化到第x行第y列;
游戏开始时根据双方执子颜色初始化棋盘信息(红方和黑方棋子放置位置会不同);
游戏保证了执子方一定处于棋盘下方,判棋规则目前都是基于我方下棋去判断的,如果我方下棋符合下棋规则,先将下棋信息进行坐标转换,然后发送给对方;接收到对方的下棋信息时,直接按照对方下棋信息对棋盘和棋子信息进行变更即可(发送之前坐标已经转换,无需再次转换)。
Ⅲ走棋规则
对于中国象棋来说,有马走日、象走田等一系列规则。
根据不同的棋子,按不同的规则进行走法判断。
判断是否能走棋的算法如下:
①如果棋子为“帅”或“将”,检查是否走直线并且走一步,以及走一步是否超出范围(老将碰面情况需要提前特殊处理)
②如果棋子为“仕”或“士”,检查是否沿斜对角线走一步,以及走一步是否超过范围
③如果棋子为“象”或“象”,检查是否走“田”字,是否被堵象眼,走一步是否超出范围
④如果棋子为“马”,检查是否走“日”字,是否被绊马脚
⑤如果棋子为“车”,检查是否走直线,移动前的位置和移动后的位置中间是否还有其他子
⑥如果棋子为“炮”,检查是否走直线,判断是否吃子,如果吃子判断中间是否只有一个棋子,否则判断中间是否还有其他子
⑦如果棋子为“卒”或“兵”,检查是否走直线,走一步;如果棋子没有过河,判断棋子是否向前走;如果棋子已经过河,判断是否向前、左、右移动
package com.chess;
import java.awt.event.MouseEvent;
import java.util.List;
import javax.swing.JLabel;
public class ChessRule {
public ChessRule() {
}
public void cannonRule(ChessManBehavior play, JLabel[] playQ, MouseEvent me, List chessRegretList, int man) {
int count = 0;
int cx = me.getX();
int cy = me.getY() + 30;
int i;
int j;
int k;
ChessRegret chessRegret;
if (cx - play.getX() >= 0 && cx - play.getX() < 57) {
for(i = 56; i <= 569; i += 57) {
if (cy - i >= 0 && cy - i < 57) {
for(j = 0; j < 32; ++j) {
if (playQ[j].getX() == play.getX() && play.getName() != playQ[j].getName() && playQ[j].isVisible()) {
for(k = i; k < play.getY(); k += 57) {
if (playQ[j].getY() == k) {
++count;
}
}
for(k = play.getY(); k < i; k += 57) {
if (playQ[j].getY() == k) {
++count;
}
}
}
}
if (count == 0) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX(), i, 55, 55);
return;
}
}
}
}
if (me.getY() - play.getY() + 30 >= 0 && me.getY() - play.getY() + 30 <= 56) {
for(i = 24; i <= 480; i += 57) {
if (me.getX() - i >= 0 && me.getX() - i < 57) {
for(j = 0; j < 32; ++j) {
if (playQ[j].getY() == play.getY() && play.getName() != playQ[j].getName() && playQ[j].isVisible()) {
for(k = i; k < play.getX(); k += 57) {
if (playQ[j].getX() == k) {
++count;
}
}
for(k = play.getX(); k < i; k += 57) {
if (playQ[j].getX() == k) {
++count;
}
}
}
}
if (count == 0) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(i, play.getY(), 55, 55);
return;
}
}
}
}
}
public void cannonEat(JLabel play, JLabel[] playQ, JLabel enemy, List chessRegretList, int man, int beEat) {
int count = 0;
int i;
int j;
ChessRegret chessRegret;
if (play.getX() == enemy.getX()) {
for(i = 0; i < 32; ++i) {
if (play.getY() < enemy.getY()) {
for(j = play.getY() + 57; j < enemy.getY(); j += 57) {
if (playQ[i].getX() == play.getX() && playQ[i].getY() == j && playQ[i].isVisible()) {
++count;
}
}
} else {
for(j = enemy.getY() + 57; j < play.getY(); j += 57) {
if (playQ[i].getX() == play.getX() && playQ[i].getY() == j && playQ[i].isVisible()) {
++count;
}
}
}
}
if (count == 1) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (play.getY() == enemy.getY()) {
for(i = 0; i < 32; ++i) {
if (play.getX() > enemy.getX()) {
for(j = enemy.getX() + 57; j < play.getX(); j += 57) {
if (playQ[i].getY() == play.getY() && playQ[i].getX() == j && playQ[i].isVisible()) {
++count;
}
}
} else {
for(j = play.getX(); j < enemy.getX(); j += 57) {
if (playQ[i].getY() == play.getY() && playQ[i].getX() == j && playQ[i].isVisible()) {
++count;
}
}
}
}
if (count == 1) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
}
public void carRule(ChessManBehavior play, JLabel[] playQ, MouseEvent me, List chessRegretList, int man) {
this.cannonRule(play, playQ, me, chessRegretList, man);
}
public void carEat(JLabel play, JLabel[] playQ, JLabel enemy, List chessRegretList, int man, int beEat) {
int count = 0;
int i;
int j;
ChessRegret chessRegret;
if (play.getX() == enemy.getX()) {
for(i = 0; i < 32; ++i) {
if (play.getY() < enemy.getY()) {
for(j = play.getY() + 57; j < enemy.getY(); j += 57) {
if (playQ[i].getX() == play.getX() && playQ[i].getY() == j && playQ[i].isVisible()) {
++count;
}
}
} else {
for(j = enemy.getY() + 57; j < play.getY(); j += 57) {
if (playQ[i].getX() == play.getX() && playQ[i].getY() == j && playQ[i].isVisible()) {
++count;
}
}
}
}
if (count == 0) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (play.getY() == enemy.getY()) {
for(i = 0; i < 32; ++i) {
if (play.getX() > enemy.getX()) {
for(j = enemy.getX() + 57; j < play.getX() - 57; j += 57) {
if (playQ[i].getY() == play.getY() && playQ[i].getX() == j && playQ[i].isVisible()) {
++count;
}
}
} else {
for(j = play.getX(); j < enemy.getX(); j += 57) {
if (playQ[i].getY() == play.getY() && playQ[i].getX() == j && playQ[i].isVisible()) {
++count;
}
}
}
}
if (count == 0) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
}
public void horseRule(JLabel play, JLabel[] playQ, MouseEvent me, List chessRegretList, int man) {
int ex = 0;
int ey = 0;
boolean move = false;
ex = me.getX();
ey = me.getY() + 30;
int i;
ChessRegret chessRegret;
if (play.getX() - ex > 0 && play.getX() - ex <= 57 && play.getY() - ey >= 59 && play.getY() - ey <= 114) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getX() == play.getX() && playQ[i].getY() - play.getY() == -57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 57, play.getY() - 114, 55, 55);
return;
}
}
if (ex - play.getX() > 0 && play.getX() - ex <= 57 && play.getY() - ey >= 59 && play.getY() - ey <= 114) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getX() == play.getX() && playQ[i].getY() - play.getY() == -57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY() - 114, 55, 55);
}
} else {
if (play.getX() - ex > 0 && play.getX() - ex <= 57 && ey - play.getY() >= 114 && ey - play.getY() <= 170) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getX() == play.getX() && playQ[i].getY() - play.getY() == 57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 57, play.getY() + 114, 55, 55);
return;
}
}
if (ex - play.getX() > 0 && play.getX() - ex <= 57 && ey - play.getY() >= 114 && ey - play.getY() <= 170) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getX() == play.getX() && playQ[i].getY() - play.getY() == 57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY() + 114, 55, 55);
return;
}
}
if (play.getX() - ex > 0 && play.getX() - ex <= 114 && play.getY() - ey > 0 && play.getY() - ey <= 57) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getY() == play.getY() && playQ[i].getX() - play.getX() == -57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 114, play.getY() - 57, 55, 55);
return;
}
}
if (play.getX() - ex > 0 && play.getX() - ex <= 114 && ey - play.getY() >= 57 && ey - play.getY() < 114) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getY() == play.getY() && playQ[i].getX() - play.getX() == -57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 114, play.getY() + 57, 55, 55);
return;
}
}
if (ex - play.getX() >= 114 && ex - play.getX() <= 170 && play.getY() - ey > 0 && play.getY() - ey <= 57) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getY() == play.getY() && playQ[i].getX() - play.getX() == 57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 114, play.getY() - 57, 55, 55);
return;
}
}
if (ex - play.getX() >= 114 && ex - play.getX() <= 170 && ey - play.getY() >= 57 && ey - play.getY() < 114) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getY() == play.getY() && playQ[i].getX() - play.getX() == 57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 114, play.getY() + 57, 55, 55);
return;
}
}
}
}
public void horseEat(JLabel play, JLabel[] playQ, JLabel enemy, List chessRegretList, int man, int beEat) {
boolean canGo = true;
int i;
ChessRegret chessRegret;
if ((play.getX() - 57 == enemy.getX() || play.getX() + 57 == enemy.getX()) && play.getY() - 114 == enemy.getY()) {
for(i = 0; i < 32; ++i) {
if (playQ[i].getX() == play.getX() && playQ[i].getY() == play.getY() - 57 && playQ[i].isVisible()) {
canGo = false;
}
}
if (canGo) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if ((play.getX() - 57 == enemy.getX() || play.getX() + 57 == enemy.getX()) && play.getY() + 114 == enemy.getY()) {
for(i = 0; i < 32; ++i) {
if (playQ[i].getX() == play.getX() && playQ[i].getY() == play.getY() + 57 && playQ[i].isVisible()) {
canGo = false;
}
}
if (canGo) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (play.getX() - 114 == enemy.getX() && (play.getY() - 57 == enemy.getY() || play.getY() + 57 == enemy.getY())) {
for(i = 0; i < 32; ++i) {
if (playQ[i].getX() - 57 == play.getX() && playQ[i].getY() == play.getY() && playQ[i].isVisible()) {
canGo = false;
}
}
if (canGo) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (play.getX() + 114 == enemy.getX() && (play.getY() - 57 == enemy.getY() || play.getY() + 57 == enemy.getY())) {
for(i = 0; i < 32; ++i) {
if (playQ[i].getX() + 57 == play.getX() && playQ[i].getY() == play.getY() && playQ[i].isVisible()) {
canGo = false;
}
}
if (canGo) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
}
public void elephantMove(JLabel play, JLabel[] playQ, MouseEvent me, List chessRegretList, int man) {
int ex = me.getX();
int ey = me.getY() + 30;
boolean move = false;
if (play.getY() > 284 || ey < 341) {
if (play.getY() < 341 || ey >= 341) {
int i;
ChessRegret chessRegret;
if (play.getX() - ex <= 114 && play.getX() - ex >= 58 && play.getY() - ey <= 114 && play.getY() - ey >= 58) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getX() == play.getX() - 57 && playQ[i].getY() - play.getY() == -57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 114, play.getY() - 114, 55, 55);
return;
}
}
if (play.getX() - ex <= 114 && play.getX() - ex >= 58 && ey - play.getY() >= 114 && ey - play.getY() <= 170) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getX() == play.getX() - 57 && playQ[i].getY() - play.getY() == 57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 114, play.getY() + 114, 55, 55);
return;
}
}
if (ex - play.getX() >= 114 && ex - play.getX() <= 170 && play.getY() - ey <= 114 && play.getY() - ey >= 58) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getX() == play.getX() + 57 && playQ[i].getY() - play.getY() == -57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 114, play.getY() - 114, 55, 55);
return;
}
}
if (ex - play.getX() >= 114 && ex - play.getX() <= 170 && ey - play.getY() >= 114 && ey - play.getY() <= 170) {
for(i = 0; i < 32; ++i) {
if (playQ[i].isVisible() && playQ[i].getX() == play.getX() + 57 && playQ[i].getY() - play.getY() == 57) {
move = true;
break;
}
}
if (!move) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 114, play.getY() + 114, 55, 55);
return;
}
}
}
}
}
public void elephantEat(JLabel play, JLabel[] playQ, JLabel enemy, List chessRegretList, int man, int beEat) {
boolean canGo = true;
int judge = play.getName().charAt(1) - 48;
int i;
ChessRegret chessRegret;
if (play.getX() - 114 == enemy.getX() && play.getY() - 114 == enemy.getY() && (judge == 1 && enemy.getY() <= 455 || judge == 2 && enemy.getY() >= 512)) {
for(i = 0; i < 32; ++i) {
if (playQ[i].getX() == play.getX() - 57 && playQ[i].getY() == play.getY() - 57 && playQ[i].isVisible()) {
canGo = false;
}
}
if (canGo) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (play.getX() + 114 == enemy.getX() && play.getY() - 114 == enemy.getY() && (judge == 1 && enemy.getY() <= 455 || judge == 2 && enemy.getY() >= 512)) {
for(i = 0; i < 32; ++i) {
if (playQ[i].getX() == play.getX() + 57 && playQ[i].getY() == play.getY() - 57 && playQ[i].isVisible()) {
canGo = false;
}
}
if (canGo) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (play.getX() - 114 == enemy.getX() && play.getY() + 114 == enemy.getY() && (judge == 1 && enemy.getY() <= 455 || judge == 2 && enemy.getY() >= 512)) {
for(i = 0; i < 32; ++i) {
if (playQ[i].getX() == play.getX() - 57 && playQ[i].getY() == play.getY() + 57 && playQ[i].isVisible()) {
canGo = false;
}
}
if (canGo) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (play.getX() + 114 == enemy.getX() && play.getY() + 114 == enemy.getY() && (judge == 1 && enemy.getY() <= 455 || judge == 2 && enemy.getY() >= 512)) {
for(i = 0; i < 32; ++i) {
if (playQ[i].getX() == play.getX() + 57 && playQ[i].getY() == play.getY() + 57 && playQ[i].isVisible()) {
canGo = false;
}
}
if (canGo) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
}
public void chapRule(JLabel play, JLabel[] playQ, MouseEvent me, List chessRegretList, int man) {
int judge = play.getName().charAt(1) - 48;
int ex = me.getX();
int ey = me.getY() + 30;
ChessRegret chessRegret;
if (ex - play.getX() >= 57 && ex - play.getX() <= 113 && play.getY() - ey > 0 && play.getY() - ey <= 57) {
if (judge == 1 && play.getX() + 57 >= 252 && play.getX() + 57 <= 309) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY() - 57, 55, 55);
}
if (judge == 2 && play.getY() - 57 <= 512 && play.getY() - 57 >= 455 && play.getX() + 57 >= 252 && play.getX() + 57 <= 309) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY() - 57, 55, 55);
}
}
if (ex - play.getX() >= 57 && ex - play.getX() <= 113 && ey - play.getY() > 0 && ey - play.getY() <= 113) {
if (judge == 1 && play.getX() + 57 <= 309 && play.getX() + 57 >= 252) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY() + 57, 55, 55);
}
if (judge == 2 && play.getY() + 57 <= 569 && play.getY() + 57 >= 512 && play.getX() + 57 >= 252 && play.getX() + 57 <= 309) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY() + 57, 55, 55);
}
}
if (play.getX() - ex > 0 && play.getX() - ex <= 57 && play.getY() - ey > 0 && play.getY() - ey <= 57) {
if (judge == 1 && play.getX() - 57 >= 195 && play.getX() - 57 <= 252) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 57, play.getY() - 57, 55, 55);
}
if (judge == 2 && play.getY() - 57 <= 512 && play.getY() - 57 >= 455) {
play.setBounds(play.getX() - 57, play.getY() - 57, 55, 55);
}
}
if (play.getX() - ex > 0 && play.getX() - ex <= 57 && ey - play.getY() > 0 && ey - play.getY() <= 113) {
if (judge == 1 && play.getX() - 57 >= 195 && play.getX() - 57 <= 252) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 57, play.getY() + 57, 55, 55);
}
if (judge == 2 && play.getY() + 57 <= 569 && play.getY() + 57 >= 512 && (play.getX() == 252 || play.getX() == 309)) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 57, play.getY() + 57, 55, 55);
}
}
}
public void chapEat(JLabel play, JLabel[] playQ, JLabel enemy, List chessRegretList, int man, int beEat) {
boolean canGo = true;
int judge = play.getName().charAt(1) - 48;
ChessRegret chessRegret;
if (enemy.getX() == play.getX() - 57 && enemy.getY() == play.getY() - 57) {
if (judge == 1 && (enemy.getY() == 56 && enemy.getX() == 195 || enemy.getY() == 113 && enemy.getX() == 252)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && (enemy.getY() == 455 && enemy.getX() == 195 || enemy.getY() == 512 && enemy.getX() == 252)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (enemy.getX() == play.getX() + 57 && enemy.getY() == play.getY() - 57) {
if (judge == 1 && (enemy.getY() == 56 && enemy.getX() == 309 || enemy.getY() == 113 && enemy.getX() == 252)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && (enemy.getY() == 455 && enemy.getX() == 309 || enemy.getY() == 512 && enemy.getX() == 252)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (enemy.getX() == play.getX() - 57 && enemy.getY() == play.getY() + 57) {
if (judge == 1 && (enemy.getY() == 170 && enemy.getX() == 195 || enemy.getY() == 113 && enemy.getX() == 252)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && (enemy.getY() == 569 && enemy.getX() == 195 || enemy.getY() == 512 && enemy.getX() == 252)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (enemy.getX() == play.getX() + 57 && enemy.getY() == play.getY() + 57) {
if (judge == 1 && (enemy.getY() == 170 && enemy.getX() == 309 || enemy.getY() == 113 && enemy.getX() == 252)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && (enemy.getY() == 569 && enemy.getX() == 309 || enemy.getY() == 512 && enemy.getX() == 252)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
}
public void masterRule(JLabel play, JLabel[] playQ, MouseEvent me, List chessRegretList, int man) {
int ex = me.getX();
int ey = me.getY() + 30;
int judge = play.getName().charAt(1) - 48;
ChessRegret chessRegret;
if (me.getX() - play.getX() >= 0 && me.getX() - play.getX() < 57 && play.getY() - ey > 0 && play.getY() - ey <= 57) {
if (judge == 1 && (play.getX() == 195 || play.getX() == 309 || play.getX() == 252) && (play.getY() == 113 || play.getY() == 170)) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX(), play.getY() - 57, 55, 55);
}
if (judge == 2 && (play.getX() == 195 || play.getX() == 309 || play.getX() == 252) && (play.getY() == 512 || play.getY() == 569)) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX(), play.getY() - 57, 55, 55);
}
}
if (me.getX() - play.getX() >= 0 && me.getX() - play.getX() < 57 && ey - play.getY() >= 57 && ey - play.getY() <= 113) {
if (judge == 1 && (play.getX() == 195 || play.getX() == 309 || play.getX() == 252) && (play.getY() == 56 || play.getY() == 113)) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX(), play.getY() + 57, 55, 55);
}
if (judge == 2 && (play.getX() == 195 || play.getX() == 309 || play.getX() == 252) && (play.getY() == 512 || play.getY() == 455)) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX(), play.getY() + 57, 55, 55);
}
}
if (ey - play.getY() >= 0 && ey - play.getY() <= 56 && play.getX() - ex > 0 && play.getX() - ex <= 57) {
if (judge == 1 && (play.getX() == 252 || play.getX() == 309) && (play.getY() == 56 || play.getY() == 113 || play.getY() == 170)) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 57, play.getY(), 55, 55);
}
if (judge == 2 && (play.getX() == 252 || play.getX() == 309) && (play.getY() == 569 || play.getY() == 512 || play.getY() == 455)) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 57, play.getY(), 55, 55);
}
}
if (ey - play.getY() >= 0 && ey - play.getY() <= 56 && ex - play.getX() >= 57 && ex - play.getX() <= 113) {
if (judge == 1 && (play.getX() == 252 || play.getX() == 195) && (play.getY() == 56 || play.getY() == 113 || play.getY() == 170)) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY(), 55, 55);
}
if (judge == 2 && (play.getX() == 252 || play.getX() == 195) && (play.getY() == 569 || play.getY() == 512 || play.getY() == 455)) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY(), 55, 55);
}
}
}
public void masterEat(JLabel play, JLabel[] playQ, JLabel enemy, List chessRegretList, int man, int beEat) {
boolean canGo = true;
int judge = play.getName().charAt(1) - 48;
ChessRegret chessRegret;
if (enemy.getX() == play.getX() && enemy.getY() == play.getY() - 57) {
if (judge == 1 && (enemy.getX() == 252 && enemy.getY() == 56 || enemy.getX() == 252 && enemy.getY() == 113 || enemy.getX() == 195 && enemy.getY() == 56 || enemy.getX() == 195 && enemy.getY() == 113 || enemy.getX() == 309 && enemy.getY() == 56 || enemy.getX() == 309 && enemy.getY() == 113)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && (enemy.getX() == 252 && enemy.getY() == 455 || enemy.getX() == 252 && enemy.getY() == 512 || enemy.getX() == 195 && enemy.getY() == 455 || enemy.getX() == 195 && enemy.getY() == 512 || enemy.getX() == 309 && enemy.getY() == 455 || enemy.getX() == 309 && enemy.getY() == 512)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (enemy.getX() == play.getX() && enemy.getY() == play.getY() + 57) {
if (judge == 1 && (enemy.getX() == 252 && enemy.getY() == 170 || enemy.getX() == 252 && enemy.getY() == 113 || enemy.getX() == 109 && enemy.getY() == 170 || enemy.getX() == 109 && enemy.getY() == 113 || enemy.getX() == 309 && enemy.getY() == 170 || enemy.getX() == 309 && enemy.getY() == 113)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && (enemy.getX() == 252 && enemy.getY() == 569 || enemy.getX() == 252 && enemy.getY() == 512 || enemy.getX() == 109 && enemy.getY() == 569 || enemy.getX() == 109 && enemy.getY() == 512 || enemy.getX() == 309 && enemy.getY() == 569 || enemy.getX() == 309 && enemy.getY() == 512)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (enemy.getX() == play.getX() - 57 && enemy.getY() == play.getY()) {
if (judge == 1 && (enemy.getX() == 252 && enemy.getY() == 56 || enemy.getX() == 195 && enemy.getY() == 56 || enemy.getX() == 252 && enemy.getY() == 113 || enemy.getX() == 195 && enemy.getY() == 113 || enemy.getX() == 252 && enemy.getY() == 170 || enemy.getX() == 195 && enemy.getY() == 170)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && (enemy.getX() == 252 && enemy.getY() == 455 || enemy.getX() == 195 && enemy.getY() == 455 || enemy.getX() == 252 && enemy.getY() == 512 || enemy.getX() == 195 && enemy.getY() == 512 || enemy.getX() == 252 && enemy.getY() == 569 || enemy.getX() == 195 && enemy.getY() == 569)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (enemy.getX() == play.getX() + 57 && enemy.getY() == play.getY()) {
if (judge == 1 && (enemy.getX() == 252 && enemy.getY() == 56 || enemy.getX() == 309 && enemy.getY() == 56 || enemy.getX() == 252 && enemy.getY() == 113 || enemy.getX() == 309 && enemy.getY() == 113 || enemy.getX() == 252 && enemy.getY() == 170 || enemy.getX() == 309 && enemy.getY() == 170)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && (enemy.getX() == 252 && enemy.getY() == 455 || enemy.getX() == 309 && enemy.getY() == 455 || enemy.getX() == 252 && enemy.getY() == 512 || enemy.getX() == 309 && enemy.getY() == 512 || enemy.getX() == 252 && enemy.getY() == 569 || enemy.getX() == 309 && enemy.getY() == 569)) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
}
public void soliderRule(JLabel play, JLabel[] playQ, MouseEvent me, List chessRegretList, int man) {
int judge = play.getName().charAt(1) - 48;
int ex = me.getX();
int ey = me.getY() + 30;
ChessRegret chessRegret;
if (judge == 1) {
if (me.getX() - play.getX() >= 0 && me.getX() - play.getX() < 57 && ey - play.getY() >= 57 && ey - play.getY() <= 113) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX(), play.getY() + 57, 55, 55);
}
if (play.getY() >= 341 && ey - play.getY() >= 0 && ey - play.getY() <= 56 && ex - play.getX() >= 57 && ex - play.getX() <= 113) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY(), 55, 55);
}
if (play.getY() >= 341 && ey - play.getY() >= 0 && ey - play.getY() <= 56 && play.getX() - ex > 0 && play.getX() - ex <= 57) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 57, play.getY(), 55, 55);
}
}
if (judge == 2) {
if (me.getX() - play.getX() >= 0 && me.getX() - play.getX() < 57 && play.getY() - ey > 0 && play.getY() - ey <= 57) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX(), play.getY() - 57, 55, 55);
}
if (play.getY() <= 284 && ey - play.getY() >= 0 && ey - play.getY() <= 56 && ex - play.getX() >= 57 && ex - play.getX() <= 113) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() + 57, play.getY(), 55, 55);
}
if (play.getY() <= 284 && ey - play.getY() >= 0 && ey - play.getY() <= 56 && play.getX() - ex > 0 && play.getX() - ex <= 57) {
chessRegret = new ChessRegret();
chessRegret.man = man;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegretList.add(chessRegret);
play.setBounds(play.getX() - 57, play.getY(), 55, 55);
}
}
}
public void soliderEat(JLabel play, JLabel[] playQ, JLabel enemy, List chessRegretList, int man, int beEat) {
int judge = play.getName().charAt(1) - 48;
ChessRegret chessRegret;
if (enemy.getX() == play.getX() && enemy.getY() == play.getY() - 57 && judge == 2) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
} else if (enemy.getX() == play.getX() && enemy.getY() == play.getY() + 57 && judge == 1) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
} else {
if (enemy.getX() == play.getX() - 57 && enemy.getY() == play.getY()) {
if (judge == 1 && enemy.getY() >= 341) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && enemy.getY() < 341) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
if (enemy.getX() == play.getX() + 57 && enemy.getY() == play.getY()) {
if (judge == 1 && enemy.getY() >= 341) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
if (judge == 2 && enemy.getY() < 341) {
chessRegret = new ChessRegret();
chessRegret.eatMan = beEat;
chessRegret.cx = play.getX();
chessRegret.cy = play.getY();
chessRegret.man = man;
chessRegretList.add(chessRegret);
enemy.setVisible(false);
play.setBounds(enemy.getX(), enemy.getY(), 55, 55);
return;
}
}
}
}
public int masterMeet(JLabel[] playQ) {
if (playQ[30].getX() != playQ[31].getX()) {
return 0;
} else {
int count = 0;
int cx = playQ[30].getX();
for(int j = playQ[30].getY() + 57; j < playQ[31].getY(); j += 57) {
for(int i = 0; i < 32; ++i) {
if (playQ[i].getX() == cx && playQ[i].getY() == j && playQ[i].isVisible()) {
++count;
}
}
}
if (count > 0) {
return 0;
} else {
return 1;
}
}
}
}
完成以上两部分代码操作了以后,我们可以进行我们最期待的项目演示。
主要负责人 | 团队成员负责模块 |
陶潜 | 主要负责象棋的棋子走向与运行规则的设计 |
流泪的飞 | 象棋的界面设计以及部分棋子的规则执行 |
团队项git地址 https://gitee.com/chinese-chess/chinese-chess
团队成员git提交记录
其中也遇到不少困难,比如象棋的棋子的类型的设计,不知道应该用什么方法去解决这个问题,所以我只能去搜索网上的设计。通过这次课程设计使我明白了自己知识还比较欠缺,只是学习书本知识还是远远不够的,自己不会的东西还有太多,学习需要自己长期的积累,在以后的学习、工作中都应该不断的学习,将课本的理论知识与生活中的实践知识相结合,不断提高自己文化知识和实践能力。