收藏 分销(赏)

java扫雷小游戏软件设计方案报告.docx

上传人:精**** 文档编号:2889278 上传时间:2024-06-10 格式:DOCX 页数:67 大小:148.31KB
下载 相关 举报
java扫雷小游戏软件设计方案报告.docx_第1页
第1页 / 共67页
java扫雷小游戏软件设计方案报告.docx_第2页
第2页 / 共67页
java扫雷小游戏软件设计方案报告.docx_第3页
第3页 / 共67页
java扫雷小游戏软件设计方案报告.docx_第4页
第4页 / 共67页
java扫雷小游戏软件设计方案报告.docx_第5页
第5页 / 共67页
点击查看更多>>
资源描述

1、 佛山科学技术学院可视化编程技术课程设计汇报计算器软件设计学生姓名: 吴晓莉学 号: 914210年级专业:11级教育技术学2班指导老师: 容汝佳学 院: 教育科学学院广东佛山提交日期:6月目 录1. 序言22概要设计3 2.1 开发环境 3 2.2 游戏功效 3 2.3 界面设计 3 2.4 类框架结构图 43. 具体设计 4 3.1 使用JAVA类说明 4 3.2 类关键方法 53.2.1 处理按了运算符后计算 53.2.2 处理输入字符 63.2.3 进制转换 63.2.4 设计总体认识 73.2.5 程序步骤图 84. 运行结果85. 测试分析9 5.1 程序运行情况9 5.2 程序异

2、常处理96. 源程序9参考文件27设计总结27摘要:该程序是一个扫雷小游戏,含有赶快简练游戏界面,玩者只要是曾经玩过扫雷游戏,那么我这个游戏是很轻易上手。该游戏含有三种模式:简单模式,中等模式和复杂模式。游戏界面上有一个显示剩下雷数目标小方框,还有一个计时小方框。中间是一个“重新玩按钮”,选择菜单栏有重新玩、能够选择模式、还能退出。关键字:java扫雷,游戏类,方法,事件1 序言学生学习压力越来越大,应该有适时娱乐放松,所以我在学习了java语言以后,决定用java语言编写一个简单扫雷小游戏,能够实现简单娱乐功效,且比一般扫雷游戏增加部分功效。Java是由Sun企业开发新一代纯面向对象网络编程

3、语言。其目标是建立一个在任意种机器、任一个操作系统网络环境中运行软件,实施所谓“程序写一次,四处运行”目标。正因为如此,Java已成为当今Internet上最流行、最受欢迎一个程序开发语言。Java开发小组把Java按特征分为基础版、移动版、企业版,每个版本有一个软件开发包。Java基础版本叫Java 2标准版(Java 2 Standard Edition,J2SE),它包含建立Java应用程序或是Applet所需应用程序编程接口(API)。Java 2移动版(The Java 2 Mobile Edition,J2ME)包含创建无线Java应用程序API。还有Java 2企业版(The J

4、ava 2 Enterprise,J2EE)是J2SE增强版本,包含建立多层架构应用程序API。Java语言是由C+语言发展起而来,是一个根本面向对象程序设计语言。作为一个纯面向对象程序设计语言,它很适合大型软件开发。Java语言去掉了C+语言部分轻易引发错误特征。Java语言特点有:面向对象、跨平台、安全性、多线程和图形功效强。2 概要设计2.1开发环境 开发平台:Microsoft Windows XP Professional Service Pack 2 开发工具:JBuilder + JDK 1.6.0_022.2游戏功效功效 1:打开游戏以后,会默认进入疯狂模式,能够经过菜单栏选择

