我的编程空间,编程开发者的网络收藏夹
学习永远不晚

Java+Swing实现中国象棋游戏

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

Java+Swing实现中国象棋游戏

一、系统介绍

1.开发环境

开发工具:Eclipse2021

JDK版本:jdk1.8

Mysql版本:8.0.13

2.技术选型

Java+Swing

3.系统功能

实现中国象棋游戏,开始游戏,悔棋,退出功能。

二、系统展示

1.首页

2.红旗走

3.黑棋走

三、部分代码

ChineseCheseRule.java

package com.sjsq;
 
import java.awt.event.MouseEvent;
 
import javax.swing.JLabel;
 

public class ChineseCheseRule {
	
	public void armsRule(int Man, JLabel chessMain, MouseEvent me) {
		int boardX = Math.round((float) (me.getX() - 24) / 57) * 57 + 24;
		int boardY = Math.round((float) (me.getY() - 56) / 57) * 57 + 56;
		// 黑卒向下
		if (Man < 21) {
			// 向下移动
			if (boardY - chessMain.getY() == 57 && boardX == chessMain.getX()
					&& boardY <= 569) {
				ChineseChessMainFrame.list.add(String.valueOf(1));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(Man));
				chessMain.setBounds(chessMain.getX(), chessMain.getY() + 57,
						55, 55);
			}
			// 向右移动,必须过河
			else if (chessMain.getY() >= 341 && boardY == chessMain.getY()
					&& boardX - chessMain.getX() == 57 && boardX <= 480) {
				ChineseChessMainFrame.list.add(String.valueOf(1));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(Man));
				chessMain.setBounds(chessMain.getX() + 57, chessMain.getY(),
						55, 55);
			}
			// 向左移动,必须过河
			else if (chessMain.getY() >= 341 && boardY == chessMain.getY()
					&& chessMain.getX() - boardX == 57 && boardX >= 24) {
				ChineseChessMainFrame.list.add(String.valueOf(1));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(Man));
				chessMain.setBounds(chessMain.getX() - 57, chessMain.getY(),
						55, 55);
			}
		}
		// 红卒向上
		else {
			// 向上移动
			if (chessMain.getY() - boardY == 57 && boardX == chessMain.getX()
					&& boardY >= 56) {
				ChineseChessMainFrame.list.add(String.valueOf(1));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(Man));
				chessMain.setBounds(chessMain.getX(), chessMain.getY() - 57,
						55, 55);
			}
			// 向右移动,必须过河
			else if (chessMain.getY() <= 284 && boardY == chessMain.getY()
					&& boardX - chessMain.getX() == 57 && boardX <= 480) {
				ChineseChessMainFrame.list.add(String.valueOf(1));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(Man));
				chessMain.setBounds(chessMain.getX() + 57, chessMain.getY(),
						55, 55);
			}
			// 向左移动,必须过河
			else if (chessMain.getY() <= 284 && boardY == chessMain.getY()
					&& chessMain.getX() - boardX == 57 && boardX >= 24) {
				ChineseChessMainFrame.list.add(String.valueOf(1));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(Man));
				chessMain.setBounds(chessMain.getX() - 57, chessMain.getY(),
						55, 55);
			}
		}
	}// 卒移动结束
 
	
	public void armsRule(JLabel chessMain1, JLabel chessMain2) {
		// 向右走
		if (chessMain2.getX() - chessMain1.getX() == 57
				&& chessMain1.getY() == chessMain2.getY()
				&& chessMain2.isVisible()
				&& chessMain1.getName().charAt(1) != chessMain2.getName()
						.charAt(1)) {
			// 黑棋要过河才能吃棋
			if (chessMain1.getName().charAt(1) == '1'
					&& chessMain1.getY() >= 341) {
				ChineseChessMainFrame.list.add(String.valueOf(3));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain1
						.getName().substring(2)));
				ChineseChessMainFrame.list.add(String.valueOf(2));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain2
						.getName().substring(2)));
				chessMain2.setVisible(false);
				chessMain1.setBounds(chessMain2.getX(), chessMain2.getY(), 55,
						55);
			}
			// 红棋要过河才能吃棋
			else if (chessMain1.getName().charAt(1) == '2'
					&& chessMain1.getY() <= 284) {
				ChineseChessMainFrame.list.add(String.valueOf(3));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain1
						.getName().substring(2)));
				ChineseChessMainFrame.list.add(String.valueOf(2));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain2
						.getName().substring(2)));
				chessMain2.setVisible(false);
				chessMain1.setBounds(chessMain2.getX(), chessMain2.getY(), 55,
						55);
			}
		}
		// 向左走
		else if (chessMain1.getX() - chessMain2.getX() == 57
				&& chessMain1.getY() == chessMain2.getY()
				&& chessMain2.isVisible()
				&& chessMain1.getName().charAt(1) != chessMain2.getName()
						.charAt(1)) {
			// 黑棋要过河才能吃棋
			if (chessMain1.getName().charAt(1) == '1'
					&& chessMain1.getY() >= 341) {
				ChineseChessMainFrame.list.add(String.valueOf(3));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain1
						.getName().substring(2)));
				ChineseChessMainFrame.list.add(String.valueOf(2));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain2
						.getName().substring(2)));
				chessMain2.setVisible(false);
				chessMain1.setBounds(chessMain2.getX(), chessMain2.getY(), 55,
						55);
			}
			// 红棋要过河才能吃棋
			else if (chessMain1.getName().charAt(1) == '2'
					&& chessMain1.getY() <= 284) {
				ChineseChessMainFrame.list.add(String.valueOf(3));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain1
						.getName().substring(2)));
				ChineseChessMainFrame.list.add(String.valueOf(2));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain2
						.getName().substring(2)));
				chessMain2.setVisible(false);
				chessMain1.setBounds(chessMain2.getX(), chessMain2.getY(), 55,
						55);
			}
		}
		// 向上走或向下走
		else if (chessMain1.getX() == chessMain2.getX()
				&& Math.abs(chessMain1.getY() - chessMain2.getY()) == 57
				&& chessMain2.isVisible()
				&& chessMain1.getName().charAt(1) != chessMain2.getName()
						.charAt(1)) {
			// 黑棋只能向下吃棋
			if (chessMain1.getName().charAt(1) == '1'
					&& chessMain2.getY() - chessMain1.getY() == 57) {
				ChineseChessMainFrame.list.add(String.valueOf(3));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain1
						.getName().substring(2)));
				ChineseChessMainFrame.list.add(String.valueOf(2));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain2
						.getName().substring(2)));
				chessMain2.setVisible(false);
				chessMain1.setBounds(chessMain2.getX(), chessMain2.getY(), 55,
						55);
			}
			// 红棋只能向上吃棋
			else if (chessMain1.getName().charAt(1) == '2'
					&& chessMain1.getY() - chessMain2.getY() == 57) {
				ChineseChessMainFrame.list.add(String.valueOf(3));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain1.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain1
						.getName().substring(2)));
				ChineseChessMainFrame.list.add(String.valueOf(2));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getX()));
				ChineseChessMainFrame.list
						.add(String.valueOf(chessMain2.getY()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMain2
						.getName().substring(2)));
				chessMain2.setVisible(false);
				chessMain1.setBounds(chessMain2.getX(), chessMain2.getY(), 55,
						55);
			}
		}
 
	}// 卒吃结束
 
	
	public void cannonRule(JLabel chessMan, JLabel[] chessman, MouseEvent me) {
		int boardX = Math.round((float) (me.getX() - 24) / 57) * 57 + 24;
		int boardY = Math.round((float) (me.getY() - 56) / 57) * 57 + 56;
		// 起点和终点之间是否有棋子
		int count = 0;
		// 上、下移动
		if (chessMan.getX() == boardX && chessMan.getY() != boardY
				&& boardY >= 56 && boardY <= 569) {
			// 找出在同一条竖线的所有棋子、并不包括自己
			for (int j = 0; j < chessman.length; j++) {
				if (chessman[j].getX() == chessMan.getX()
						&& !chessman[j].getName().equals(chessMan.getName())
						&& chessman[j].isVisible()) {
					if ((chessman[j].getY() > chessMan.getY() && chessman[j]
							.getY() < boardY)
							|| (chessman[j].getY() < chessMan.getY() && chessman[j]
									.getY() > boardY)) {
						count++;
						break;
					}
				}
 
			}
			if (count == 0) {
				ChineseChessMainFrame.list.add(String.valueOf(1));
				ChineseChessMainFrame.list.add(String.valueOf(chessMan.getX()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMan.getY()));
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].getName().equals(chessMan.getName())) {
						ChineseChessMainFrame.list.add(String.valueOf(i));
						break;
					}
				}
				chessMan.setBounds(boardX, boardY, 55, 55);
			}
		}
		// 左、右移动
		if (chessMan.getY() == boardY && chessMan.getX() != boardX
				&& boardX >= 24 && boardX <= 480) {
			// 找出在同一条横线的所有棋子、并不包括自己
			for (int j = 0; j < chessman.length; j++) {
				if (chessman[j].getY() == chessMan.getY()
						&& !chessman[j].getName().equals(chessMan.getName())
						&& chessman[j].isVisible()) {
					if ((chessman[j].getX() > chessMan.getX() && chessman[j]
							.getX() < boardX)
							|| (chessman[j].getX() < chessMan.getX() && chessman[j]
									.getX() > boardX)) {
						count++;
						break;
					}
				}
 
			}
			if (count == 0) {
				ChineseChessMainFrame.list.add(String.valueOf(1));
				ChineseChessMainFrame.list.add(String.valueOf(chessMan.getX()));
				ChineseChessMainFrame.list.add(String.valueOf(chessMan.getY()));
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].getName().equals(chessMan.getName())) {
						ChineseChessMainFrame.list.add(String.valueOf(i));
						break;
					}
				}
				chessMan.setBounds(boardX, boardY, 55, 55);
			}
		}
	}// 炮、车移动方法结束
 
	
	public void cannonRule(int chess, JLabel chessMan, JLabel chessManTake,
			JLabel[] chessman) {
 
		// 起点和终点之间是否有棋子
		int count = 0;
		if (chessMan.getX() == chessManTake.getX()
				&& chessMan.getY() != chessManTake.getY()) {
			// 所有的棋子
			for (int i = 0; i < chessman.length; i++) {
				// 找出在同一条竖线的所有棋子、并不包括自己
				if (chessman[i].getX() == chessMan.getX()
						&& !chessman[i].getName().equals(chessMan.getName())
						&& chessman[i].isVisible()) {
					if ((chessman[i].getY() > chessMan.getY() && chessman[i]
							.getY() < chessManTake.getY())
							|| (chessman[i].getY() < chessMan.getY() && chessman[i]
									.getY() > chessManTake.getY())) {
						count++;
					}
				}
			}
		} else if (chessMan.getY() == chessManTake.getY()
				&& chessMan.getX() != chessManTake.getX()) {
			// 所有的棋子
			for (int i = 0; i < chessman.length; i++) {
				// 找出在同一条横线的所有棋子、并不包括自己
				if (chessman[i].getY() == chessMan.getY()
						&& !chessman[i].getName().equals(chessMan.getName())
						&& chessman[i].isVisible()) {
					if ((chessman[i].getX() > chessMan.getX() && chessman[i]
							.getX() < chessManTake.getX())
							|| (chessman[i].getX() < chessMan.getX() && chessman[i]
									.getX() > chessManTake.getX())) {
						count++;
					}
				}
			}
		}
		// 起点和终点之间只有一个棋子是炮的规则、并不能吃自己的棋子
		if (count == 1
				&& chess == 0
				&& chessMan.getName().charAt(1) != chessManTake.getName()
						.charAt(1)) {
			ChineseChessMainFrame.list.add(String.valueOf(3));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getName()
					.substring(2)));
			ChineseChessMainFrame.list.add(String.valueOf(2));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake
					.getName().substring(2)));
			chessManTake.setVisible(false);
			chessMan.setBounds(chessManTake.getX(), chessManTake.getY(), 55, 55);
		}
		// 起点和终点之间没有棋子是车的规则、并不能吃自己的棋子
		else if (count == 0
				&& chess == 1
				&& chessMan.getName().charAt(1) != chessManTake.getName()
						.charAt(1)) {
			ChineseChessMainFrame.list.add(String.valueOf(3));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getName()
					.substring(2)));
			ChineseChessMainFrame.list.add(String.valueOf(2));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake
					.getName().substring(2)));
			chessManTake.setVisible(false);
			chessMan.setBounds(chessManTake.getX(), chessManTake.getY(), 55, 55);
		}
	}// 炮、车吃棋方法结束
 
	
	public void horseRule(JLabel chessMan, JLabel[] chessman, MouseEvent me) {
		int boardX = Math.round((float) (me.getX() - 24) / 57) * 57 + 24;
		int boardY = Math.round((float) (me.getY() - 56) / 57) * 57 + 56;
		// 保存障碍
		int Move = 0;
		if (boardY >= 56 && boardY <= 569 && boardX >= 24 && boardX <= 480) {
			// 左移、上边
			if (chessMan.getX() - boardX == 114
					&& chessMan.getY() - boardY == 57) {
				// 正前方是否有别的棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessMan.getX() - chessman[i].getX() == 57
							&& chessMan.getY() == chessman[i].getY()
							&& chessman[i].isVisible()) {
						Move = 1;
						break;
					}
				}
				// 可以移动该棋子
				if (Move == 0) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					for (int i = 0; i < chessman.length; i++) {
						if (chessman[i].getName().equals(chessMan.getName())) {
							ChineseChessMainFrame.list.add(String.valueOf(i));
							break;
						}
					}
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 左移、下边
			else if (chessMan.getX() - boardX == 114
					&& boardY - chessMan.getY() == 57) {
				// 正前方是否有别的棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessMan.getX() - chessman[i].getX() == 57
							&& chessMan.getY() == chessman[i].getY()
							&& chessman[i].isVisible()) {
						Move = 1;
						break;
					}
				}
				// 可以移动该棋子
				if (Move == 0) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					for (int i = 0; i < chessman.length; i++) {
						if (chessman[i].getName().equals(chessMan.getName())) {
							ChineseChessMainFrame.list.add(String.valueOf(i));
							break;
						}
					}
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 右移、上边
			else if (boardX - chessMan.getX() == 114
					&& chessMan.getY() - boardY == 57) {
				// 正前方是否有别的棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].getX() - chessMan.getX() == 57
							&& chessMan.getY() == chessman[i].getY()
							&& chessman[i].isVisible()) {
						Move = 1;
						break;
					}
				}
				// 可以移动该棋子
				if (Move == 0) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					for (int i = 0; i < chessman.length; i++) {
						if (chessman[i].getName().equals(chessMan.getName())) {
							ChineseChessMainFrame.list.add(String.valueOf(i));
							break;
						}
					}
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 右移、下边
			else if (boardX - chessMan.getX() == 114
					&& boardY - chessMan.getY() == 57) {
				// 正前方是否有别的棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].getX() - chessMan.getX() == 57
							&& chessMan.getY() == chessman[i].getY()
							&& chessman[i].isVisible()) {
						Move = 1;
						break;
					}
				}
				// 可以移动该棋子
				if (Move == 0) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					for (int i = 0; i < chessman.length; i++) {
						if (chessman[i].getName().equals(chessMan.getName())) {
							ChineseChessMainFrame.list.add(String.valueOf(i));
							break;
						}
					}
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 上移、左边
			else if (chessMan.getX() - boardX == 57
					&& chessMan.getY() - boardY == 114) {
				// 正前方是否有别的棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessMan.getY() - chessman[i].getY() == 57
							&& chessMan.getX() == chessman[i].getX()
							&& chessman[i].isVisible()) {
						Move = 1;
						break;
					}
				}
				// 可以移动该棋子
				if (Move == 0) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					for (int i = 0; i < chessman.length; i++) {
						if (chessman[i].getName().equals(chessMan.getName())) {
							ChineseChessMainFrame.list.add(String.valueOf(i));
							break;
						}
					}
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 上移、右边
			else if (boardX - chessMan.getX() == 57
					&& chessMan.getY() - boardY == 114) {
				// 正前方是否有别的棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessMan.getY() - chessman[i].getY() == 57
							&& chessMan.getX() == chessman[i].getX()
							&& chessman[i].isVisible()) {
						Move = 1;
						break;
					}
				}
				// 可以移动该棋子
				if (Move == 0) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					for (int i = 0; i < chessman.length; i++) {
						if (chessman[i].getName().equals(chessMan.getName())) {
							ChineseChessMainFrame.list.add(String.valueOf(i));
							break;
						}
					}
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 下移、左边
			else if (chessMan.getX() - boardX == 57
					&& boardY - chessMan.getY() == 114) {
				// 正前方是否有别的棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].getY() - chessMan.getY() == 57
							&& chessMan.getX() == chessman[i].getX()
							&& chessman[i].isVisible()) {
						Move = 1;
						break;
					}
				}
				// 可以移动该棋子
				if (Move == 0) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					for (int i = 0; i < chessman.length; i++) {
						if (chessman[i].getName().equals(chessMan.getName())) {
							ChineseChessMainFrame.list.add(String.valueOf(i));
							break;
						}
					}
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 下移、右边
			else if (boardX - chessMan.getX() == 57
					&& boardY - chessMan.getY() == 114) {
				// 正前方是否有别的棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].getY() - chessMan.getY() == 57
							&& chessMan.getX() == chessman[i].getX()
							&& chessman[i].isVisible()) {
						Move = 1;
						break;
					}
				}
				// 可以移动该棋子
				if (Move == 0) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					for (int i = 0; i < chessman.length; i++) {
						if (chessman[i].getName().equals(chessMan.getName())) {
							ChineseChessMainFrame.list.add(String.valueOf(i));
							break;
						}
					}
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
		}
	}// 马移动结束
 
	
	public void horseRule(JLabel chessMan, JLabel chessManTake,
			JLabel[] chessman) {
		// 保存障碍
		int Move = 0;
		boolean Chess = false;
		// 左移、上边
		if (chessMan.getName().charAt(1) != chessManTake.getName().charAt(1)
				&& chessMan.getX() - chessManTake.getX() == 114
				&& chessMan.getY() - chessManTake.getY() == 57) {
			// 正前方是否有别的棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessMan.getX() - chessman[i].getX() == 57
						&& chessMan.getY() == chessman[i].getY()
						&& chessman[i].isVisible()) {
					Move = 1;
					break;
				}
			}
			Chess = true;
		}
		// 左移、下边
		else if (chessMan.getName().charAt(1) != chessManTake.getName().charAt(
				1)
				&& chessMan.getX() - chessManTake.getX() == 114
				&& chessManTake.getY() - chessMan.getY() == 57) {
			// 正前方是否有别的棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessMan.getX() - chessman[i].getX() == 57
						&& chessMan.getY() == chessman[i].getY()
						&& chessman[i].isVisible()) {
					Move = 1;
					break;
				}
			}
			Chess = true;
		}
		// 右移、上边
		else if (chessMan.getName().charAt(1) != chessManTake.getName().charAt(
				1)
				&& chessManTake.getX() - chessMan.getX() == 114
				&& chessMan.getY() - chessManTake.getY() == 57) {
			// 正前方是否有别的棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessman[i].getX() - chessMan.getX() == 57
						&& chessMan.getY() == chessman[i].getY()
						&& chessman[i].isVisible()) {
					Move = 1;
					break;
				}
			}
			Chess = true;
		}
		// 右移、下边
		else if (chessMan.getName().charAt(1) != chessManTake.getName().charAt(
				1)
				&& chessManTake.getX() - chessMan.getX() == 114
				&& chessManTake.getY() - chessMan.getY() == 57) {
			// 正前方是否有别的棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessman[i].getX() - chessMan.getX() == 57
						&& chessMan.getY() == chessman[i].getY()
						&& chessman[i].isVisible()) {
					Move = 1;
					break;
				}
			}
			Chess = true;
		}
		// 上移、左边
		else if (chessMan.getName().charAt(1) != chessManTake.getName().charAt(
				1)
				&& chessMan.getX() - chessManTake.getX() == 57
				&& chessMan.getY() - chessManTake.getY() == 114) {
			// 正前方是否有别的棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessMan.getY() - chessman[i].getY() == 57
						&& chessMan.getX() == chessman[i].getX()
						&& chessman[i].isVisible()) {
					Move = 1;
					break;
				}
			}
			Chess = true;
		}
		// 上移、右边
		else if (chessMan.getName().charAt(1) != chessManTake.getName().charAt(
				1)
				&& chessManTake.getX() - chessMan.getX() == 57
				&& chessMan.getY() - chessManTake.getY() == 114) {
			// 正前方是否有别的棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessMan.getY() - chessman[i].getY() == 57
						&& chessMan.getX() == chessman[i].getX()
						&& chessman[i].isVisible()) {
					Move = 1;
					break;
				}
			}
			Chess = true;
		}
		// 下移、左边
		else if (chessMan.getName().charAt(1) != chessManTake.getName().charAt(
				1)
				&& chessMan.getX() - chessManTake.getX() == 57
				&& chessManTake.getY() - chessMan.getY() == 114) {
			// 正前方是否有别的棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessman[i].getY() - chessMan.getY() == 57
						&& chessMan.getX() == chessman[i].getX()
						&& chessman[i].isVisible()) {
					Move = 1;
					break;
				}
			}
			Chess = true;
		}
		// 下移、右边
		else if (chessMan.getName().charAt(1) != chessManTake.getName().charAt(
				1)
				&& chessManTake.getX() - chessMan.getX() == 57
				&& chessManTake.getY() - chessMan.getY() == 114) {
			// 正前方是否有别的棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessman[i].getY() - chessMan.getY() == 57
						&& chessMan.getX() == chessman[i].getX()
						&& chessman[i].isVisible()) {
					Move = 1;
					break;
				}
			}
			Chess = true;
		}
		// 没有障碍、并可以吃棋
		if (Move == 0 && Chess) {
			ChineseChessMainFrame.list.add(String.valueOf(3));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getName()
					.substring(2)));
			ChineseChessMainFrame.list.add(String.valueOf(2));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake
					.getName().substring(2)));
			chessManTake.setVisible(false);
			chessMan.setBounds(chessManTake.getX(), chessManTake.getY(), 55, 55);
		}
	}// 马吃棋结束
 
	
	public void elephantRule(int Man, JLabel chessMan, JLabel[] chessman,
			MouseEvent me) {
		// 坐标和障碍
		int boardX = Math.round((float) (me.getX() - 24) / 57) * 57 + 24;
		int boardY = Math.round((float) (me.getY() - 56) / 57) * 57 + 56;
		int Move = 0;
		if (boardY >= 56 && boardY <= 569 && boardX >= 24 && boardX <= 480) {
			// 上左
			if (chessMan.getX() - boardX == 114
					&& chessMan.getY() - boardY == 114) {
				// 左上方是否有棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].isVisible()
							&& chessMan.getX() - chessman[i].getX() == 57
							&& chessMan.getY() - chessman[i].getY() == 57) {
						Move++;
						break;
					}
				}
				// 红旗不能过楚河
				if (Move == 0 && Man > 9 && boardY > 284) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 黑旗不能过汉界
				else if (Move == 0 && Man <= 9 && boardY <= 284) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 上右
			else if (boardX - chessMan.getX() == 114
					&& chessMan.getY() - boardY == 114) {
				// 右上方是否有棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].isVisible()
							&& chessman[i].getX() - chessMan.getX() == 57
							&& chessMan.getY() - chessman[i].getY() == 57) {
						Move++;
						break;
					}
				}
				// 红旗不能过楚河
				if (Move == 0 && Man > 9 && boardY > 284) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 黑旗不能过汉界
				else if (Move == 0 && Man <= 9 && boardY <= 284) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 下左
			else if (chessMan.getX() - boardX == 114
					&& boardY - chessMan.getY() == 114) {
				// 左下方是否有棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].isVisible()
							&& chessMan.getX() - chessman[i].getX() == 57
							&& chessman[i].getY() - chessMan.getY() == 57) {
						Move++;
						break;
					}
				}
				// 红旗不能过楚河
				if (Move == 0 && Man > 9 && boardY > 284) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 黑旗不能过汉界
				else if (Move == 0 && Man <= 9 && boardY <= 284) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 下右
			else if (boardX - chessMan.getX() == 114
					&& boardY - chessMan.getY() == 114) {
				// 右下方是否有棋子
				for (int i = 0; i < chessman.length; i++) {
					if (chessman[i].isVisible()
							&& chessman[i].getX() - chessMan.getX() == 57
							&& chessman[i].getY() - chessMan.getY() == 57) {
						Move++;
						break;
					}
				}
				// 红旗不能过楚河
				if (Move == 0 && Man > 9 && boardY > 284) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 黑旗不能过汉界
				else if (Move == 0 && Man <= 9 && boardY <= 284) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
		}
	}// 相移动规则结束
 
	
	public void elephantRule(JLabel chessMan, JLabel chessManTake,
			JLabel[] chessman) {
		// 障碍
		int Move = 0;
		boolean Chess = false;
		// 上左
		if (chessMan.getX() - chessManTake.getX() == 114
				&& chessMan.getY() - chessManTake.getY() == 114) {
			// 左上方是否有棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessman[i].isVisible()
						&& chessMan.getX() - chessman[i].getX() == 57
						&& chessMan.getY() - chessman[i].getY() == 57) {
					Move++;
					break;
				}
			}
			Chess = true;
		}
		// 上右
		else if (chessManTake.getX() - chessMan.getX() == 114
				&& chessMan.getY() - chessManTake.getY() == 114) {
			// 右上方是否有棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessman[i].isVisible()
						&& chessman[i].getX() - chessMan.getX() == 57
						&& chessMan.getY() - chessman[i].getY() == 57) {
					Move++;
					break;
				}
			}
			Chess = true;
		}
		// 下左
		else if (chessMan.getX() - chessManTake.getX() == 114
				&& chessManTake.getY() - chessMan.getY() == 114) {
			// 左下方是否有棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessman[i].isVisible()
						&& chessMan.getX() - chessman[i].getX() == 57
						&& chessman[i].getY() - chessMan.getY() == 57) {
					Move++;
					break;
				}
			}
			Chess = true;
		}
		// 下右
		else if (chessManTake.getX() - chessMan.getX() == 114
				&& chessManTake.getY() - chessMan.getY() == 114) {
			// 右下方是否有棋子
			for (int i = 0; i < chessman.length; i++) {
				if (chessman[i].isVisible()
						&& chessman[i].getX() - chessMan.getX() == 57
						&& chessman[i].getY() - chessMan.getY() == 57) {
					Move++;
					break;
				}
			}
			Chess = true;
		}
		// 没有障碍、并不能吃自己的棋子
		if (Chess
				&& Move == 0
				&& chessMan.getName().charAt(1) != chessManTake.getName()
						.charAt(1)) {
			ChineseChessMainFrame.list.add(String.valueOf(3));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getName()
					.substring(2)));
			ChineseChessMainFrame.list.add(String.valueOf(2));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake
					.getName().substring(2)));
			chessManTake.setVisible(false);
			chessMan.setBounds(chessManTake.getX(), chessManTake.getY(), 55, 55);
		}
	}// 相、象吃棋规则结束
 
	
	public void chapRule(int Man, JLabel chessMan, JLabel[] chessman,
			MouseEvent me) {
		// 坐标
		int boardX = Math.round((float) (me.getX() - 24) / 57) * 57 + 24;
		int boardY = Math.round((float) (me.getY() - 56) / 57) * 57 + 56;
		if (boardY >= 56 && boardY <= 569 && boardX >= 24 && boardX <= 480) {
			// 上左
			if (chessMan.getX() - boardX == 57
					&& chessMan.getY() - boardY == 57) {
				// 士不能超过自己的界限
				if (Man < 14 && boardX >= 195 && boardX <= 252 && boardY >= 56
						&& boardY <= 113) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 仕不能超过自己的界限
				else if (Man > 13 && boardX >= 195 && boardX <= 252
						&& boardY >= 455 && boardY <= 512) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 上右
			else if (boardX - chessMan.getX() == 57
					&& chessMan.getY() - boardY == 57) {
				// 士不能超过自己的界限
				if (Man < 14 && boardX >= 252 && boardX <= 309 && boardY >= 56
						&& boardY <= 113) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 仕不能超过自己的界限
				else if (Man > 13 && boardX >= 252 && boardX <= 309
						&& boardY >= 455 && boardY <= 512) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 下左
			else if (chessMan.getX() - boardX == 57
					&& boardY - chessMan.getY() == 57) {
				// 士不能超过自己的界限
				if (Man < 14 && boardX >= 195 && boardX <= 252 && boardY >= 113
						&& boardY <= 170) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 仕不能超过自己的界限
				else if (Man > 13 && boardX >= 195 && boardX <= 252
						&& boardY >= 512 && boardY <= 569) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 下右
			else if (boardX - chessMan.getX() == 57
					&& boardY - chessMan.getY() == 57) {
				// 士不能超过自己的界限
				if (Man < 14 && boardX >= 252 && boardX <= 309 && boardY >= 113
						&& boardY <= 170) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 仕不能超过自己的界限
				else if (Man > 13 && boardX >= 252 && boardX <= 309
						&& boardY >= 512 && boardY <= 569) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
		}
	}// 士移动规则结束
 
	
	public void chapRule(int Man, JLabel chessMan, JLabel chessManTake,
			JLabel[] chessman) {
		// 当前状态
		boolean Chap = false;
		// 上左
		if (chessMan.getX() - chessManTake.getX() == 57
				&& chessMan.getY() - chessManTake.getY() == 57) {
			// 士不能超过自己的界限
			if (Man < 14 && chessManTake.getX() >= 195
					&& chessManTake.getX() <= 252 && chessManTake.getY() >= 56
					&& chessManTake.getY() <= 113 && chessManTake.isVisible()) {
				Chap = true;
			}
			// 仕不能超过自己的界限
			else if (Man > 13 && chessManTake.getX() >= 195
					&& chessManTake.getX() <= 252 && chessManTake.getY() >= 455
					&& chessManTake.getY() <= 512 && chessManTake.isVisible()) {
				Chap = true;
			}
		}
		// 上右
		else if (chessManTake.getX() - chessMan.getX() == 57
				&& chessMan.getY() - chessManTake.getY() == 57) {
			// 士不能超过自己的界限
			if (Man < 14 && chessManTake.getX() >= 252
					&& chessManTake.getX() <= 309 && chessManTake.getY() >= 56
					&& chessManTake.getY() <= 113 && chessManTake.isVisible()) {
				Chap = true;
			}
			// 仕不能超过自己的界限
			else if (Man > 13 && chessManTake.getX() >= 252
					&& chessManTake.getX() <= 309 && chessManTake.getY() >= 455
					&& chessManTake.getY() <= 512 && chessManTake.isVisible()) {
				Chap = true;
			}
		}
		// 下左
		else if (chessMan.getX() - chessManTake.getX() == 57
				&& chessManTake.getY() - chessMan.getY() == 57) {
			// 士不能超过自己的界限
			if (Man < 14 && chessManTake.getX() >= 195
					&& chessManTake.getX() <= 252 && chessManTake.getY() >= 113
					&& chessManTake.getY() <= 170 && chessManTake.isVisible()) {
				Chap = true;
			}
			// 仕不能超过自己的界限
			else if (Man > 13 && chessManTake.getX() >= 195
					&& chessManTake.getX() <= 252 && chessManTake.getY() >= 512
					&& chessManTake.getY() <= 569 && chessManTake.isVisible()) {
				Chap = true;
			}
		}
		// 下右
		else if (chessManTake.getX() - chessMan.getX() == 57
				&& chessManTake.getY() - chessMan.getY() == 57) {
			// 士不能超过自己的界限
			if (Man < 14 && chessManTake.getX() >= 252
					&& chessManTake.getX() <= 309 && chessManTake.getY() >= 113
					&& chessManTake.getY() <= 170 && chessManTake.isVisible()) {
				Chap = true;
			}
			// 仕不能超过自己的界限
			else if (Man > 13 && chessManTake.getX() >= 252
					&& chessManTake.getX() <= 309 && chessManTake.getY() >= 512
					&& chessManTake.getY() <= 569 && chessManTake.isVisible()) {
				Chap = true;
			}
		}
		// 可移动、并不能吃自己的棋子
		if (Chap
				&& chessMan.getName().charAt(1) != chessManTake.getName()
						.charAt(1)) {
			ChineseChessMainFrame.list.add(String.valueOf(3));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getName()
					.substring(2)));
			ChineseChessMainFrame.list.add(String.valueOf(2));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake
					.getName().substring(2)));
			chessManTake.setVisible(false);
			chessMan.setBounds(chessManTake.getX(), chessManTake.getY(), 55, 55);
		}
	}// 士、仕吃棋规则结束
 
	
	public void willRule(int Man, JLabel chessMan, JLabel[] chessman,
			MouseEvent me) {
		// 坐标
		int boardX = Math.round((float) (me.getX() - 24) / 57) * 57 + 24;
		int boardY = Math.round((float) (me.getY() - 56) / 57) * 57 + 56;
		if (boardY >= 56 && boardY <= 569 && boardX >= 24 && boardX <= 480) {
			// 上
			if (chessMan.getX() == boardX && chessMan.getY() - boardY == 57) {
				// 将不能超过自己的界限
				if (Man == 30 && boardY >= 56 && boardY <= 113) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 帅不能超过自己的界限
				else if (Man == 31 && boardY >= 455 && boardY <= 512) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 下
			else if (chessMan.getX() == boardX
					&& boardY - chessMan.getY() == 57) {
				// 将不能超过自己的界限
				if (Man == 30 && boardY >= 113 && boardY <= 170) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 帅不能超过自己的界限
				else if (Man == 31 && boardY >= 512 && boardY <= 569) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 左
			else if (chessMan.getY() == boardY
					&& chessMan.getX() - boardX == 57) {
				// 将不能超过自己的界限
				if (Man == 30 && boardX >= 195 && boardX <= 252) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 帅不能超过自己的界限
				else if (Man == 31 && boardX >= 195 && boardX <= 252) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
			// 右
			else if (chessMan.getY() == boardY
					&& boardX - chessMan.getX() == 57) {
				// 将不能超过自己的界限
				if (Man == 30 && boardX >= 252 && boardX <= 309) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
				// 帅不能超过自己的界限
				else if (Man == 31 && boardX >= 252 && boardX <= 309) {
					ChineseChessMainFrame.list.add(String.valueOf(1));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getX()));
					ChineseChessMainFrame.list.add(String.valueOf(chessMan
							.getY()));
					ChineseChessMainFrame.list.add(String.valueOf(Man));
					chessMan.setBounds(boardX, boardY, 55, 55);
				}
			}
		}
	}// 将、帅移动规则结束
 
	
	public void willRule(int Man, JLabel chessMan, JLabel chessManTake,
			JLabel[] chessman) {
		// 当前状态
		boolean will = false;
		int count = 0;
 
		if (chessMan.getX() == chessManTake.getX()
				&& chessMan.getName().charAt(0) == '将'
				&& chessManTake.getName().charAt(0) == '将') {
			for (int i = 0; i < chessman.length; i++) {
				if (chessman[i].getX() == chessMan.getX()
						&& !chessman[i].getName().equals(chessMan.getName())
						&& !chessman[i].getName()
								.equals(chessManTake.getName())
						&& chessman[i].isVisible()) {
					count++;
				}
			}
			if (count == 0) {
				will = true;
			}
		}
		// 上
		else if (chessMan.getX() == chessManTake.getX()
				&& chessMan.getY() - chessManTake.getY() == 57) {
 
			// 将不能超过自己的界限
			if (Man == 30 && chessManTake.getY() >= 56
					&& chessManTake.getY() <= 113) {
				will = true;
			}
			// 帅不能超过自己的界限
			else if (Man == 31 && chessManTake.getY() >= 455
					&& chessManTake.getY() <= 512) {
				will = true;
			}
		}
		// 下
		else if (chessMan.getX() == chessManTake.getX()
				&& chessManTake.getY() - chessMan.getY() == 57) {
			// 将不能超过自己的界限
			if (Man == 30 && chessManTake.getY() >= 113
					&& chessManTake.getY() <= 170) {
				will = true;
			}
			// 帅不能超过自己的界限
			else if (Man == 31 && chessManTake.getY() >= 512
					&& chessManTake.getY() <= 569) {
				will = true;
			}
		}
		// 左
		else if (chessMan.getY() == chessManTake.getY()
				&& chessMan.getX() - chessManTake.getX() == 57) {
			// 将不能超过自己的界限
			if (Man == 30 && chessManTake.getX() >= 195
					&& chessManTake.getX() <= 252) {
				will = true;
			}
			// 帅不能超过自己的界限
			else if (Man == 31 && chessManTake.getX() >= 195
					&& chessManTake.getX() <= 252) {
				will = true;
			}
		}
		// 右
		else if (chessMan.getY() == chessManTake.getY()
				&& chessManTake.getX() - chessMan.getX() == 57) {
			// 将不能超过自己的界限
			if (Man == 30 && chessManTake.getX() >= 252
					&& chessManTake.getX() <= 309) {
				will = true;
			}
			// 帅不能超过自己的界限
			else if (Man == 31 && chessManTake.getX() >= 252
					&& chessManTake.getX() <= 309) {
				will = true;
			}
		}
		if (will
				&& chessMan.getName().charAt(1) != chessManTake.getName()
						.charAt(1)) {
			ChineseChessMainFrame.list.add(String.valueOf(3));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessMan.getName()
					.substring(2)));
			ChineseChessMainFrame.list.add(String.valueOf(2));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getX()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake.getY()));
			ChineseChessMainFrame.list.add(String.valueOf(chessManTake
					.getName().substring(2)));
			chessManTake.setVisible(false);
			chessMan.setBounds(chessManTake.getX(), chessManTake.getY(), 55, 55);
		}
	}// 将、帅吃棋规则结束
 
}

