ImageVerifierCode 换一换
格式:DOCX , 页数:79 ,大小:145.97KB ,
资源ID:19283299      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/19283299.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(纯Java写的中国象棋Word文档下载推荐.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

纯Java写的中国象棋Word文档下载推荐.docx

1、 Vector Var; /规则类对象(使于调用方法) ChessRule rule; /* * 单击棋子 * chessManClick = true 闪烁棋子 并给线程响应 * chessManClick = false 吃棋子 停止闪烁 并给线程响应 */ boolean chessManClick; * 控制玩家走棋 * chessPlayClick=1 黑棋走棋 * chessPlayClick=2 红棋走棋 默认红棋 * chessPlayClick=3 双方都不能走棋 int chessPlayClick=2; /控制棋子闪烁的线程 Thread tmain; /把第一次的单击棋

2、子给线程响应 static int Man,i; ChessMainFrame()中国象棋 * 构造函数 * 初始化图形用户界面 ChessMainFrame(String Title) /获行客格引用 con = this.getContentPane(); con.setLayout(null); /实例化规则类 rule = new ChessRule(); Var = new Vector(); /创建工具栏 jmain = new JToolBar(); text = new JLabel(欢迎使用象棋对弈系统 /当鼠标放上显示信息 text.setToolTipText(信息提示

3、anew = new JButton( 新 游 戏 anew.setToolTipText(重新开始新的一局 exit = new JButton( 退 出 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

4、(0,0,558,30); con.add(jmain); /添加棋子标签 drawChessMan(); /注册按扭监听 anew.addActionListener(this); repent.addActionListener(this); exit.addActionListener(this); /注册棋子移动监听 for (int i=0;i screenSize.height) frameSize.height = screenSize.height; if (frameSize.width screenSize.width) frameSize.width = screenSi

5、ze.width; this.setLocation(screenSize.width - 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 drawChes

6、sMan() /流程控制 int i,k; /图标 Icon in; /黑色棋子 /车 in = new ImageIcon(image黑车.GIF for (i=0,k=24;2;i+,k+=456) playi = new JLabel(in); playi.setBounds(k,56,55,55); playi.setName(车1 /马image黑马.GIF for (i=4,k=81;6;i+,k+=342) 马1 /相image黑象.GIF for (i=8,k=138;10;i+,k+=228) 象1 /士image黑士.GIF for (i=12,k=195;14;i+,k+

7、=114)士1 /卒image黑卒.GIF for (i=16,k=24;21; playi.setBounds(k,227,55,55);卒1 + i); /炮image黑炮.GIF for (i=26,k=81;28;i+,k+=342) playi.setBounds(k,170,55,55);炮1 /将image黑将.GIF play30 = new JLabel(in); play30.setBounds(252,56,55,55); play30.setName(将1 /红色棋子image红车.GIF for (i=2,k=24;4;i+,k+=456) playi.setBoun

8、ds(k,569,55,55);车2image红马.GIF for (i=6,k=81;8;马2image红象.GIF for (i=10,k=138;12;i+,k+=228)象2image红士.GIF for (i=14,k=195;16;士2 /兵image红卒.GIF for (i=21,k=24;26; playi.setBounds(k,398,55,55);卒2image红炮.GIF for (i=28,k=81;30; playi.setBounds(k,455,55,55);炮2 /帅 play31 = new JLabel(in); play31.setBounds(252

9、,569,55,55); play31.setName(帅2 * 线程方法控制棋子闪烁 public void run() while (true) /单击棋子第一下开始闪烁 if (chessManClick) playMan.setVisible(false); /时间控制 try tmain.sleep(200); catch(Exception e) playMan.setVisible(true); /闪烁当前提示信息 以免用户看不见 else text.setVisible(false); tmain.sleep(250); text.setVisible(true); try t

10、main.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 (me.getSource().equals(image) /该红棋走棋的时候 if (chessPlayClick = 2 & playMan.getName().charA

11、t(1) = 2) Ex = playMan.getX(); Ey = playMan.getY(); /移动卒、兵 if (Man 15 & Man 25 & 30) rule.cannonRule(playMan,play,me); /移动车=0 & 4) /移动马 3 & 8) rule.horseRule(playMan,play,me); /移动相、象 7 & 12) rule.elephantRule(Man,playMan,play,me); /移动仕、士 11 & 16) rule.chapRule(Man,playMan,play,me); /移动将、帅 else if (M

12、an = 30 | Man = 31) rule.willRule(Man,playMan,play,me); /是否走棋错误(是否在原地没有动) if (Ex = playMan.getX() & Ey = playMan.getY() text.setText( 红棋走棋 chessPlayClick=2; else 黑棋走棋 chessPlayClick=1; /if /该黑棋走棋的时候 else if (chessPlayClick = 1 &1) 30) else if (Man = 30 | Man = 31) /else if /当前没有操作(停止闪烁) chessManClic

13、k=false; /if /单击棋子 else /第一次单击棋子(闪烁棋子) if (!chessManClick) for (int i=0; /被单击的棋子 if (me.getSource().equals(playi) /告诉线程让该棋子闪烁 Man=i; /开始闪烁 chessManClick=true; break; /for /第二次单击棋子(吃棋子) else if (chessManClick) /当前没有操作(停止闪烁) chessManClick=false; for (i=0; /找到被吃的棋子 /该红棋吃棋的时候 if (chessPlayClick = 2 & Ex = playMan.getX(); Ey = playMan.getY(); /卒、兵吃规则 if (Man rule.armsRule(playMan,playi); /炮吃规则 else if (Man rule.cannonRule(0,playMan,playi,play,me); /车吃规则 rule.cannonRule(1,playMan,playi,play,me); /马吃规则 rule.horseRule(playMan,playi,play,me); /相、象吃规则 rule.elephantRule(playMan,playi,play);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1