5、不一样游戏模式。功效 2:游戏界面左边有个小框,用来显示目前界面剩下雷数目。功效 3:游戏界面右边有一个小框,用来显示目前游戏已经进行了时间(秒)。功效 4:游戏界面中间有一个按钮,点击能够重新开始游戏。功效 5:菜单栏二级菜单有选项能够退出游戏。2.3界面设计图2.3.1 游戏面板(疯狂模式)图2.3.2 游戏面板(中等模式)图2.3.3 游戏面板(简单模式)2.4类框架结构图BottomPanel 图 2.4.1 所表示CenterPanel 图 2.4.2 所表示Display 图 2.4.3 所表示Field 图 2.4.4 所表示Digit 图 2.4.5 所表示J_sweep 图

6、2.4.6 所表示NorthPanel 图 2.4.7 所表示BottomPanel属性private static final long serialVersionUID操作public BottomPanel()图 2.4.1CenterPanel属性private static final long serialVersionUID = 1L; private int countX, countY, fieldsLeft; private Field fields; private Difficulty difficulty; private Random random; private

7、 boolean gameOver; private J_sweep minesweeper;public CenterPanel(J_sweep minesweeper, Difficulty difficulty)public void setMinesweeper(Difficulty difficulty)private void setFields()public void paint(Graphics g)private void setGameOver()private void setWon()private void performFieldClick(int x, int

8、y)private void performFieldClickFlagged(int x, int y)private boolean isNeighbourMinesFlagged(int x, int y)public void mousePressed(MouseEvent e)图 2.4.2Display属性private static final long serialVersionUID = 1L;private Digit digit0, digit1, digit2;private int value;操作public Display(int value)public voi

9、d setValue(int value)public int getValue()public void paint(Graphics g)图 2.4.3Field属性private int x, y, neighbourMines;private boolean clicked, mine, flag, mineClicked;private Color color1, color2, color3, color4,color5, color6, color7, color8;操作public Field(int x, int y)public boolean setClicked()pu

10、blic boolean isClicked()public void setMine(boolean mine)public void incrementNeighbourMines()public int getNeighbourMines()public int setFlag()public boolean isFlag()public void setGameOver()public void setWon()public void paint(Graphics g)图 2.4.4Digit属性private int digit, x, y, width, height;privat

11、e Color darkRed;操作public Digit(int digit, int x, int y)public void setDigit(int digit)public void paint(Graphics g)图 2.4.5J_sweep属性private static final long serialVersionUID private NorthPanel northPanel;private CenterPanel centerPanel;private BottomPanel bottomPanel;private JCheckBoxMenuItem miBegi

12、nner,miIntermediate, miExpert;private Difficulty difficulty;public J_sweep()public void startTime()public void stopTime()public void setMines(int value)public void setMines(int value, boolean real)public void setMainMenuDifficulty()public void actionPerformed(ActionEvent e)public static void main(St

13、ring args)图 2.4.6NorthPanelprivate static final long serialVersionUIDprivate J_sweep minesweeper;private Display mineDisplay, timeDisplay;private long begin;private Timer timer;public NorthPanel(J_sweep minesweeper, Difficulty difficulty)public void setMinesweeper(Difficulty difficulty)public void s

14、etMines(int value, boolean real)public void startTime()public int stopTime()public void actionPerformed(ActionEvent e)图 2.4.73具体设计3.1 扫雷游戏使用Java类说明类名: BottomPanel作用: 这是设计整个界面底部颜色继承父类: JPanel类 实现接口: 没有 public class BottomPanel extends JPanel private static final long serialVersionUID = -29266788L;pub

15、lic BottomPanel() super();setBackground(Color.white);/这是设计整个界面底部颜色类名: J_sweep 作用: 主类。继承父类: JFrame类实现接口: ActionListener类public class J_sweep extends JFrame implements ActionListenerprivate static final long serialVersionUID = 5319706L;/生成序列号,不用管它private NorthPanel northPanel;private CenterPanel cente

16、rPanel;private BottomPanel bottomPanel;private JCheckBoxMenuItem miBeginner, miIntermediate, miExpert;private Difficulty difficulty;public J_sweep()super(wxl_扫雷);/软件标题setDefaultCloseOperation(EXIT_ON_CLOSE);/退出按钮/*resizeable值为true时,表示在生成窗体能够自由改变大小;resizeable值为false时,表示生成窗体大小是由程序员决定,用户不能够自由改变该窗体大小*/s

