中国象棋设计

上传人:灯火****19 文档编号:121020033 上传时间:2020-02-14 格式:PPT 页数:40 大小:2.38MB
返回 下载 相关 举报
中国象棋设计_第1页
第1页 / 共40页
中国象棋设计_第2页
第2页 / 共40页
中国象棋设计_第3页
第3页 / 共40页
中国象棋设计_第4页
第4页 / 共40页
中国象棋设计_第5页
第5页 / 共40页
点击查看更多>>
资源描述

《中国象棋设计》由会员分享,可在线阅读,更多相关《中国象棋设计(40页珍藏版)》请在金锄头文库上搜索。

1、中国象棋软件设计 姓名 胡云鹏 王义道 宋玉 余松涛班级 08计科学号 084947024 084947020 084947011 084947035学院 人文管理学院 主标题 问题定义阶段可行性研究阶段需求分析详细设计总体设计编码测试 问题定义阶段 功能简要描述 这是一个单机版中国象棋 该游戏严格按照象棋的游戏规则进行游戏 用鼠标拖动棋子到指定位置 即可进行交替象棋对战 在游戏界面中还可进行新游戏 悔棋 退出等功能型操作 问题定义阶段 用例图 红棋 黑棋 进入界面 悔棋 结束 玩家 可行性研究阶段 由于该单机版中国象棋是为了学习交流因此经济可行 又现有条件可满足技术和操作的可行性 故该项目具

2、有可行性 需求分析 1 1 数据流图1 2 数据字典1 2 1 外部实体1 2 2 数据元素1 2 3 数据流1 2 4 存储文件1 2 5 加工2 状态转换图 数据流图 玩家操作 资源信息 游戏事件处理 显示 鼠标事件 消息 显示信息 资源数据 顶层数据流图 主控模块 游戏处理 棋盘格局 原子数据流图 1 2 游戏处理 棋盘格局 1 生成棋盘及棋子 2 1 2 1 1 棋子处理 空白落子 2 3 是否开始新游戏 2 4 交替下子 2 5 提示信息 判断胜负 2 2 2 1 2 吃子 2 1 3 越界 数据字典 外部实体 数据字典 数据元素 数据字典 数据元素 数据字典 数据元素 数据字典 数

3、据流 数据字典 存储文件 数据字典 加工 数据字典 加工 状态转换图 s0 q1 s1 s2 q2 红方 黑方 s2n q2n 1 S2n 1 q2n 2 sF 详细设计 数据结构设计 开始游戏 红方行棋 判断输赢 绘制画面 是否结束 是否结束 黑方行棋 绘制画面 判断输赢 Y N Y Y 系统流程图 详细设计 算法设计 本系统主要有以下4个模块 每个模块对应一个程序包 1 engine 搜索引擎包 系统的核心部分 2 message 网络对战过程中各种消息及其传递机制的类实现包 3 main 主界面实现包 4 pieces 棋子及其相关类实现包具体实现方法见编码 总体设计 象棋 界面模块 事

4、件处理 棋盘 棋子布局 窗口菜单模块 对弈处理 菜单处理 提示事件 编码 importjava awt importjava awt event importjavax swing importjava util importjava io publicclassChess publicstaticvoidmain Stringargs newChessMainFrame 中国象棋 观棋不语真君子 棋死无悔大丈夫 classChessMainFrameextendsJFrameimplementsActionListener MouseListener Runnable 玩家JLabelpla

5、y newJLabel 32 棋盘 JLabelimage 窗格Containercon 工具栏JToolBarjmain 重新开始JButtonanew 悔棋JButtonrepent 退出JButtonexit 当前信息JLabeltext 保存当前操作VectorVar 规则类对象 使于调用方法 ChessRulerule 单击棋子 chessManClick true闪烁棋子并给线程响应 chessManClick false吃棋子停止闪烁并给线程响应 booleanchessManClick 控制玩家走棋 chessPlayClick 1黑棋走棋 chessPlayClick 2红棋

6、走棋默认红棋 chessPlayClick 3双方都不能走棋 intchessPlayClick 2 控制棋子闪烁的线程Threadtmain 把第一次的单击棋子给线程响应staticintMan i ChessMainFrame newChessMainFrame 中国象棋 构造函数 初始化图形用户界面 ChessMainFrame StringTitle 获行客格引用con this getContentPane con setLayout null 实例化规则类rule newChessRule Var newVector 创建工具栏jmain newJToolBar text newJ

