欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    纯Java写的中国象棋.docx

    • 资源ID:8832319       资源大小:29.20KB        全文页数:67页
    • 资源格式: DOCX        下载积分:3金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    纯Java写的中国象棋.docx

    1、纯Java写的中国象棋运行效果如下图所示:源代码如下(可以直接运行出结果):import java.awt.*;import javax.swing.*;import java.util.*;import java.io.*;/主类public class Chess public static void main(String args) new ChessMainFrame(中国象棋,博大精深); /主框架类class ChessMainFrame extends JFrame implements ActionListener,MouseListener,Runnable /玩家 JLa

    2、bel play = new JLabel32; /棋盘 JLabel image; /窗格 Container con; /工具栏 JToolBar jmain; /重新开始 JButton anew; /悔棋 JButton repent; /退出 JButton exit; /当前信息 JLabel text; /保存当前操作 Vector Var; /规则类对象(使于调用方法) ChessRule rule; /* * 单击棋子 * chessManClick = true 闪烁棋子 并给线程响应 * chessManClick = false 吃棋子 停止闪烁 并给线程响应 */ b

    3、oolean chessManClick; /* * 控制玩家走棋 * chessPlayClick=1 黑棋走棋 * chessPlayClick=2 红棋走棋 默认红棋 * chessPlayClick=3 双方都不能走棋 */ int chessPlayClick=2; /控制棋子闪烁的线程 Thread tmain; /把第一次的单击棋子给线程响应 static int Man,i; ChessMainFrame() new ChessMainFrame(中国象棋); /* * 构造函数 * 初始化图形用户界面 */ ChessMainFrame(String Title) /获行客格

    4、引用 con = this.getContentPane(); con.setLayout(null); /实例化规则类 rule = new ChessRule(); Var = new Vector(); /创建工具栏 jmain = new JToolBar(); text = new JLabel(欢迎使用象棋对弈系统); /当鼠标放上显示信息 text.setToolTipText(信息提示); anew = new JButton( 新 游 戏 ); anew.setToolTipText(重新开始新的一局); exit = new JButton( 退 出 ); exit.set

    5、ToolTipText(退出象棋程序程序); 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.add(jmain); /添加棋子标签 drawChessMan(); /注册按扭监听 anew.addActionList

    6、ener(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 = screenSize.width; this.setLocation(screenSize.width - frameSize.width) / 2 - 280 ,(scree

    7、nSize.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 drawChessMan() /流程控制 int i,k; /图标 Icon in; /黑色棋子 /车 in = new ImageIcon(image黑车.GIF

    8、); for (i=0,k=24;i2;i+,k+=456) playi = new JLabel(in); playi.setBounds(k,56,55,55); playi.setName(车1); /马 in = new ImageIcon(image黑马.GIF); for (i=4,k=81;i6;i+,k+=342) playi = new JLabel(in); playi.setBounds(k,56,55,55); playi.setName(马1); /相 in = new ImageIcon(image黑象.GIF); for (i=8,k=138;i10;i+,k+=

    9、228) playi = new JLabel(in); playi.setBounds(k,56,55,55); playi.setName(象1); /士 in = new ImageIcon(image黑士.GIF); for (i=12,k=195;i14;i+,k+=114) playi = new JLabel(in); playi.setBounds(k,56,55,55); playi.setName(士1); /卒 in = new ImageIcon(image黑卒.GIF); for (i=16,k=24;i21;i+,k+=114) playi = new JLabel

    10、(in); playi.setBounds(k,227,55,55); playi.setName(卒1 + i); /炮 in = new ImageIcon(image黑炮.GIF); for (i=26,k=81;i28;i+,k+=342) playi = new JLabel(in); playi.setBounds(k,170,55,55); playi.setName(炮1 + i); /将 in = new ImageIcon(image黑将.GIF); play30 = new JLabel(in); play30.setBounds(252,56,55,55); play3

    11、0.setName(将1); /红色棋子 /车 in = new ImageIcon(image红车.GIF); for (i=2,k=24;i4;i+,k+=456) playi = new JLabel(in); playi.setBounds(k,569,55,55); playi.setName(车2); /马 in = new ImageIcon(image红马.GIF); for (i=6,k=81;i8;i+,k+=342) playi = new JLabel(in); playi.setBounds(k,569,55,55); playi.setName(马2); /相 in

    12、 = new ImageIcon(image红象.GIF); for (i=10,k=138;i12;i+,k+=228) playi = new JLabel(in); playi.setBounds(k,569,55,55); playi.setName(象2); /士 in = new ImageIcon(image红士.GIF); for (i=14,k=195;i16;i+,k+=114) playi = new JLabel(in); playi.setBounds(k,569,55,55); playi.setName(士2); /兵 in = new ImageIcon(ima

    13、ge红卒.GIF); for (i=21,k=24;i26;i+,k+=114) playi = new JLabel(in); playi.setBounds(k,398,55,55); playi.setName(卒2 + i); /炮 in = new ImageIcon(image红炮.GIF); for (i=28,k=81;i 15 & Man 25 & Man =0 & Man 3 & Man 7 & Man 11 & Man 15 & Man 25 & Man =0 & Man 3 & Man 7 & Man 11 & Man 16) rule.chapRule(Man,pla

    14、yMan,play,me); /移动将、帅 else if (Man = 30 | Man = 31) rule.willRule(Man,playMan,play,me); /是否走棋错误(是否在原地没有动) if (Ex = playMan.getX() & Ey = playMan.getY() text.setText( 黑棋走棋); chessPlayClick=1; else text.setText( 红棋走棋); chessPlayClick=2; /else if /当前没有操作(停止闪烁) chessManClick=false; /if /单击棋子 else /第一次单击

    15、棋子(闪烁棋子) if (!chessManClick) for (int i=0;i32;i+) /被单击的棋子 if (me.getSource().equals(playi) /告诉线程让该棋子闪烁 Man=i; /开始闪烁 chessManClick=true; break; /for /if /第二次单击棋子(吃棋子) else if (chessManClick) /当前没有操作(停止闪烁) chessManClick=false; for (i=0;i 15 & Man 25 & Man =0 & Man 3 & Man 7 & Man 11 & Man 16) rule.chapRule(Man,playMan,playi,play); /将、帅吃棋规则 else if (Man = 30 | Man = 31) rule.willRule(Man,playMan,playi,play); playMan.setVisible(true); /是否走棋错误(是否在原地没有动) if (Ex = playMan.getX() & Ey = playMan.getY() text.setText( 红棋走棋); chessPl


    注意事项

    本文(纯Java写的中国象棋.docx)为本站会员主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 冰点文库 网站版权所有

    经营许可证编号:鄂ICP备19020893号-2


    收起
    展开