Java+Swing实现中国象棋游戏

简介: Java+Swing实现中国象棋游戏

一、系统介绍


1.开发环境


开发工具:Eclipse2021

JDK版本:jdk1.8

Mysql版本:8.0.13


2.技术选型


Java+Swing


3.系统功能


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


二、系统展示


1.首页


c36c6748f7204deb97586c308cc1aae6.jpg


2.黑棋走


abba48a5d3464903ba32b8a74fb574da.jpg


3.红旗走


0f8bc46c59684c0b81047d700e7e62a6.jpg


三、部分代码


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);
    }
  }// 将、帅吃棋规则结束
}


四、其他


1.更多系统


JavaSwing系统系列实现


Java+Swing实现斗地主游戏


Java+Swing实现图书管理系统


Java+Swing实现医院管理系统


Java+Swing实现考试管理系统


Java+Swing实现酒店管理系统


Java+Swing实现超市管理系统


Java+Swing实现电影购票系统


Java+Swing实现仓库管理系统-1


Java+Swing实现仓库管理系统-2


Java+Swing实现进销存管理系统


Java+Swing实现自助取款机系统


Java+Swing实现通讯录管理系统


Java+Swing实现停车场管理系统


Java+Swing实现学生信息管理系统


Java+Swing实现学生宿舍管理系统


Java+Swing实现学生选课管理系统


Java+Swing实现学生成绩管理系统


Java+Swing实现学校教材管理系统


Java+Swing实现学校教务管理系统


Java+Swing实现企业人事管理系统


Java+Swing实现电子相册管理系统


Java+Swing实现超市管理系统-TXT存储数据


Java+Swing实现自助取款机系统-TXT存储数据


Java+Swing实现宠物商店管理系统-TXT存储数据


Java+JSP系统系列实现

Java+JSP实现学生图书管理系统


Java+JSP实现学生信息管理系统


Java+JSP实现用户信息管理系统


Java+Servlet系统系列实现

Java+Servlet+JSP实现航空订票系统


Java+Servlet+JSP实现新闻发布系统


Java+Servlet+JSP学生宿舍管理系统


Java+Servlet+JSP实现图书管理系统


Java+Servlet+JSP实现停车场管理系统


Java+Servlet+JSP实现房屋租赁管理系统


Java+Servlet+JSP实现学生信息管理系统


Java+Servlet+JSP实现学生选课管理系统


Java+Servlet+JSP实现宠物诊所管理系统


Java+Servlet+JSP实现学生成绩管理系统-1


Java+Servlet+JSP实现学生成绩管理系统-2


Java+SSM系统系列实现

Java+SSM+JSP实现图书管理系统


Java+SSM+JSP实现超市订单系统


Java+SSM+JSP实现网上考试系统


Java+SSM+JSP实现宠物商城系统


Java+SSM+Layui实现学生成绩管理系统


Java+SSM+Bootstrap实现学生信息管理系统


Java+SSH系统系列实现

Java+SSH+JSP实现在线考试系统


Java+SSH+JSP实现医院在线挂号系统


Java+Springboot系统系列实现

Java+Springboot+H-ui+Maven实现营销管理系统


Java+Springboot+Bootstrap+Maven实现网上商城系统


Java+Springboot+Bootstrap+Maven实现景区旅游管理系统


1.更多JavaWeb系统请关注专栏。


https://blog.csdn.net/helongqiang/category_10020130.html

https://blog.csdn.net/helongqiang/category_10020130.html


2.更多JavaSwing系统请关注专栏。


https://blog.csdn.net/helongqiang/category_6229101.html

https://blog.csdn.net/helongqiang/category_6229101.html


2.源码下载

Java+Swing实现中国象棋游戏


3.运行项目

请点击以下链接,部署你的项目。


Eclipse如何导入JavaSwing项目超详细图文教程


Eclipse如何导入JavaSwing项目超详细视频教程


4.备注

如有侵权请联系我删除。


5.支持博主

如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!


相关文章
|
6月前
|
前端开发 JavaScript Java
计算机Java项目|java游戏账号交易系统
计算机Java项目|java游戏账号交易系统
计算机Java项目|java游戏账号交易系统
|
5月前
|
Java 索引
Java实现扑克牌游戏 | 随机发牌 ( 过程拆分详解+完整代码 )
Java实现扑克牌游戏 | 随机发牌 ( 过程拆分详解+完整代码 )
118 3
|
2月前
|
开发框架 IDE Java
java制作游戏,如何使用libgdx,入门级别教学
本文是一篇入门级教程,介绍了如何使用libgdx游戏开发框架创建一个简单的游戏项目,包括访问libgdx官网、设置项目、下载项目生成工具,并在IDE中运行生成的项目。
58 1
java制作游戏,如何使用libgdx,入门级别教学
|
4月前
|
安全 Java API
|
4月前
|
人工智能 算法 Java
LeetCode经典算法题:井字游戏+优势洗牌+Dota2参议院java解法
LeetCode经典算法题:井字游戏+优势洗牌+Dota2参议院java解法
54 1
|
4月前
|
SQL Java 数据库连接
【Java】Java Swing 图书管借阅管理系统(源码+论文)【独一无二】
【Java】Java Swing 图书管借阅管理系统(源码+论文)【独一无二】
236 0
|
4月前
|
存储 数据可视化 Java
【Java】Java swing 民宿管理系统 GUI(源码+可视化界面)【独一无二】
【Java】Java swing 民宿管理系统 GUI(源码+可视化界面)【独一无二】
|
6月前
|
Java 数据安全/隐私保护
利用Java图形化界面组件Swing写一个简易的登录界面
利用Java图形化界面组件Swing写一个简易的登录界面
92 1
|
6月前
|
前端开发 JavaScript Java
计算机Java项目|游戏美术外包管理信息系统
计算机Java项目|游戏美术外包管理信息系统
|
6月前
|
Java Windows
基于java Swing编写扫雷游戏设计实现(已调试)
基于java Swing编写扫雷游戏设计实现(已调试)
84 1
下一篇
DataWorks