7、Label 欢迎使用象棋对弈系统 当鼠标放上显示信息text setToolTipText 信息提示 anew newJButton 新游戏 anew setToolTipText 重新开始新的一局 anew addActionListener this repent addActionListener this exit newJButton 退出 exit setToolTipText 退出象棋程序程序 repent newJButton 悔棋 repent setToolTipText 返回到上次走棋的位置 把组件添加到工具栏jmain setLayout newGridLayout 0

8、 4 jmain add anew jmain add repent jmain add exit jmain add text jmain setBounds 0 0 558 30 con add jmain 添加棋子标签drawChessMan 注册按扭监听 exit addActionListener this 注册棋子移动监听for inti 0 i 32 i con add play i play i addMouseListener this 添加棋盘标签con add image newJLabel newImageIcon image Main GIF image setBou

9、nds 0 30 558 620 image addMouseListener this 注册窗体关闭监听this addWindowListener newWindowAdapter publicvoidwindowClosing WindowEventwe System exit 0 窗体居中DimensionscreenSize Toolkit getDefaultToolkit getScreenSize DimensionframeSize this getSize if frameSize height screenSize height frameSize height scre

10、enSize height if frameSize width screenSize width frameSize width screenSize width this setLocation screenSize width frameSize width 2 280 screenSize height frameSize height 2 350 设置 this setIconImage newImageIcon image 红将 GIF getImage this setResizable false this setTitle Title this setSize 558 670

11、 this show 添加棋子方法 publicvoiddrawChessMan 流程控制inti k 图标Iconin 黑色棋子 车in newImageIcon image 黑车 GIF for i 0 k 24 i 2 i k 456 play i newJLabel in play i setBounds k 56 55 55 play i setName 车1 马in newImageIcon image 黑马 GIF for i 4 k 81 i 6 i k 342 play i newJLabel in play i setBounds k 56 55 55 play i set

12、Name 马1 相in newImageIcon image 黑象 GIF for i 8 k 138 i 10 i k 228 play i newJLabel in play i setBounds k 56 55 55 play i setName 象1 士 in newImageIcon image 黑士 GIF for i 12 k 195 i 14 i k 114 play i newJLabel in play i setBounds k 56 55 55 play i setName 士1 卒in newImageIcon image 黑卒 GIF for i 16 k 24

13、i 21 i k 114 play i newJLabel in play i setBounds k 227 55 55 play i setName 卒1 i 炮 in newImageIcon image 黑炮 GIF for i 26 k 81 i 28 i k 342 play i newJLabel in play i setBounds k 170 55 55 play i setName 炮1 i 将in newImageIcon image 黑将 GIF play 30 newJLabel in play 30 setBounds 252 56 55 55 play 30 s

14、etName 将1 红色棋子 车in newImageIcon image 红车 GIF for i 2 k 24 i 4 i k 456 play i newJLabel in play i setBounds k 569 55 55 play i setName 车2 马in newImageIcon image 红马 GIF for i 6 k 81 i 8 i k 342 play i newJLabel in play i setBounds k 569 55 55 play i setName 马2 相in newImageIcon image 红象 GIF for i 10 k

15、138 i 12 i k 228 play i newJLabel in play i setBounds k 569 55 55 play i setName 象2 士in newImageIcon image 红士 GIF for i 14 k 195 i 16 i k 114 play i newJLabel in play i setBounds k 569 55 55 play i setName 士2 兵in newImageIcon image 红卒 GIF for i 21 k 24 i 26 i k 114 play i newJLabel in play i setBoun

16、ds k 398 55 55 play i setName 卒2 i 炮in newImageIcon image 红炮 GIF for i 28 k 81 i 30 i k 342 play i newJLabel in play i setBounds k 455 55 55 play i setName 炮2 i 帅in newImageIcon image 红将 GIF catch Exceptione play Man setVisible true play 31 newJLabel in play 31 setBounds 252 569 55 55 play 31 setName 帅2 线程方法控制棋子闪烁 publicvoidrun while true 单击棋子第一下开始闪烁if chessManClick play Man setVisible false 时间控制try tmain sleep 200 闪烁当前提示信息以免用户看不见else text setVisible false 时间控制try tmain sleep 250 catch Exception

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号