返回顶部
首页 > 资讯 > 后端开发 > Python >Java+Swing实现中国象棋游戏
  • 594
分享到

Java+Swing实现中国象棋游戏

2024-04-02 19:04:59 594人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

目录一、系统介绍1.开发环境2.技术选型3.系统功能二、系统展示三、部分代码一、系统介绍 1.开发环境 开发工具:Eclipse2021 jdk版本:jdk1.8 Mysql版本:8

一、系统介绍

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

--结束END--

本文标题: Java+Swing实现中国象棋游戏

本文链接: https://lsjlt.com/news/138608.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • Java+Swing实现中国象棋游戏
    目录一、系统介绍1.开发环境2.技术选型3.系统功能二、系统展示三、部分代码一、系统介绍 1.开发环境 开发工具:Eclipse2021 JDK版本:jdk1.8 Mysql版本:8...
    99+
    2024-04-02
  • Java实现中国象棋游戏
    目录一、界面二、按钮三、加棋子四、实现棋子的移动五、判断胜负六、按钮“开始游戏”和“重新开始”的实现七、加规则八、轮次九、悔棋十、背景...
    99+
    2024-04-02
  • js实现中国象棋游戏
    本文实例为大家分享了js实现中国象棋游戏的具体代码,供大家参考,具体内容如下 使用table元素作表格,div元素作象棋。 效果如下: 代码如下: <html> <...
    99+
    2024-04-02
  • 怎么用Java实现中国象棋游戏
    本篇内容介绍了“怎么用Java实现中国象棋游戏”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一、界面下棋的棋盘首先要准备好,这就是一个合适大...
    99+
    2023-06-30
  • Java+Swing实现经典五子棋游戏
    目录前言主要需求主要设计功能截图代码实现总结前言 五子棋是世界智力运动会竞技项目之一,是一种两人对弈的纯策略型棋类游戏,是世界智力运动会竞技项目之一,通常双方分别使用黑白两色的棋子,...
    99+
    2024-04-02
  • Python实现人机中国象棋游戏
    目录导语1.游戏规则&基本玩法1.1 基本玩法1.2 行棋规则2.素材文件3.主要代码3.1 Chinachess.py 为主文件3.2 Constants.py 数据常量3...
    99+
    2024-04-02
  • Android实现中国象棋游戏(局域网版)
    本文实例为大家分享了Android实现中国象棋游戏的具体代码,供大家参考,具体内容如下 实现环境:  android studio 3.2.1, 手机分辨率为: 1920 ...
    99+
    2024-04-02
  • Java+Swing实现五子棋游戏的示例代码
    目录一、系统介绍1.开发环境2.技术选型3.系统功能二、系统展示三、部分代码AI.javaChess.javaGobang.javaGobangListener.java一、系统介绍...
    99+
    2024-04-02
  • java swing怎么实现简单的五子棋游戏
    这篇文章将为大家详细讲解有关java swing怎么实现简单的五子棋游戏,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。用java swing写的一个简单的五子棋游戏。下面是Main.java。packag...
    99+
    2023-06-06
  • python实现象棋游戏
    本文实例为大家分享了python实现象棋游戏的具体代码,供大家参考,具体内容如下 import math from turtle import * speed(0)   #调整画的...
    99+
    2024-04-02
  • Android实现象棋游戏
    本文实例为大家分享了Android实现象棋游戏的具体代码,供大家参考,具体内容如下 主要是实现两人对战象棋,没有实现人机对战,主要不会判断下一步棋走那个好,或者对每下一步棋进行打分而...
    99+
    2024-04-02
  • GMchess Linux下的中国象棋游戏
    gmchess,一款Linux下的中国象棋程序       ...
    99+
    2022-06-03
    中国象棋 Linux 游戏
  • 基于c++的中国象棋游戏设计与实现
    目录1.文档2.游戏操作逻辑3.UI框架4.网络通信1.文档 文档分为两部分,一部分在代码中,然后通过doxygen生成HTML。解压本目录下的html.zip后打开index.ht...
    99+
    2024-04-02
  • java实现简单中国象棋
    本文实例为大家分享了java实现简单中国象棋的具体代码,供大家参考,具体内容如下 可以实现简单的人机对战功能,棋子移动会插入关键帧,可以悔棋等功能 运行效果 代码 import j...
    99+
    2024-04-02
  • Java实现五子棋游戏
    本文实例为大家分享了Java实现五子棋游戏的具体代码,供大家参考,具体内容如下 一、功能分析 五子棋的实现还是较为简单的,通过下期的流程我们可以知道大概要实现一下功能: 1、格界面 ...
    99+
    2024-04-02
  • java实现四子棋游戏
    非常简单的四子棋游戏 本人是刚学java的小白,最近在书上看到了有关四子棋游戏的编程题,就试着来写一写,代码也比较简单。 思路 写四子棋的难点是如何判断四个棋子连在一起。 下面给出图...
    99+
    2024-04-02
  • Java实现三子棋游戏
    本文实例为大家分享了Java实现三子棋游戏的具体代码,供大家参考,具体内容如下 一、题目要求 编写程序,实现简单的三子棋游戏。在三子棋中,双方在3×3的棋盘中轮流下棋,一...
    99+
    2024-04-02
  • Java Swing实现坦克大战游戏
    目录一、引言二、效果图三、实现四、完成一、引言 90坦克大战,很经典的一款游戏,当年与小伙伴一人一个手柄,搬上小板凳坐在电视机前,身体时不时跟随手柄摇晃着,时而表情严肃、眉头紧锁,时...
    99+
    2024-04-02
  • Java实现三子棋小游戏
    # 前言 之前在学习C语言的时候,做过一个三子棋的小游戏,最近开始学习Java,就想着能不能用Java再把之前的练习重新实现一边,既然有这个想法了,那就开始行动啦~。 再写的过程中...
    99+
    2024-04-02
  • java实现马踏棋盘游戏
    用java实现马踏棋盘游戏算法,供大家参考,具体内容如下 在4399小游戏中有这样一个游戏 这是代码实现 package com.HorseChess; import java....
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作