17、etResizable(false);difficulty = Difficulty.疯狂模式;/默认定义最高难度JMenuBar menuBar = new JMenuBar();/菜单栏控件JMenu menu = new JMenu(文件);/菜单栏菜单项JMenuItem menuItem = new JMenuItem(重新玩);/菜单栏下拉菜单menuItem.addActionListener(this);/给下拉框加上事件捕捉menu.add(menuItem);/下拉框放入下拉菜单控件menu.addSeparator();/加个空格线miBeginner = new JCh

18、eckBoxMenuItem(简单模式);/选择框 下面一样,不解释!miBeginner.addActionListener(this);menu.add(miBeginner);miIntermediate = new JCheckBoxMenuItem(中等模式);miIntermediate.addActionListener(this);menu.add(miIntermediate);miExpert = new JCheckBoxMenuItem(疯狂模式, true);miExpert.addActionListener(this);menu.add(miExpert);men

19、u.addSeparator();menuItem = new JMenuItem(退出);menuItem.addActionListener(this);menu.add(menuItem);menuBar.add(menu);setJMenuBar(menuBar);/把菜单栏加入面板northPanel = new NorthPanel(this, Difficulty.疯狂模式);/定义一个面板add(northPanel, BorderLayout.NORTH);/把这个面板放在上面centerPanel = new CenterPanel(this, Difficulty.疯狂模

20、式);add(centerPanel, BorderLayout.CENTER);/把这个面板放在中间/*调整此窗口大小,以适合其子组件首选大小和布局 XJQ*/bottomPanel = new BottomPanel();add(bottomPanel , BorderLayout.SOUTH);pack();/设置窗口相对于指定组件位置setLocationRelativeTo(null);/设置可视化setVisible(true);类名: CenterPanel 作用: 设置中间面板继承父类: JPanel类实现接口: MouseListener 类public class Cent

21、erPanel extends JPanel implements MouseListenerprivate static final long serialVersionUID = 1L;private int countX, countY, fieldsLeft;private Field fields;/ 用数组定义界面横向和纵向private Difficulty difficulty;/定义难度private Random random;private boolean gameOver;private J_sweep minesweeper;类名: Display 作用: 计时继承父

22、类: JPanel类实现接口:没有public class Display extends JPanelprivate static final long serialVersionUID = 1L;private Digit digit0, digit1, digit2;/定义了一个表示雷有、无、不确定量private int value;类名: Field作用: 定义数字颜色继承父类: 没有实现接口:没有public class Fieldprivate int x, y, neighbourMines;private boolean clicked, mine, flag, mineCl

23、icked;private Color color1, color2, color3, color4, color5, color6, color7, color8;/ 定义了从18之间,八个数字颜色类名NorthPanel作用: 定义中间面板继承父类: JPanel类实现接口: ActionListener 类public class NorthPanel extends JPanel implements ActionListenerprivate static final long serialVersionUID = 040336L;private J_sweep minesweepe

24、r;private Display mineDisplay, timeDisplay;private long begin;private Timer timer;类名Digit作用: 统计剩下雷数目继承父类: 没有实现接口:没有public class Digitprivate int digit, x, y, width, height;private Color darkRed;/定义接下来用来绘制数字颜色3.2类关键方法3.2.1设计整个界面底部颜色: public BottomPanel() super();setBackground(Color.white); 3.2.2添加鼠标监

