




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
目录 一 需求分析一 需求分析 2 二 系统运行环境二 系统运行环境 2 三 系统功能需求描述 三 系统功能需求描述 2 四 总体设计四 总体设计 2 五 系统结构图五 系统结构图 3 六 程序模块设计六 程序模块设计 3 七 实验总结体会七 实验总结体会 15 一 需求分析一 需求分析 在个人电脑日益普及的今天 一些有趣的桌面游戏已经成为人们在使用计算机进行工 作或学习之余休闲娱乐的首选 而俄罗斯方块游戏是人们最熟悉的小游戏之一 它以其趣 味性强 易上手等诸多特点得到了大众的认可 因此开发此游戏软件可满足人们的一些娱 乐的需求 此俄罗斯方块游戏可以为用户提供一个可在普通个人电脑上运行的 界面美观的 易于 控制的俄罗斯方块游戏 二二 系统运行环境 系统运行环境 操作系统选择 Windows XP 版本 运行环境选择 MyEclipse 三 系统功能需求描述三 系统功能需求描述 俄罗斯方块游戏是一款适合大众的游戏软件 它适合不同年龄的人玩 本软件要实现 的功能如下 1 游戏区 玩家可以在游戏区中堆积方块 并能够在游戏过程中随时了解得分 情况 2 游戏控制 玩家可以通过游戏控制功能来选择开始新的一局游戏 暂停或退 出游戏 3 级别设置 玩家可以根据自己的需要自行设定游戏的开始级别 级别越高 游戏速度越快 难度越大 四 总体设计四 总体设计 游戏中玩家可以做的操作有 1 以 90 度为单位旋转方每一格块 2 以格子为单位左右移动方块 让方块加速落下 3 方块移到区域最下方或是着地到其他方块上无法移动时 就会固定在该处 而新的随机图形会出现在区域上方开始落下 4 当区域中某一列横向格子全部由方块填满 则该列会自动消除并成为玩家 的得分 同时删除的列数越多 得分指数上升 5 当固定的方块堆到区域最上方 则游戏结束 五 系统结构图五 系统结构图 游戏区 游戏控制 显示玩家操作 显示操作结果 开始 暂停 继续 提高等级 退出 降低等级 六 程序模块设计六 程序模块设计 6 1 用户界面设计 游戏区模块 创建游戏区 处理玩家游戏操作 显示游戏结果 俄罗斯方块游戏 游戏控制模块 开始游戏 暂停游戏 初始级别设置 退出游戏 6 2 程序代码设计 package russia import java awt import java awt event 俄罗斯方块类 class ERS Block extends Frame private static final long serialVersionUID 1L public static boolean isPlay false public static int level 1 score 0 public static TextField scoreField levelField public static MyTimer timer GameCanvas gameScr public static void main String argus ERS Block ers new ERS Block 俄罗斯方块游戏 V1 0 Author Vincent WindowListener win listener new WinListener ers addWindowListener win listener 俄罗斯方块类的构造方法 SuppressWarnings deprecation ERS Block String title super title setSize 600 480 setLayout new GridLayout 1 2 gameScr new GameCanvas gameScr addKeyListener gameScr timer new MyTimer gameScr timer setDaemon true timer start timer suspend add gameScr Panel rightScr new Panel rightScr setLayout new GridLayout 2 1 0 30 rightScr setSize 120 500 add rightScr 右边信息窗体的布局 MyPanel infoScr new MyPanel infoScr setLayout new GridLayout 4 1 0 5 infoScr setSize 120 300 rightScr add infoScr 定义标签和初始值 Label scorep new Label 分数 Label LEFT Label levelp new Label 级数 Label LEFT scoreField new TextField 8 levelField new TextField 8 scoreField setEditable false levelField setEditable false infoScr add scorep infoScr add scoreField infoScr add levelp infoScr add levelField scorep setSize new Dimension 20 60 scoreField setSize new Dimension 20 60 levelp setSize new Dimension 20 60 levelField setSize new Dimension 20 60 scoreField setText 0 levelField setText 1 右边控制按钮窗体的布局 MyPanel controlScr new MyPanel controlScr setLayout new GridLayout 5 1 0 5 rightScr add controlScr 定义按钮 play Button play b new Button 开始游戏 play b setSize new Dimension 50 200 play b addActionListener new Command Command button play gameScr 定义按钮 Level UP Button level up b new Button 提高级数 level up b setSize new Dimension 50 200 level up b addActionListener new Command Command button levelup gameScr 定义按钮 Level Down Button level down b new Button 降低级数 level down b setSize new Dimension 50 200 level down b addActionListener new Command Command button leveldown gameScr 定义按钮 Level Pause Button pause b new Button 游戏暂停 pause b setSize new Dimension 50 200 pause b addActionListener new Command Command button pause gameScr 定义按钮 Quit Button quit b new Button 退出游戏 quit b setSize new Dimension 50 200 quit b addActionListener new Command Command button quit gameScr controlScr add play b controlScr add level up b controlScr add level down b controlScr add pause b controlScr add quit b setVisible true gameScr requestFocus 重写 MyPanel 类 使 Panel 的四周留空间 class MyPanel extends Panel private static final long serialVersionUID 1L public Insets getInsets return new Insets 30 50 30 50 游戏画布类 class GameCanvas extends Canvas implements KeyListener private static final long serialVersionUID 1L final int unitSize 30 小方块边长 int rowNum 正方格的行数 int columnNum 正方格的列数 int maxAllowRowNum 允许有多少行未削 int blockInitRow 新出现块的起始行坐标 int blockInitCol 新出现块的起始列坐标 int scrArr 屏幕数组 Block b 对方快的引用 画布类的构造方法 GameCanvas rowNum 15 columnNum 10 maxAllowRowNum rowNum 2 b new Block this blockInitRow rowNum 1 blockInitCol columnNum 2 2 scrArr new int 32 32 初始化屏幕 并将屏幕数组清零的方法 void initScr for int i 0 i rowNum i for int j 0 j columnNum j scrArr i j 0 b reset repaint 重新刷新画布方法 public void paint Graphics g for int i 0 i rowNum i for int j 0 j columnNum j drawUnit i j scrArr i j 画方块的方法 public void drawUnit int row int col int type scrArr row col type Graphics g getGraphics switch type 表示画方快的方法 case 0 g setColor Color black break 以背景为颜色画 case 1 g setColor Color blue break 画正在下落的方块 case 2 g setColor Color magenta break 画已经落下的方法 g fill3DRect col unitSize getSize height row 1 unitSize unitSize unitSize true g dispose public Block getBlock return b 返回 block 实例的引用 返回屏幕数组中 row col 位置的属性值 public int getScrArrXY int row int col if row rowNum col columnNum return 1 else return scrArr row col 返回新块的初始行坐标方法 public int getInitRow return blockInitRow 返回新块的初始行坐标 返回新块的初始列坐标方法 public int getInitCol return blockInitCol 返回新块的初始列坐标 满行删除方法 void deleteFullLine int full line num 0 int k 0 for int i 0 i rowNum i boolean isfull true L1 for int j 0 j columnNum j if scrArr i j 0 k isfull false break L1 if isfull full line num if k 0 j columnNum j if scrArr i j 0 drawUnit k 1 j 0 else drawUnit k 1 j 2 scrArr k 1 j scrArr i j for int i k 1 i rowNum i for int j 0 j columnNum j drawUnit i j 0 scrArr i j 0 ERS Block score full line num ERS Block scoreField setText ERS Block score 判断游戏是否结束方法 boolean isGameEnd for int col 0 col columnNum col if scrArr maxAllowRowNum col 0 return true return false public void keyTyped KeyEvent e public void keyReleased KeyEvent e 处理键盘输入的方法 public void keyPressed KeyEvent e if ERS Block isPlay return switch e getKeyCode case KeyEvent VK DOWN b fallDown break case KeyEvent VK LEFT b leftMove break case KeyEvent VK RIGHT b rightMove break case KeyEvent VK SPACE b leftTurn break 处理控制类 class Command implements ActionListener static final int button play 1 给按钮分配编号 static final int button levelup 2 static final int button leveldown 3 static final int button quit 4 static final int button pause 5 static boolean pause resume true int curButton 当前按钮 GameCanvas scr 控制按钮类的构造方法 Command int button GameCanvas scr curButton button this scr scr 按钮执行方法 SuppressWarnings deprecation public void actionPerformed ActionEvent e switch curButton case button play if ERS Block isPlay scr initScr ERS Block isPlay true ERS Block score 0 ERS Block scoreField setText 0 ERS Block timer resume scr requestFocus break case button levelup if ERS Block level 1 ERS Block level ERS Block levelField setText ERS Block level ERS Block score 0 ERS Block scoreField setText ERS Block score scr requestFocus break case button pause if pause resume ERS Block timer suspend pause resume false else ERS Block timer resume pause resume true scr requestFocus break case button quit System exit 0 方块类 class Block static int pattern 0 x0f00 0 x4444 0 x0f00 0 x4444 用十六进至表示 本行表示长条四种状态 0 x04e0 0 x0464 0 x00e4 0 x04c4 0 x4620 0 x6c00 0 x4620 0 x6c00 0 x2640 0 xc600 0 x2640 0 xc600 0 x6220 0 x1700 0 x2230 0 x0740 0 x6440 0 x0e20 0 x44c0 0 x8e00 0 x0660 0 x0660 0 x0660 0 x0660 int blockType 块的模式号 0 6 int turnState 块的翻转状态 0 3 int blockState 快的下落状态 int row col 块在画布上的坐标 GameCanvas scr 块类的构造方法 Block GameCanvas scr this scr scr blockType int Math random 1000 7 turnState int Math random 1000 4 blockState 1 row scr getInitRow col scr getInitCol 重新初始化块 并显示新块 public void reset blockType int Math random 1000 7 turnState int Math random 1000 4 blockState 1 row scr getInitRow col scr getInitCol dispBlock 1 实现 块 翻转的方法 public void leftTurn if assertValid blockType turnState 1 4 row col dispBlock 0 turnState turnState 1 4 dispBlock 1 实现 块 的左移的方法 public void leftMove if assertValid blockType turnState row col 1 dispBlock 0 col dispBlock 1 实现块的右移 public void rightMove if assertValid blockType turnState row col 1 dispBlock 0 col dispBlock 1 实现块落下的操作的方法 public boolean fallDown if bloc
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 公司医疗器械装配工合规化技术规程
- 2025湖南省邵阳学院公开招聘事业编制人员22人模拟试卷及完整答案详解
- 广播电视机务员合规化技术规程
- 2025湖南永州市教育局直属学校(单位)招聘教师46人考前自测高频考点模拟试题及完整答案详解一套
- 高低压电器及成套设备装配工工作纪律遵守考核试卷及答案
- 道路巡视养护工数据分析与运用考核试卷及答案
- 公司木制玩具制作工岗位工艺作业技术规程
- 2025北京师范大学黔南龙溪实验学校引进人才18人模拟试卷及1套完整答案详解
- 过程控制系统点检员劳动防护用品使用考核试卷及答案
- 冷冻食品制作工岗位现场作业技术规程
- 锅炉工安全培训知识课件
- 天津地区高考语文五年高考真题汇编-文言文阅读
- 个人简历模板(5套完整版)
- 跟踪出站调车讲解
- 2023-2024年贵州省劳动合同样本范本书电子版完整版
- 耳部全息铜砭刮痧
- 煤气发生炉拆除方案
- 《新概念英语》第三册课文详解及课后答案
- 金匮要略-黄芪桂枝五物汤
- J17J177 钢丝网架珍珠岩复合保温外墙板建筑构造
- 酒店账单-水单-住宿
评论
0/150
提交评论