Java+Swing实现中国象棋游戏

目录
  • 一、系统介绍
    • 1.开发环境
    • 2.技术选型
    • 3.系统功能
  • 二、系统展示
  • 三、部分代码

一、系统介绍

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象棋的资料请关注我们其它相关文章!

(0)

相关推荐

  • java使用swing绘制国际象棋棋盘

    本文实例为大家分享了java使用swing绘制国际象棋棋盘的具体代码,供大家参考,具体内容如下 1.完整代码 import java.awt.Color; import java.awt.Point; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; public class guo_ji_xiang_qi_qipan { public static void main(

  • java实现象棋小游戏

    本文实例为大家分享了java实现象棋小游戏的具体代码,供大家参考,具体内容如下 用Eclipse编写 java环境1.8jdk 代码如下 package xiangqi象棋; /** *中国象棋Java版V3.0 *源文件:Chess.java *添加功能:实现了当前棋局的保存 **/ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.io.*; //

  • Java实现中国象棋的示例代码

    目录 前言 主要设计 功能截图 代码实现 总结 前言 中国象棋是起源于中国的一种棋,属于二人对抗性游戏的一种,在中国有着悠久的历史.由于用具简单,趣味性强,成为流行极为广泛的棋艺活动. 中国象棋使用方形格状棋盘,圆形棋子共有32个,红黑二色各有16个棋子,摆放和活动在交叉点上.双方交替行棋,先把对方的将(帅)“将死”的一方获胜. 中国象棋是一款具有浓郁中国特色的益智游戏,新增的联网对战,趣味多多,聚会可以约小朋友一起来挑战.精彩的对弈让你感受中国象棋的博大精深. <中国象棋>游戏是用java语

  • Java棋类游戏实践之中国象棋

    本文实例讲述了java实现的中国象棋游戏代码,分享给大家供大家参考,具体代码如下 一.实践目的: 1.鼠标点击.拖动等事件的应用与区别 2.棋谱文件的保存与读取 3.完善象棋的规则. 二.实践内容: 中国象棋历史悠久,吸引了无数的人研究,现对中国象棋的对战和实现棋谱的制作做如下的设计和说明,供大家参考学习. 1.机机对弈,红方先手.在符合规则的情况下拖动棋子到目的地,松鼠标落子. 人人对弈图 2.制作棋谱,选择制作棋谱菜单后,对弈开始,并记录了下棋过程. 选择"制作棋谱"菜单 棋谱制作

  • java实现简单网络象棋游戏

    本文实例为大家分享了java实现网络象棋游戏的具体代码,供大家参考,具体内容如下 游戏规则: 1.将/帅:不能出田字格,不能走斜线,只能前进后退向左向右,每次只走一格: 2.士/仕:不能出田字格,只能走斜线,每次只走一格: 3.象/相:只能走田字格,中间防止蹩脚,不能有棋: 4.马:只能走日,(这个比较麻烦,且看下图标识) 5.车:车只能走直线,这个很好理解,不细说了: 6.炮: 情况一:纯走路-->中间和目的地都不能有棋 情况二:吃棋-–>中间要有一颗棋,目标也有棋,且是敌方的棋,毕竟不能自

  • Java+Swing实现中国象棋游戏

    目录 一.系统介绍 1.开发环境 2.技术选型 3.系统功能 二.系统展示 三.部分代码 一.系统介绍 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.Mouse

  • Java实现中国象棋游戏

    目录 一.界面 二.按钮 三.加棋子 四.实现棋子的移动 五.判断胜负 六.按钮“开始游戏”和“重新开始”的实现 七.加规则 八.轮次 九.悔棋 十.背景 及 提示 本文实例为大家分享了Java实现中国象棋游戏的具体代码,供大家参考,具体内容如下 实现一个小游戏需要知道从哪里下手,一步步实现和完善,对于一个中国象棋的小游戏,我们可以按这样的顺序展开: 一.界面 下棋的棋盘首先要准备好,这就是一个合适大小合适比例合适位置的界面,然后在窗体上画上(没错drawLine的那种画上)n条直线和斜线,具体

  • Java+Swing实现经典五子棋游戏

    目录 前言 主要需求 主要设计 功能截图 代码实现 总结 前言 五子棋是世界智力运动会竞技项目之一,是一种两人对弈的纯策略型棋类游戏,是世界智力运动会竞技项目之一,通常双方分别使用黑白两色的棋子,下在棋盘直线与横线的交叉点上,先形成5子连线者获胜. 棋具与围棋通用,起源于中国上古时代的传统黑白棋种之一.主要流行于华人和汉字文化圈的国家以及欧美一些地区,是世界上最古老的棋. 容易上手,老少皆宜,而且趣味横生,引人入胜:不仅能增强思维能力,提高智力,而且富含哲理,有助于修身养性. 用java语言实现

  • Android实现中国象棋游戏(局域网版)

    本文实例为大家分享了Android实现中国象棋游戏的具体代码,供大家参考,具体内容如下 实现环境:  android studio 3.2.1, 手机分辨率为: 1920 * 1080 局域网 UDP 连接分主活动类,棋类,主机类 代码如下: 清单文件要添加的权限: <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name=

  • java实现简单中国象棋

    本文实例为大家分享了java实现简单中国象棋的具体代码,供大家参考,具体内容如下 可以实现简单的人机对战功能,棋子移动会插入关键帧,可以悔棋等功能 运行效果 代码 import java.awt.Canvas; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

  • java swing实现的扫雷游戏及改进版完整示例

    本文实例讲述了java swing实现的扫雷游戏及改进版.分享给大家供大家参考,具体如下: 版本1: package awtDemo; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JButton; import jav

  • Java Swing实现坦克大战游戏

    一.引言 90坦克大战,很经典的一款游戏,当年与小伙伴一人一个手柄,搬上小板凳坐在电视机前,身体时不时跟随手柄摇晃着,时而表情严肃.眉头紧锁,时而欢呼雀跃.喜笑颜开,全身心投入到游戏中,在消灭一只只坦克.守住关卡.坦克升级.晋级通关的时候,更是手舞足蹈.击掌庆祝,如今想想也是记忆犹新.回味无穷!于是乎就我就自己用java写了一个,找一下当年的感觉,顺便虐一下电脑,嘻嘻嘻嘻嘻(ming式笑声). 二.效果图 三.实现 绘图时将这个鹰的图标用 g.drawImage 的方式绘制在界面中央最下方,然后

  • Python实现人机中国象棋游戏

    目录 导语 1.游戏规则&基本玩法 1.1 基本玩法 1.2 行棋规则 2.素材文件 3.主要代码 3.1 Chinachess.py 为主文件 3.2 Constants.py 数据常量 3.3 Pieces.py 棋子类,走法 3.4 Computer.py 电脑走法计算 3.5 Button.py按钮定义 4.游戏效果 总结 导语 哈喽!哈喽!我是木木子!今日游戏更新——中国象棋上线啦! 中国象棋是一种古老的棋类游戏,大约有两千年的历史. 是中华文明非物质文化经典产物,艺术价值泛属于整个人

  • js实现中国象棋游戏

    本文实例为大家分享了js实现中国象棋游戏的具体代码,供大家参考,具体内容如下 使用table元素作表格,div元素作象棋. 效果如下: 代码如下: <html> <head> <title>中国象棋</title> <meta charset="UTF-8"> <style> table{     margin:10px;     border-collapse:collapse; } table.board{  

随机推荐