25、听器:public CenterPanel(J_sweep minesweeper, Difficulty difficulty)super();this.setBackground(Color.LIGHT_GRAY);addMouseListener(this); this.minesweeper = minesweeper;this.difficulty = difficulty;random = new Random();setFields();3.2.3 设置三种模式界面大小:private void setFields()int mines = 0;switch (difficult

26、y)case 简单模式:countX = countY = 12;/这是设置简单模式界面横竖全部有12个格子mines = 15;/这是设置简单模式雷个数break;case 中等模式:countX = countY = 16;/这是设置中等模式界面横竖全部有16个格子mines = 40;/这是设置中等模式雷个数break;case 疯狂模式:countX = 30;/这是设置疯狂模式界面横向有30个格子countY = 16;/这是设置疯狂模式界纵向全部有16个格子mines = 99;/这是设置疯狂模式雷个数break; 3.2.4 绘制统计雷数目标数字public Digit(int

27、digit, int x, int y)this.digit = digit;this.x = x;this.y = y;width = 13;height = 23;darkRed = new Color(128, 0, 0);public void setDigit(int digit)this.digit = digit;public void paint(Graphics g)g.setColor(Color.BLACK);g.fillRect(x, y, width, height);switch (digit)case 0: case 2: case 3: case 5: case

28、 6: case 7: case 8: case 9:g.setColor(Color.RED);g.drawLine(x + 2, y + 1, x + 10, y + 1);g.drawLine(x + 3, y + 2, x + 9, y + 2);g.drawLine(x + 4, y + 3, x + 8, y + 3);break;case -2: case -1: case 1: case 4:g.setColor(darkRed);g.fillRect(x + 3, y + 1, 1, 1);g.fillRect(x + 5, y + 1, 1, 1);g.fillRect(x

29、 + 7, y + 1, 1, 1);g.fillRect(x + 9, y + 1, 1, 1);g.fillRect(x + 4, y + 2, 1, 1);g.fillRect(x + 6, y + 2, 1, 1);g.fillRect(x + 8, y + 2, 1, 1);g.fillRect(x + 5, y + 3, 1, 1);g.fillRect(x + 7, y + 3, 1, 1);break;switch (digit)case -1: case 2: case 3: case 4: case 5: case 6: case 8: case 9:g.setColor(

30、Color.RED);g.drawLine(x + 3, y + 10, x + 9, y + 10);g.drawLine(x + 2, y + 11, x + 10, y + 11);g.drawLine(x + 3, y + 12, x + 9, y + 12);break;case -2: case 0: case 1: case 7:g.setColor(darkRed);g.fillRect(x + 4, y + 10, 1, 1);g.fillRect(x + 6, y + 10, 1, 1);g.fillRect(x + 8, y + 10, 1, 1);g.fillRect(

31、x + 3, y + 11, 1, 1);g.fillRect(x + 5, y + 11, 1, 1);g.fillRect(x + 7, y + 11, 1, 1);g.fillRect(x + 9, y + 11, 1, 1);g.fillRect(x + 4, y + 12, 1, 1);g.fillRect(x + 6, y + 12, 1, 1);g.fillRect(x + 8, y + 12, 1, 1);break;switch (digit)case 0: case 2: case 3: case 5: case 6: case 8: case 9:g.setColor(C

32、olor.RED);g.drawLine(x + 4, y + 19, x + 8, y + 19);g.drawLine(x + 3, y + 20, x + 9, y + 20);g.drawLine(x + 2, y + 21, x + 10, y + 21);break;case -2: case -1: case 1: case 4: case 7:g.setColor(darkRed);g.fillRect(x + 5, y + 19, 1, 1);g.fillRect(x + 7, y + 19, 1, 1);g.fillRect(x + 4, y + 20, 1, 1);g.f

33、illRect(x + 6, y + 20, 1, 1);g.fillRect(x + 8, y + 20, 1, 1);g.fillRect(x + 3, y + 21, 1, 1);g.fillRect(x + 5, y + 21, 1, 1);g.fillRect(x + 7, y + 21, 1, 1);g.fillRect(x + 9, y + 21, 1, 1);break;switch (digit)case 0: case 4: case 5: case 6: case 8: case 9:g.setColor(Color.RED);g.drawLine(x + 1, y +

34、2, x + 1, y + 10);g.drawLine(x + 2, y + 3, x + 2, y + 9);g.drawLine(x + 3, y + 4, x + 3, y + 8);break;case -2: case -1: case 1: case 2: case 3: case 7:g.setColor(darkRed);g.fillRect(x + 1, y + 2, 1, 1);g.fillRect(x + 1, y + 4, 1, 1);g.fillRect(x + 1, y + 6, 1, 1);g.fillRect(x + 1, y + 8, 1, 1);g.fil

