《java语言程序设计》课程设计中国象棋对弈系统(源码)



《《java语言程序设计》课程设计中国象棋对弈系统(源码)》由会员分享,可在线阅读,更多相关《《java语言程序设计》课程设计中国象棋对弈系统(源码)(42页珍藏版)》请在装配图网上搜索。
1、 数学与应用数学专业Java课程设计报告 《java语言程序设计》课程设计 姓 名: 王 ** 学 号: 指导教师: 班 级: 所在院系: Java语言程序设计实验报告 实验项目名称:中国象棋对弈系统 作者姓名与单位:王浩 数学与应用数学专业 数学081班 摘
2、要: 本文主要是运用java实现具有一定功能的中国象棋对弈系统软件,主要功能如下: a、 象棋对弈:红方先走,然后黑方再走,红黑交替,直到一方获胜。 b、 新游戏:任何时候可以重新开始一盘新的对弈。 c、 悔棋:当走错棋的时候可以悔棋。 d、 信息提示:提示当前信息状态。 e、 简单的帮助文档:象棋规则介绍、软件的简单介绍和编制说明 关键词:java、中国象棋对弈系统 正文: 一 程序设计说明 1.1程序的设计及实现 本系统主要有以下4个模块,每个模块对应一个程序包: 1、engine:搜索引擎包,系统的核心部分。 2、message:网络
3、对战过程中各种消息及其传递机制的类实现包。 3、main:主界面实现包。 4、pieces:棋子及其相关类实现包。 现就各个包中的要点给与说明。 1.1.1 搜索引擎的实现(engine包) (1) BitBoard.java:位棋盘的实现,见2.4节。 (2) CCEvalue.java:评价函数知识类。 本程序使用开源软件“梦入神蛋”的快速评价函数。该函数包含子力价值和棋子所在位置的奖励值。子力价值分别是:帅-0, 仕- 40, 象-40, 马-88, 车-200, 炮-96, 兵-9。帅是无价的,用0表示。以马为例,位置的奖励值如下: 0, -3, 5, 4, 2, 2,
4、 5, 4, 2, 2, -3, 2, 4, 6,10,12,20,10, 8, 2, 2, 4, 6,10,13,11,12,11,15, 2, 0, 5, 7, 7,14,15,19,15, 9, 8, 2,-10, 4,10,15,16,12,11, 6, 2, 0, 5, 7, 7,14,15,19,15, 9, 8, 2, 4, 6,10,13,11,12,11,15, 2, -3, 2, 4, 6,10,12,20,10, 8, 2, 0, -3, 5, 4, 2, 2, 5, 4, 2, 2 上面的每行代表棋盘的一条纵线。其中,-10所在的位置是“窝
5、心马”,所以要罚10分。 (3) ChessPosition.java:动态局面类 包含对局过程中的动态信息,主要实现的是2.4节的各类位棋盘和移子函数。 (4) MoveStruct.java:着法表示类。 (5) PreMove.java:伪合法着法生成模块,见4.1。 (6) MoveSortStruct.java:合法着法的生成及其排序算法,见4.2。 (7) SearchMove.java:搜索算法,实现如下功能: 1)主置换表及开局库 2)Alpha-Beta搜索算法 3)针对吃子着法的静态搜索算法 4)适应性空着裁剪算法:见5.5.2,根据不同情况来调整R值的
6、做法,称为“适应性空着裁剪”(Adaptive Null-Move Pruning),它首先由Ernst Heinz发表在1999年的ICCA杂志上。其内容可以概括为: a. 深度小于或等于6时,用R = 2的空着裁剪进行搜索 b. 深度大于8时,用R = 3; c. 深度是6或7时,如果每方棋子都大于或等于3个,则用 R = 3,否则用 R = 2。 5)带时间控制的迭代加深搜索算法:每次加深搜索都判断时间是否够用。 6)“将军”扩展(加深)搜索算法:当搜索到己方被“将”时,增加搜索的深度。 7)主要变例搜索算法 1.1.2 信息传输机制(message包) 在对弈过程中(
7、主要是网络对弈)需要在对弈双方之间传输各类信息,抽象为各类消息。如时间规则的协定、各方的走子信息等。每方都有消息接收、消息处理和消息发送程序(OuterMsgReceiver、LocalMsgReceiver,QzMessageHandler,MessageSender)。己方的MessageSender与对方的OuterMsgReceiver通过接口SrConnection连接。所有接收的消息放入消息队列QzMsgQueue中,等待消息处理进程QzMessageHandler来处理。所有的消息都封装在QzMessage类对象中,消息的类型通过消息的Header类型(以静态常量存放在MsgHe
8、ader类中)来区分。 1.1.3 棋子(pieces包) Qizi.java包含棋子的信息,如棋子的(在棋盘上的)位置、图片、名称、类型、状态等。PiecesFactory.java以“工厂”模式提供根据棋子类型或其他信息生成相关Qizi对象的方法。 1.2主控模块(main包) 实现了程序界面与消息传递、搜索引擎的集成。 (1) NewBoard.java:棋盘坐标系统及其界面的实现。 (2) CChessApp.java:主界面类,以内部类实现了QzMessageHandler接口、计时规则TimeRule接口以及事件的处理程序,根据需要生成其他的并发线程如消息接收、处理和发
9、送,机器思考(启动搜索引擎),计时显示等。 (3) SetRuleDialog.java:设置规则的对话框。 (4) SetSysInfoDialog.java:设置系统的一些属性如对战模式、连接端口等。 (5) Translation.java:提供了一系列实用方法主要有: 1)FEN串与局面ChessPosition对象之间的转换 2)不同着法表示(见第一章)之间的转换。如“炮二平五”与“Ch2-e2”及“62.5或C2.5“(C和6代表炮)这几种表示法之间的转换 3)棋谱文件的读入和存储。 4)开局库的生成:将近年实战的棋谱文件(可能有几种格式)整理生成开局库。
10、 2、 运行结果: 3、 设计体会: 本次课程设计主要是运用本学期所学到的Java基础知识来设计一个符合要求的中国象棋对弈系统,这期间我遇到了很多的困难,发现了很多的问题,正是在解决问题的期间我才慢慢地熟悉了Java的基础知识,才慢慢学会了如何去按照给定的要求设计出合适的java系统。 通过本次课程设计,我明白了一个道理:无论做什么事情,都必需养成严谨,认真,善思的工作作风遇到问题最好的办法就是请教别人,因为每个人掌握的情况都不一样,一个人不可能做到处处都懂,必须发挥群众的力量,
11、复杂的事情才能够简单化。这一点我深有体会,在很多时候,我遇到的困难或许别人之前就遇到过,向他们请教远比自己在那边摸索来得简单,来得快。 附件 程序代码: import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.io.*; public class Chess{ public static void main(String args[]){ new Ches
12、sMainFrame("中国象棋:观棋不语真君子,棋死无悔大丈夫"); } } class ChessMainFrame extends JFrame implements ActionListener,MouseListener,Runnable{ //玩家 JLabel play[] = new JLabel[32]; //棋盘 JLabel image; //窗格 Container con; //工具栏 JToolBar jmain; //重新开始 JButton anew; //悔棋 JButton repent; //
13、退出 JButton exit; //当前信息 JLabel text; //保存当前操作 Vector Var; //规则类对象(使于调用方法) ChessRule rule; /** ** 单击棋子 ** chessManClick = true 闪烁棋子 并给线程响应 ** chessManClick = false 吃棋子 停止闪烁 并给线程响应 */ boolean chessManClick; /** ** 控制玩家走棋 ** chessPlayClick=1 黑棋走棋 ** chessPlayClick=2 红
14、棋走棋 默认红棋 ** chessPlayClick=3 双方都不能走棋 */ int chessPlayClick=2; //控制棋子闪烁的线程 Thread tmain; //把第一次的单击棋子给线程响应 static int Man,i; ChessMainFrame(){ new ChessMainFrame("中国象棋"); } /** ** 构造函数 ** 初始化图形用户界面 */ ChessMainFrame(String Title){ //获行客格引用 con = this.getContentPane(
15、); con.setLayout(null); //实例化规则类 rule = new ChessRule(); Var = new Vector(); //创建工具栏 jmain = new JToolBar(); text = new JLabel("欢迎使用象棋对弈系统"); //当鼠标放上显示信息 text.setToolTipText("信息提示"); anew = new JButton(" 新 游 戏 "); anew.setToolTipText("重新开始新的一局"); exit = new JButto
16、n(" 退 出 "); exit.setToolTipText("退出象棋程序程序"); repent = new JButton(" 悔 棋 "); repent.setToolTipText("返回到上次走棋的位置"); //把组件添加到工具栏 jmain.setLayout(new GridLayout(0,4)); jmain.add(anew); jmain.add(repent); jmain.add(exit); jmain.add(text); jmain.setBounds(0,0,558,30); con.a
17、dd(jmain); //添加棋子标签 drawChessMan(); //注册按扭监听 anew.addActionListener(this); repent.addActionListener(this); exit.addActionListener(this); //注册棋子移动监听 for (int i=0;i<32;i++){ con.add(play[i]); play[i].addMouseListener(this); } //添加棋盘标签 con.add(image = new JLabel
18、(new ImageIcon("image\\Main.GIF"))); image.setBounds(0,30,558,620); image.addMouseListener(this); //注册窗体关闭监听 this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we){ System.exit(0); } } ); //窗体居中 Dimension screenSize = Tool
19、kit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height){ frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width){ frameSize.width = screenSize.width; } this.setLocation((screenSize.widt
20、h - frameSize.width) / 2 - 280 ,(screenSize.height - frameSize.height ) / 2 - 350); //设置 this.setIconImage(new ImageIcon("image\\红将.GIF").getImage()); this.setResizable(false); this.setTitle(Title); this.setSize(558,670); this.show(); } /** ** 添加棋子方法 */ public void draw
21、ChessMan(){ //流程控制 int i,k; //图标 Icon in; //黑色棋子 //车 in = new ImageIcon("image\\黑车.GIF"); for (i=0,k=24;i<2;i++,k+=456){ play[i] = new JLabel(in); play[i].setBounds(k,56,55,55); play[i].setName("车1"); } //马 in = new ImageIcon("image\\黑马.GIF"); f
22、or (i=4,k=81;i<6;i++,k+=342){ play[i] = new JLabel(in); play[i].setBounds(k,56,55,55); play[i].setName("马1"); } //相 in = new ImageIcon("image\\黑象.GIF"); for (i=8,k=138;i<10;i++,k+=228){ play[i] = new JLabel(in); play[i].setBounds(k,56,55,55); play[i].setName("象1
23、"); } //士 in = new ImageIcon("image\\黑士.GIF"); for (i=12,k=195;i<14;i++,k+=114){ play[i] = new JLabel(in); play[i].setBounds(k,56,55,55); play[i].setName("士1"); } //卒 in = new ImageIcon("image\\黑卒.GIF"); for (i=16,k=24;i<21;i++,k+=114){ play[i] = new JLabel(in
24、); play[i].setBounds(k,227,55,55); play[i].setName("卒1" + i); } //炮 in = new ImageIcon("image\\黑炮.GIF"); for (i=26,k=81;i<28;i++,k+=342){ play[i] = new JLabel(in); play[i].setBounds(k,170,55,55); play[i].setName("炮1" + i); } //将 in = new ImageIcon("image\\
25、黑将.GIF"); play[30] = new JLabel(in); play[30].setBounds(252,56,55,55); play[30].setName("将1"); //红色棋子 //车 in = new ImageIcon("image\\红车.GIF"); for (i=2,k=24;i<4;i++,k+=456){ play[i] = new JLabel(in); play[i].setBounds(k,569,55,55); play[i].setName("车2"); } //马
26、 in = new ImageIcon("image\\红马.GIF"); for (i=6,k=81;i<8;i++,k+=342){ play[i] = new JLabel(in); play[i].setBounds(k,569,55,55); play[i].setName("马2"); } //相 in = new ImageIcon("image\\红象.GIF"); for (i=10,k=138;i<12;i++,k+=228){ play[i] = new JLabel(in); play[i].s
27、etBounds(k,569,55,55); play[i].setName("象2"); } //士 in = new ImageIcon("image\\红士.GIF"); for (i=14,k=195;i<16;i++,k+=114){ play[i] = new JLabel(in); play[i].setBounds(k,569,55,55); play[i].setName("士2"); } //兵 in = new ImageIcon("image\\红卒.GIF"); for (i=21,k=2
28、4;i<26;i++,k+=114){ play[i] = new JLabel(in); play[i].setBounds(k,398,55,55); play[i].setName("卒2" + i); } //炮 in = new ImageIcon("image\\红炮.GIF"); for (i=28,k=81;i<30;i++,k+=342){ play[i] = new JLabel(in); play[i].setBounds(k,455,55,55); play[i].setName("炮2" + i)
29、; } //帅 in = new ImageIcon("image\\红将.GIF"); play[31] = new JLabel(in); play[31].setBounds(252,569,55,55); play[31].setName("帅2"); } /** ** 线程方法控制棋子闪烁 */ public void run(){ while (true){ //单击棋子第一下开始闪烁 if (chessManClick){ play[Man].setVisible(false);
30、 //时间控制 try{ tmain.sleep(200); } catch(Exception e){ } play[Man].setVisible(true); } //闪烁当前提示信息 以免用户看不见 else {text.setVisible(false);//时间控制 try{tmain.sleep(250); } catch(Exception e){ } text.setVisible(true); }
31、 try{tmain.sleep(350); } catch (Exception e){ } } } /** ** 单击棋子方法*/ public void mouseClicked(MouseEvent me){ System.out.println("Mouse");//当前坐标 int Ex=0,Ey=0; //启动线程 if (tmain == null){ tmain = new Thread(this); tmain.start(); } //单击棋盘(移动棋子) if (m
32、e.getSource().equals(image)){//该红棋走棋的时候 if (chessPlayClick == 2 && play[Man].getName().charAt(1) == 2){ Ex = play[Man].getX(); Ey = play[Man].getY();//移动卒、兵 if (Man > 15 && Man < 26){ rule.armsRule(Man,play[Man],me); } //移动炮 else if (Man > 25 && Man < 30){
33、 rule.cannonRule(play[Man],play,me); }//移动车 else if (Man >=0 && Man < 4){ rule.cannonRule(play[Man],play,me); }//移动马 else if (Man > 3 && Man < 8){ rule.horseRule(play[Man],play,me); }//移动相、象 else if (Man > 7 && Man < 12){ rule.elephantRule(Man,play[
34、Man],play,me); }//移动仕、士 else if (Man > 11 && Man < 16){ rule.chapRule(Man,play[Man],play,me); }//移动将、帅 else if (Man == 30 || Man == 31){ rule.willRule(Man,play[Man],play,me); }//是否走棋错误(是否在原地没有动) if (Ex == play[Man].getX() && Ey == play[Man].getY()){
35、 text.setText(" 红棋走棋"); chessPlayClick=2; } else {text.setText(" 黑棋走棋"); chessPlayClick=1; } }//if//该黑棋走棋的时候 else if (chessPlayClick == 1 && play[Man].getName().charAt(1) == 1){ Ex = play[Man].getX(); Ey = play[Man].getY();//
36、移动卒、兵 if (Man > 15 && Man < 26){ rule.armsRule(Man,play[Man],me); }//移动炮 else if (Man > 25 && Man < 30){ rule.cannonRule(play[Man],play,me); }//移动车 else if (Man >=0 && Man < 4){ rule.cannonRule(play[Man],play,me); }//移动马 else if (Man > 3 && Man <
37、8){ rule.horseRule(play[Man],play,me); }//移动相、象 else if (Man > 7 && Man < 12){ rule.elephantRule(Man,play[Man],play,me); }//移动仕、士 else if (Man > 11 && Man < 16){ rule.chapRule(Man,play[Man],play,me); }//移动将、帅 else if (Man == 30 || Man == 31){ rul
38、e.willRule(Man,play[Man],play,me); }//是否走棋错误(是否在原地没有动) if (Ex == play[Man].getX() && Ey == play[Man].getY()){ text.setText(" 黑棋走棋"); chessPlayClick=1; } else {text.setText(" 红棋走棋"); chessPlayClick=2; }}//else if //当前没有操作(停止闪烁)
39、 chessManClick=false; }//if//单击棋子 else{//第一次单击棋子(闪烁棋子) if (!chessManClick){ for (int i=0;i<32;i++){ //被单击的棋子 if (me.getSource().equals(play[i])){ //告诉线程让该棋子闪烁 Man=i; //开始闪烁 chessManClick=true; break; } }//for }//if
40、//第二次单击棋子(吃棋子) else if (chessManClick){//当前没有操作(停止闪烁) chessManClick=false; for (i=0;i<32;i++){ //找到被吃的棋子 if (me.getSource().equals(play[i])){ //该红棋吃棋的时候 if (chessPlayClick == 2 && play[Man].getName().charAt(1) == 2){ Ex = play[Man].getX(); Ey =
41、 play[Man].getY(); //卒、兵吃规则 if (Man > 15 && Man < 26){ rule.armsRule(play[Man],play[i]); } //炮吃规则 else if (Man > 25 && Man < 30){ rule.cannonRule(0,play[Man],play[i],play,me); } //车吃规则 else if (Man >=0 &
42、& Man < 4){ rule.cannonRule(1,play[Man],play[i],play,me); } //马吃规则 else if (Man > 3 && Man < 8){ rule.horseRule(play[Man],play[i],play,me); } //相、象吃规则 else if (Man > 7 && Man < 12){ rule.elephantRule(play[Man],play[i],play);
43、 } //士、仕吃棋规则 else if (Man > 11 && Man < 16){ rule.chapRule(Man,play[Man],play[i],play); } //将、帅吃棋规则 else if (Man == 30 || Man == 31){ rule.willRule(Man,play[Man],play[i],play); play[Man].setVisible(true); } /
44、/是否走棋错误(是否在原地没有动) if (Ex == play[Man].getX() && Ey == play[Man].getY()){ text.setText(" 红棋走棋"); chessPlayClick=2; break; } else{text.setText(" 黑棋走棋"); chessPlayClick=1;break; } }//if //该黑棋吃
45、棋的时候 else if (chessPlayClick == 1 && play[Man].getName().charAt(1) == 1){ Ex = play[Man].getX(); Ey = play[Man].getY(); //卒吃规则 if (Man > 15 && Man < 26){ rule.armsRule(play[Man],play[i]); } //炮吃规则 else if (Man > 25 && Man < 30){
46、 rule.cannonRule(0,play[Man],play[i],play,me); }//车吃规则 else if (Man >=0 && Man < 4){ rule.cannonRule(1,play[Man],play[i],play,me); }//马吃规则 else if (Man > 3 && Man < 8){ rule.horseRule(play[Man],play[i],play,me); } //相、象吃规则
47、 else if (Man > 7 && Man < 12){ rule.elephantRule(play[Man],play[i],play); } //士、仕吃棋规则 else if (Man > 11 && Man < 16){ rule.chapRule(Man,play[Man],play[i],play); } //将、帅吃棋规则 else if (Man == 30 || Man == 31){ rule.willRul
48、e(Man,play[Man],play[i],play); play[Man].setVisible(true); } //是否走棋错误(是否在原地没有动) if (Ex == play[Man].getX() && Ey == play[Man].getY()){text.setText(" 黑棋走棋"); chessPlayClick=1;break; } else { text.setText("
49、红棋走棋"); chessPlayClick=2; break; } }//else if }//if }//for //是否胜利 if (!play[31].isVisible()){ JOptionPane.showConfirmDialog( this,"黑棋胜利","玩家一胜利", JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE); //双方都不可以在走棋了
50、 chessPlayClick=3; text.setText(" 黑棋胜利"); }//if else if (!play[30].isVisible()){ JOptionPane.showConfirmDialog( this,"红棋胜利","玩家二胜利", JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE); chessPlayClick=3; text.setText(" 红棋胜利"); }//else if }//
51、else }//else } public void mousePressed(MouseEvent me){} public void mouseReleased(MouseEvent me){} public void mouseEntered(MouseEvent me){} public void mouseExited(MouseEvent me){} /** ** 定义按钮的事件响应 */ public void actionPerformed(ActionEvent ae) {//重新开始按钮 if (ae.getSource(
52、).equals(anew)){int i,k; //重新排列每个棋子的位置 //黑色棋子 //车 for (i=0,k=24;i<2;i++,k+=456){play[i].setBounds(k,56,55,55); } //马 for (i=4,k=81;i<6;i++,k+=342){play[i].setBounds(k,56,55,55); }//相 for (i=8,k=138;i<10;i++,k+=228){ play[i].setBounds(k,56,55,55); }//士 fo
53、r (i=12,k=195;i<14;i++,k+=114){ play[i].setBounds(k,56,55,55); }//卒 for (i=16,k=24;i<21;i++,k+=114){ play[i].setBounds(k,227,55,55);} //炮 for (i=26,k=81;i<28;i++,k+=342){ play[i].setBounds(k,170,55,55);} //将 play[30].setBounds(252,56,55,55); //红色棋子 //车
54、 for (i=2,k=24;i<4;i++,k+=456){ play[i].setBounds(k,569,55,55);}//马 for (i=6,k=81;i<8;i++,k+=342){ play[i].setBounds(k,569,55,55);}//相 for (i=10,k=138;i<12;i++,k+=228){ play[i].setBounds(k,569,55,55);}//士 for (i=14,k=195;i<16;i++,k+=114){ play[i].setBounds(k,569,55,55
55、);}//兵 for (i=21,k=24;i<26;i++,k+=114){ play[i].setBounds(k,398,55,55);}//炮 for (i=28,k=81;i<30;i++,k+=342){ play[i].setBounds(k,455,55,55);}//帅 play[31].setBounds(252,569,55,55); chessPlayClick = 2; text.setText(" 红棋走棋"); for (i=0;i<32;i++){ play[
56、i].setVisible(true);}//清除Vector中的内容 Var.clear();}//悔棋按钮 else if (ae.getSource().equals(repent)){ try{//获得setVisible属性值 String S = (String)Var.get(Var.size()-4);//获得X坐标 int x = Integer.parseInt((String)Var.get(Var.size()-3));//获得Y坐标 int y = Integer.parseInt((String)Var.get(V
57、ar.size()-2));//获得索引 int M = Integer.parseInt((String)Var.get(Var.size()-1)); //赋给棋子 play[M].setVisible(true); play[M].setBounds(x,y,55,55); if (play[M].getName().charAt(1) == 1){ text.setText(" 黑棋走棋"); chessPlayClick = 1;} else{text.setText("
58、 红棋走棋"); chessPlayClick = 2;}//删除用过的坐标 Var.remove(Var.size()-4); Var.remove(Var.size()-3); Var.remove(Var.size()-2); Var.remove(Var.size()-1);//停止旗子闪烁 chessManClick=false;} catch(Exception e){}}//退出 else if (ae.getSource().equals(exit)){ int j=JO
59、ptionPane.showConfirmDialog(this,"真的要退出吗?","退出", JOptionPane.YES_OPTION,JOptionPane.QUESTION_MESSAGE); if (j == JOptionPane.YES_OPTION){System.exit(0);}}} /*定义中国象棋规则的类*/ class ChessRule {/**卒子的移动规则*/ public void armsRule(int Man,JLabel play,MouseEvent me){//黑卒向下 if (Man < 21){//向下移
60、动、得到终点的坐标模糊成合法的坐标 if ((me.getY()-play.getY()) > 27 && (me.getY()-play.getY()) < 86 && (me.getX()-play.getX()) < 55 && (me.getX()-play.getX()) > 0){ //当前记录添加到集合(用于悔棋) Var.add(String.valueOf(play.isVisible())); Var.add(String.valueOf(play.getX())); Var.add(String.valueOf(p
61、lay.getY())); Var.add(String.valueOf(Man)); play.setBounds(play.getX(),play.getY()+57,55,55);} //向右移动、得到终点的坐标模糊成合法的坐标、必须过河 else if (play.getY() > 284 && (me.getX() - play.getX()) >= 57 && (me.getX() - play.getX()) <= 112){play.setBounds(play.getX()+57,play.getY(),55,55); }//向左移动、
62、得到终点的坐标模糊成合法的坐标、必须过河 else if (play.getY() > 284 && (play.getX() - me.getX()) >= 2 && (play.getX() - me.getX()) <=58){//模糊坐标 play.setBounds(play.getX()-57,play.getY(),55,55);}}//红卒向上 else{//当前记录添加到集合(用于悔棋) Var.add(String.valueOf(play.isVisible())); Var.add(String.valueOf(play
63、.getX())); Var.add(String.valueOf(play.getY())); Var.add(String.valueOf(Man)); //向上移动、得到终点的坐标模糊成合法的坐标 if ((me.getX()-play.getX()) >= 0 && (me.getX()-play.getX()) <= 55 && (play.getY()-me.getY()) >27 && play.getY()-me.getY() < 86){ play.setBounds(play.getX(),play.getY()-57,5
64、5,55);}//向右移动、得到终点的坐标模糊成合法的坐标、必须过河 else if (play.getY() <= 341 && (me.getX() - play.getX()) >= 57 && (me.getX() - play.getX()) <= 112){ play.setBounds(play.getX()+57,play.getY(),55,55);} //向左移动、得到终点的坐标模糊成合法的坐标、必须过河 else if (play.getY() <= 341 && (play.getX() - me.getX()) >= 3 && (
65、play.getX() - me.getX()) <=58){ play.setBounds(play.getX()-57,play.getY(),55,55); }}}//卒移动结束/**卒吃棋规则*/ public void armsRule(JLabel play1,JLabel play2){//向右走 if ((play2.getX() - play1.getX()) <= 112 && (play2.getX() - play1.getX()) >= 57 && (play1.getY() - play2.getY()) < 22 && (pla
66、y1.getY() - play2.getY()) > -22 && play2.isVisible() && play1.getName().charAt(1)!=play2.getName().charAt(1)){//黑棋要过河才能右吃棋 if (play1.getName().charAt(1) == 1 && play1.getY() > 284 && play1.getName().charAt(1) != play2.getName().charAt(1)){ play2.setVisible(false);//把对方的位置给自己 play1.setBounds(play2.getX(),play2.getY(),55,55);} //红棋要过河才左能吃棋 else if (play1.getName().charAt(1) == 2 && play1.getY() < 341 &&play1.getName().charAt(1) != play2.getName().charAt(1)){play
- 温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年水电工程运行维护管理合同示范文本.docx
- 2025年工程勘测设计合同模板.docx
- 2025年区域产品销售代理合同.docx
- 2025年经销商授权合同样本.docx
- 2025年员工住房资金借贷合同.docx
- 2025年轻钢建筑施工合同示例.docx
- 2025年网络推广托管合同.docx
- 2025年简明个人借款正式合同范例.docx
- 2025年房产按揭贷款合同范例.docx
- 2025年技术合同争议调解.docx
- 2025年电子版城市住宅租赁合同范本.docx
- 2025年简易转让合同协议书样本.docx
- 2025年投资顾问服务合同实例.docx
- 2025年经销合同模板.docx
- 2025年工业项目设计合同样本.docx