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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

本文(基于java的动物换位游戏软件设计Word格式.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

基于java的动物换位游戏软件设计Word格式.docx

1、(3)左面的动物只能向右方跳跃,右面的动物只能向左方跳跃。(4)用户可以通过单击界面上提供的按钮,让程序自动完成动物换位。(5)可以随时单击界面上提供的按钮,重新开始当前的级别。(6)用户通过菜单选项,可以选择左、右动物的图像。2. 类总体设计2.1 类组合关系图在设计动物换位时需要编写10个Java源文件:ChangeAnimalWindow.java、Animal.java、Point.java、Stone.java、HandleMouse.java、AutoMoveAnimal.java、Customdlg.java、People.java、Record.java和ShowRecordD

2、ialog.java。动物换位除了需要编写上述10个Java源文件所给出的类外,还需要Java系统提供的一些重要的类,如:JmenuItem、File和Jbutton类等。动物换位所用到的一些重要的类以及之间组合关系如图2.1所示。 图2.1 类之间的组合关系2.2 系统流程图 图2.2 系统流程图2.3 主类ChangeAnimalWindow类负责创建动物换位的主窗口,该类含有main方法,程序从该类开始执行。2.4 其他类2.4.1 Animal.javaAnimal类是JPanel的一个子类,创建的对象是ChangeAnimalWindow类的重要成员之一,用来表示“动物”。2.4.2

3、 Point.javaPoint类负责创建确定位置的对象,使用Point对象,可以确定Animal以及Stone对象在窗体中的位置。2.4.3 Stone.javaStone类是JButton的一个子类,创建的对象表示“石头”。2.4.4 HandleMouse.javaHandleMouse类所创建的对象负责处理鼠标事件。2.4.5 AutoMoveAnimal.javaAutoMoveAnimal类所创建的对象使用算法完成动物的自动换位。2.4.6 Customdlg.javaCustomdlg类所创建的对象用来设置“自定义”级别的动物数量。2.4.7 People.javaPeople对

4、象封装用户的名字和成绩,以便ShowRecordDialog对象可以排序。2.4.8 Record.javaRecord类是javax.swing包中JDialog对话框的子类,当用户成功完成相应级别的游戏时,Record创建的对象负责保存用户的名字和成绩到相应的级别文件中。2.4.9 ShowRecordDialog.javaShowRecordDialog类是javax.swing包中JDialog对话框的子类,当用户单击查看相应的级别排行榜时,ShowRecordDialog创建的对象负责显示用户的成绩。3. 类详细设计3.1 主类 图3.1 ChangeAnimalWindow类的UM

5、L图(1)成员变量 amoutOfAnimal是int型数据,默认值是6。amoutOfAnimal的值用来确定ChangeAnimalWindow窗体中“动物”的数目,即Animal对象的数目。 distance是int型数据,默认值是80。distance的值用来确定Point对象之间的距离,进而可以确定Animal之间,Stone之间的距离以及Animal和Stone对象外观的大小。 animal是Animal型数组,其长度为amoutOfAnimal。 point是Point型数组,其长度为amoutOfAnimal+1。 stone是Stone型数组,其长度为amoutOfAnima

6、l+1。 handleMouse是HandleMouse类创建的鼠标事件监视器,用来监视animal数组中Animal对象触发的鼠标事件。 autoMoveAnimal是AutoMoveAnimal类创建的对话框。通过该对话框可以实现程序自动将左右动物交换位置。 bar是JMenuBar创建的菜单条,用来添加菜单。bar被放置在窗口的顶部。 menuGrade是JMenu创建的菜单,其名字为“选择级别”。menuImage也是JMenu创建的菜单,其名字为“选择动物图像(JPG,GIF)”。menuHelp也是JMenu创建的菜单,其名字为“帮助”。menuHero也是JMenu创建的菜单,其

7、名字为“英雄榜”。menuGrade、menuImage、menuHero和menuHelp被添加到菜单条bar中。 oneGradeItem、twoGradeItem、threeGradeItem和custom是JMenuItem创建的菜单项,它们的名字依次为“初级”、“中级”、“高级”和“自定义”,这四个菜单项被添加到菜单项menuGrade中。leftImage、rightImage和defaultImage也是JMenuItem创建的菜单项,其名字依次为“左面动物的图像”、“右面动物的图像”和“左右面动物的默认图像”,这三个菜单项被添加到菜单项menuImage中。oneGradeRe

8、sult、twoGradeResult、threeGradeResult、customGradeResult和limitTime也是JMenuItem创建的菜单项,其名字依次为“初级英雄榜”、“中级英雄榜”、“高级英雄榜”、“自定义英雄榜”、“我超时了吗”,这五个菜单项被添加到菜单项menuHero中。helpcontent和aboutUs是JMenuItem创建的菜单项,它们的名字依次为“游戏规则”、和“关于我们”,这两个菜单项被添加到菜单项menuHelp中。oneGradeItem、twoGradeItem、threeGradeItem和custom以及leftImage、rightIm

9、age和defaultImage等菜单项都将当前窗口注册为自己的ActionEvent事件监视器。renew、quit和autoButton是JButton创建的按钮对象,名字依次为“重新开始”、“撤销”和“自动演示”。renew、quit和autoButton都将当前窗口注册为自己的 ActionEvent事件监视器。(2)方法 ChangeAnimalWindow()是构造方法,负责完成窗口的初始化。 init()方法负责完成Animal、Stone和Point对象的创建。 setAmoutOfAnimal(int)方法负责设置动物的个数,即amountOfAnimal的值。 remove

10、AnimalAndStone()方法负责从窗体中移掉动物和石头,即移掉Animal对象和Stone对象。 needDoing()方法负责执行一些经常需要重复执行的代码。 actionPerformed(ActionEvent)方法是ChangeAnimalWindow类实现的ActionListener接口中的方法。ChangeAnimalWindow创建的窗口是oneGradeItem、twoGradeItem、threeGradeItem、custom、leftImage、rightImage、defaultImage等菜单项和renew、quit、autoButton按钮的ActionE

11、vent事件监视器。当用户选中某个菜单项或单击按钮时,窗口将执行actionPerformed(ActionEvent)方法进行相应的操作。如果用户选中oneGradeItem、twoGradeItem、threeGradeItem和custom四个菜单项的某一项时,actionPerformed(ActionEvent)方法所执行的操作就是改变amountOfAnimal的值,并执行needDoing()方法,完成必要的初始化。如果用户选中leftImage和rightImage菜单项的某一个时,actionPerformed(ActionEvent)方法所执行的操作就是改变leftImag

12、eFile和rightImageFile的引用。当用户单击renew按钮时,actionPerformed(ActionEvent)方法所进行的操作是保持当前的amountOfAnimal的值,并执行needDoing()方法,完成必要的初始化,当用户单击quit按钮时,actionPerformed(ActionEvent)方法所进行的操作是撤销当前“动物”的前一次跳跃。当用户单击autoButton按钮时,actionPerformed(ActionEvent)方法所进行的操作是弹出autoMoveAnimal对话框,用户可以通过该对话框让程序显示动物换位过程。main(String)方法

13、是程序运行的入口方法。3.2 其他类 图3.2 Animal类的UML图 图3.3 Point类的UML图 图3.4 Stone类的UML图 图3.5 HandleMouse类的UML图 图3.6 AutoMoveAnimal类的UML图4. 关键成员函数代码ChangeAnimalWindow.java(主类)import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.ArrayList;import java.io.*;import javax.swing.filechooser.*;pub

14、lic class ChangeAnimalWindow extends JFrame implements ActionListener int amountOfAnimal=6; int distance=80; Animal animal; Point point; Stone stone; HandleMouse handleMouse; AutoMoveAnimal autoMoveAnimal; File leftImageFile,rightImageFile; File fileOneGrade,fileTwoGrade,fileThreeGrade,filecustomGra

15、de; JButton renew,quit,autoButton=null; JMenuBar bar; JMenu menuGrade,menuImage,menuHelp,menuHero; JMenuItem oneGradeResult,twoGradeResult,threeGradeResult,customGradeResult; JMenuItem oneGradeItem,twoGradeItem,threeGradeItem,limitTime; JMenuItem custom; JMenuItem helpcontent,aboutUs; JMenuItem left

16、Iamge,rightIamge,defaultImage; JPanel pCenter; ShowRecordDialog showDiolag=null; ChangeAnimalWindow() fileOneGrade=new File(初级英雄排行榜.txt); fileTwoGrade=new File(中级英雄排行榜.txt fileThreeGrade=new File(高级英雄排行榜.txt filecustomGrade=new File(自定义英雄排行榜.txt pCenter=new JPanel(); pCenter.setBackground(Color.pink

17、); pCenter.setLayout(null); handleMouse=new HandleMouse(); autoMoveAnimal=new AutoMoveAnimal(); leftImageFile=new File(dog.jpg rightImageFile=new File(cat.jpg init(); bar=new JMenuBar(); menuGrade=new JMenu(选择级别 menuImage=new JMenu(选择动物图像(JPG,GIF) menuHero=new JMenu(英雄榜 menuHelp=new JMenu(帮助 oneGrad

18、eItem=new JMenuItem(初 级 twoGradeItem=new JMenuItem(中 级 threeGradeItem=new JMenuItem(高 级 custom=new JMenuItem(自定义 leftIamge=new JMenuItem(左面动物的图像 rightIamge=new JMenuItem(右面动物的图像 defaultImage=new JMenuItem(左右面动物的默认图像 oneGradeResult=new JMenuItem(初级英雄榜 twoGradeResult=new JMenuItem(中级英雄榜 threeGradeResu

19、lt=new JMenuItem(高级英雄榜 customGradeResult=new JMenuItem(自定义英雄榜 limitTime=new JMenuItem(我超时了吗 helpcontent=new JMenuItem(游戏规则 aboutUs=new JMenuItem(关于我们 menuGrade.add(oneGradeItem); menuGrade.add(twoGradeItem); menuGrade.add(threeGradeItem); menuGrade.add(custom); menuImage.add(leftIamge); menuImage.ad

20、d(rightIamge); menuImage.add(defaultImage); menuHero.add(oneGradeResult); menuHero.add(twoGradeResult); menuHero.add(threeGradeResult); menuHero.add(customGradeResult); menuHero.add(limitTime); menuHelp.add(helpcontent); menuHelp.add(aboutUs); bar.add(menuGrade); bar.add(menuImage); bar.add(menuHero

21、); bar.add(menuHelp); setJMenuBar(bar); oneGradeItem.addActionListener(this); twoGradeItem.addActionListener(this); threeGradeItem.addActionListener(this); custom.addActionListener(this); leftIamge.addActionListener(this); rightIamge.addActionListener(this); defaultImage.addActionListener(this); one

22、GradeResult.addActionListener(this); twoGradeResult.addActionListener(this); threeGradeResult.addActionListener(this); customGradeResult.addActionListener(this); limitTime.addActionListener(this); helpcontent.addActionListener(this); aboutUs.addActionListener(this); renew=new JButton(重新开始 renew.addA

23、ctionListener(this); autoButton=new JButton(自动演示 autoButton.addActionListener(this); quit=new JButton(撤消 quit.addActionListener(this); JPanel north=new JPanel(); north.add(renew); north.add(quit); north.add(autoButton); String mess=互换左右动物位置; JLabel hintMess=new JLabel(mess,JLabel.CENTER); north.add(

24、hintMess); add(north,BorderLayout.NORTH); add(pCenter,BorderLayout.CENTER); JPanel south=new JPanel(); south.add(handleMouse); add(south,BorderLayout.SOUTH); setVisible(true); setBounds(60,60,710,300); validate(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); if(!fileOneGrade.exists() try fileOneG

25、rade.createNewFile(); catch(IOException exp) fileTwoGrade.exists() try fileTwoGrade.createNewFile();fileThreeGrade.exists() try fileThreeGrade.createNewFile();filecustomGrade.exists() try filecustomGrade.createNewFile(); handleMouse.gradeFile=fileOneGrade; showDiolag=new ShowRecordDialog(); public v

26、oid init() animal=new AnimalamountOfAnimal; point=new PointamountOfAnimal+1; stone=new StoneamountOfAnimal+1; int space=distance; for(int i=0;ipoint.length;i+) pointi=new Point(space,100); space=space+distance;animal.length; animali=new Animal(); animali.addMouseListener(handleMouse); if(i animali.s

27、etIsLeft(false); /else if(i=animal.length/2+1) / /if(animali.equals(animali) /animali.setIsLeft(true); /else / animali.setIsLeft(false); /stone.length; stonei=new Stone(); pCenter.add(stonei); stonei.setSize(distance*8/9,18); int w=stonei.getBounds().width; int h=stonei.getBounds().height; stonei.setLocation(pointi.getX()-w/2,pointi.getY(); pointi.setThisStone(stonei); animali.setSize(distance*6/7,distance*3/4);

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

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