35、lRect(x + 1, y + 10, 1, 1);g.fillRect(x + 2, y + 3, 1, 1);g.fillRect(x + 2, y + 5, 1, 1);g.fillRect(x + 2, y + 7, 1, 1);g.fillRect(x + 2, y + 9, 1, 1);g.fillRect(x + 3, y + 4, 1, 1);g.fillRect(x + 3, y + 6, 1, 1);g.fillRect(x + 3, y + 8, 1, 1);break;switch (digit)case 0: case 2: case 6: case 8:g.set

36、Color(Color.RED);g.drawLine(x + 1, y + 12, x + 1, y + 20);g.drawLine(x + 2, y + 13, x + 2, y + 19);g.drawLine(x + 3, y + 14, x + 3, y + 18);break;case -2: case -1: case 1: case 3: case 4: case 5: case 7: case 9:g.setColor(darkRed);g.fillRect(x + 1, y + 12, 1, 1);g.fillRect(x + 1, y + 14, 1, 1);g.fil

37、lRect(x + 1, y + 16, 1, 1);g.fillRect(x + 1, y + 18, 1, 1);g.fillRect(x + 1, y + 20, 1, 1);g.fillRect(x + 2, y + 13, 1, 1);g.fillRect(x + 2, y + 15, 1, 1);g.fillRect(x + 2, y + 17, 1, 1);g.fillRect(x + 2, y + 19, 1, 1);g.fillRect(x + 3, y + 14, 1, 1);g.fillRect(x + 3, y + 16, 1, 1);g.fillRect(x + 3,

38、 y + 18, 1, 1);break;switch (digit)case 0: case 1: case 2: case 3: case 4: case 7: case 8: case 9:g.setColor(Color.RED);g.drawLine(x + 11, y + 2, x + 11, y + 10);g.drawLine(x + 10, y + 3, x + 10, y + 9);g.drawLine(x + 9, y + 4, x + 9, y + 8);break;case -2: case -1: case 5: case 6:g.setColor(darkRed)

39、;g.fillRect(x + 11, y + 2, 1, 1);g.fillRect(x + 11, y + 4, 1, 1);g.fillRect(x + 11, y + 6, 1, 1);g.fillRect(x + 11, y + 8, 1, 1);g.fillRect(x + 11, y + 10, 1, 1);g.fillRect(x + 10, y + 3, 1, 1);g.fillRect(x + 10, y + 5, 1, 1);g.fillRect(x + 10, y + 7, 1, 1);g.fillRect(x + 10, y + 9, 1, 1);g.fillRect

40、(x + 9, y + 4, 1, 1);g.fillRect(x + 9, y + 6, 1, 1);g.fillRect(x + 9, y + 8, 1, 1);break;switch (digit)case 0: case 1: case 3: case 4: case 5: case 6: case 7: case 8: case 9:g.setColor(Color.RED);g.drawLine(x + 11, y + 12, x + 11, y + 20);g.drawLine(x + 10, y + 13, x + 10, y + 19);g.drawLine(x + 9, y + 14, x + 9, y + 18);break;case -2: case -1: case 2:g.setColor(darkRed);g.fillRect(x + 11, y + 12, 1, 1);g.fillRect(x + 11, y + 14, 1, 1);g.fillRect(x + 11, y + 16, 1, 1);g.fillRect(x + 11, y + 18, 1, 1);g.fillRect(x + 11, y + 20, 1, 1);g.fillRect(x + 10, y + 13, 1, 1);g.fill

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 考试专区 > 中考

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服