以上就是Java+Swing实现中国象棋游戏的详细内容,更多关于Java Swing象棋的资料请关注编程网其它相关文章!

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

Java+Swing实现中国象棋游戏

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

怎么用Java实现中国象棋游戏

本篇内容介绍了“怎么用Java实现中国象棋游戏”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一、界面下棋的棋盘首先要准备好,这就是一个合适大
2023-06-30

java swing怎么实现简单的五子棋游戏

这篇文章将为大家详细讲解有关java swing怎么实现简单的五子棋游戏,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。用java swing写的一个简单的五子棋游戏。下面是Main.java。packag
2023-06-06

GMchess Linux下的中国象棋游戏

gmchess,一款Linux下的中国象棋程序
2022-06-03

编程热搜

  • Python 学习之路 - Python
    一、安装Python34Windows在Python官网(https://www.python.org/downloads/)下载安装包并安装。Python的默认安装路径是:C:\Python34配置环境变量:【右键计算机】--》【属性】-
    Python 学习之路 - Python
  • chatgpt的中文全称是什么
    chatgpt的中文全称是生成型预训练变换模型。ChatGPT是什么ChatGPT是美国人工智能研究实验室OpenAI开发的一种全新聊天机器人模型,它能够通过学习和理解人类的语言来进行对话,还能根据聊天的上下文进行互动,并协助人类完成一系列
    chatgpt的中文全称是什么
  • C/C++中extern函数使用详解
  • C/C++可变参数的使用
    可变参数的使用方法远远不止以下几种,不过在C,C++中使用可变参数时要小心,在使用printf()等函数时传入的参数个数一定不能比前面的格式化字符串中的’%’符号个数少,否则会产生访问越界,运气不好的话还会导致程序崩溃
    C/C++可变参数的使用
  • css样式文件该放在哪里
  • php中数组下标必须是连续的吗
  • Python 3 教程
    Python 3 教程 Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。 Python
    Python 3 教程
  • Python pip包管理
    一、前言    在Python中, 安装第三方模块是通过 setuptools 这个工具完成的。 Python有两个封装了 setuptools的包管理工具: easy_install  和  pip , 目前官方推荐使用 pip。    
    Python pip包管理
  • ubuntu如何重新编译内核
  • 改善Java代码之慎用java动态编译

目录