




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
基于Java的飞机大战游戏开发 毕业设计(论文) 摘要上,都能见到的飞机大战游出现,而如互联网,同时云计算和移动 AbstractPlaneWaristheoneofthemostclassicgamesintheearlyhistoryofthedevelopmentofcomputergames.Wecanalwaysseeaircraft-relatedshootinggamewhetheritisonacomputerteminalormobileterminal.However,thefirstcommonplanewargameisatwo-dimensionalplane,andmostlyappearsintheformofblackandwhite,butnow,onthecomputer,notjustmodelsandmorecolorful,3Dstrongvisualimpact.Javaisverypopularwithdeveloperssinceitappeared,formedthepowerfulshockfortherapidevelopmentoftheC++language.Javatechnologyhasexcellentversatility,efficiency,platformportability,andsecurityandiswidelyusedinpersonalPC,datacenter,gameconsoles,scientificsupercomputers,cellphonesandtheInternet.What’smore,Javahastheworld'slargestdeveloperofprofessionalcommunity.IntheglobalcloudcomputingandmobileInternetindustryenvironment,Javahasmoresignificantadvantagesandbroadprospects.Therefore,thispaperdescribesthedevelopmentofobject-orientedprogramminglanguageJavaandEclipsedevelopmenttoolsforaircraftwargame.Firstly,itintroducesresearchbackground,purposeandmeaning,andtelledJavadevelopmentprocessandthecurrentdevelopmentstatusathomeandabroad.Thenintroducesthe tformdevelopmentenvironmentandbuiltenvironmentandfinallytellstheJavabasedircraftwargamefeaturesimplementationItsfunctionmodulesareasfollowsthemainnterfacemoduleHeromoduleEnemymoduleBulletmoduleandthedetectionmoduledetectingacollisionwiththeenemybulletsWebelievesitsJavabasedaircraftwargamewouldbewelcomedgreater.JavaEclipse 飞机大战游戏拥有所有游戏共通的成分。它们都有一个独立的循环体,这个循实现至不能正确地领会这个过程(因为你没能完成它),可能是没能建立一个合适的时间 该游戏要满足以下功能性需求: (2)子弹的控制 (3)多种Enemy战机的出现方式 (4)各种战机和子弹的碰撞情况的检测和控制 (5)各个战机和子弹生命周期的结束控制 第一章开发技术和开发平台误的指针(以引用取代)、运算符重载,多重继承(以接口代替)等特性,增加了垃存空间,使得程序员不用再为内 跨平台 (2)安全性问。 (3)面向对象性、继承性等有关对象的特性,使得程序代码 (4)分布式 壮性 Applet程序中所采用的AWT的绘图机制主要涉及三个方法:paint()方法,update()方法和repaint()方法,update()方法和paint()方法都有一个Graphics好游事件编程:用户编程定义每个特定时间发生时程序应做出何种响应,并且这些AWT的时间,而是交由时间监听TU。在多处理机计算机上实现多线程时,它们可以并行工作,而 率。线程是共享地址空间的,也就是说多。可大致分为三大类: 可以直接读入网络上所放的数据,或把自己的数据传送到网络的另一端。 作为交互的方式。 质量。帮助程序员快速的录入代码,此外它的重构功能也让修改代码减少了很多的工作量,挥场所。从官网下载下面的安装包并安装: 第二章飞机大战游戏需求分析该游戏主要包括以下几个功能: 建求很高的程序系统,飞行速度的把控,还有响应速度的的差别都将很容易导致程序在与运行不久后可能出现与想象中完全不同的差别,考虑在设计中。否能够解决。行分析和研究。 (1)技术可行性e 经济可行性 上是可以接受的,并且本软件是实施后可以显著提理。而且软件维护简单,实用性强,一次性开 (3)社会可行性通过在网上大量的调研得出的,软件的软件设计实在独立的环境下完成的,不存在侵计原则有: (1)简单性:在实现软件的功能的同时,尽量让软件操作简单易懂,这对于一 (3)一致性:命名规则一致性:类型、变量和其他元素的命名规则保持一致;应该是一致的。 (1)游戏状态的控制功能、运行、结束状态。 控制功能 (1)战机和背景的美化。游戏优美清新的界面会给用户带来愉快的心情和美饰,提高玩家玩的兴致和欲望。 从而可以实现爆炸效果。 (3)多线程技术的实现。线程机制的应用是实现游戏控制的基石,游戏中的刷 (4)碰撞问题的解决。碰撞检测技术的实现要综合运用数学和物理知识,在不第三章飞机大战功能模块实现各模块组织如图所示: (2)资源模块: (3)引用的第三方Jar包如下:publicclassStartWin{GameImagestart;GameImageover;intchoice=0;/** *初始化界面显示*@return玩家的选择*/publicintshow(){GameCore.setGameSize(400,600);GameCore.setGameTitle("飞机大战");GameCore.loadBgView("./win/start/background.png");GameImagecopyright=newGameImage("./win/start/game_copyright.png");copyright.setPosition(0,0);start=newGameImage("./win/start/game_start.png");start.setPosition(75,250);//宽为250over=newGameImage("./win/start/game_over.png");over.setPosition(75,300);GameSpriteloadPlane=newGameSprite("load");loadPlane.setPosition(120,400);loadPlane.playSpriteAnimate("fly",true);GameCore.addMouseListener(newMouseControler(){/***游戏加载界面上所有的事件控制处理*/booleanfirst=true;@OverridepublicvoidmousePressed(MouseEvente){if(first){choice=getAreaNum(e);first=false;}}});while(choice==0)GameCore.pause(100);GameCore.playSound("./button/button.mp3",false);returnchoice;}}publicclassGameControler{Herohero;LinkedList<Enemy>e;LinkedList<Bullet>b;intscore;/***运行控制*/publicvoidrun(){intendChoice=0;while(endChoice<2){loadGame();hero=newHero();b=hero.bullets;e=newLinkedList<Enemy>(); score=0;//加载heroGameCore.playSound("./hero/fly.mp3",true);hero.fly();//游戏核心,碰撞爆炸,启动碰撞检测线程detectCollision();//只要英雄还活着,敌机就不断生产while(hero.isLive){Enemyenemy=EnemyControler.createEnemy();e.add(enemy);GameCore.pause(1900);}endChoice=finishGame();}}}publicclassHero{publicGameSpritesprite;publicbooleanisLive=true;publicLinkedList<Bullet>bullets=newLinkedList<Bullet>();publicHero(){sprite=newGameSprite("hero");sprite.playSpriteAnimate("fly",true);intx=(int)(GameCore.getGameWidth()-sprite.getSize().width)/2;inty=GameCore.getGameHeight()-25-sprite.getSize().height;sprite.setPosition(x,y);}/***战机起飞*/publicvoidfly(){//开枪射击GameCore.addKeyListener(newKeyControler(){@OverridepublicvoidkeyPressed(KeyEvente){ if(!Hero.this.isLive)return;intkey=e.getKeyCode();switch(key){caseKeyEvent.LEFT:Hero.this.sprite.moveLeft(8);break;caseKeyEvent.RIGHT:Hero.this.sprite.moveRight(8);break;caseKeyEvent.UP:Hero.this.sprite.moveUp(8);break;caseKeyEvent.DOWN:Hero.this.sprite.moveDown(8);break;caseKeyEvent.SPACE:Hero.this.shoot(1);break;//单枪caseKeyEvent.ENTER://双枪Hero.this.shoot(2);break;}}});}/** *子弹类,实现Runnable接口可运行 */publicclassBulletimplementsRunnable{publicGameImageimage;publicbooleanisLive=true;publicBullet(Pointp){image=newGameImage("./bullet/bullet1.png");image.setPosition(p.x,p.y);}/***子弹线程,在Hero类中启动*/@Overridepublicvoidrun(){ GameCore.playSound("./bullet/bullet.mp3",false);while(!image.isTop())//可能有误差{if(!isLive)break;image.moveUp(5);//子弹的移动速度GameCore.pause(10);}image.hide();isLive=false;}}心代码如下:publicclassEnemy1extendsEnemy{publicintlives=2;publicEnemy1(){obj=newGameImage("./enemy/enemy1.png");}@Overridepublicvoidrun(){while(obj!=null&&!obj.isBottom())//可能有误差{if(lives<1){blowup();obj.hide();System.out.println("小型飞机爆炸了");return;}obj.moveDown(3);GameCore.pause(25);}if(obj==null)return;obj.hide();lives=0;}publicvoidblowup(){Pointp=obj.getPosition();GameSpritesprite=newGameSprite("enemy1");GameCore.playSound("./enemy/1.mp3",false);sprite.playSpriteAnimate("blowup",false); sprite.setPosition(p.x,p.y);GameCore.pause(1000);sprite.hide();}}publicclassEnemyControler{privatestaticRandomrand=newRandom();/***生成敌机类型*@return敌机编号*/publicstaticintcreateEnemyType(){intnum=1+rand.nextInt(3);returnnum;}/***根据类型生成敌机坐标*@paramtype*@returnpoint对象*/publicstaticPointcreateEnemyPoint(GameObjectobj){Pointp=newPoint();Dimensiond=obj.getSize();intwidth=GameCore.getGameWidth();p.x=rand.nextInt(width-d.width);p.y=-d.height;returnp;}/***生产敌机*/publicstaticEnemycreateEnemy(){Enemyenemy=null;inttype;type=EnemyControler.createEnemyType();switch(type){case1:enemy=newEnemy1();break;case2:enemy=newEnemy2();break;case3:enemy=newEnemy3();break;}Pointp=EnemyControler.createEnemyPoint(enemy.obj);enemy.obj.setPosition(p.x,p.y);enemy.fly();returnenemy;}}码如下:/***碰撞检测线程*/publicvoiddetectCollision(){//敌机检测子弹,敌机检测hero newThread(newRunnable(){@Overridepublicvoidrun(){while(true){System.out.println("碰撞检测线程进入");if(!hero.isLive)return;for(inti=e.size()-1;i>=0;i--){Enemyenemy=e.get(i);if(enemy.getLives()<1)continue;if(enemy.obj.isIntersectWith(hero.sprite)){System.out.println("敌机与hero撞了");hero.isLive=false;hero.blowup();score=countScore();destroyAll();return;}for(intj=b.size()-1;j>=0;j--){Bulletbullet=b.get(j);if(!bullet.isLive)continue;if(enemy.obj.isIntersectWith(bullet.image)){System.out.println("敌机与子弹撞了");enemy.setLives(enemy.getLives()-1);bullet.isLive=false;}}}GameCore.pause(50);}}}).start();}/***两个矩形相交判断*@paramobject*@return*/publicbooleanisIntersectWith(GameObjectobject){Pointp1=this.getPosition();Dimensiond1=this.getSize();Pointp2=object.getPosition();Dimensiond2=object.getSize();//this在object左边if(p1.x+d1.width<p2.x)returnfalse;//this在object右边if(p1.x>p2.x+d2.width)returnfalse;//this在object上边if(p1.y+d1.height<p2.y)returnfalse;//this在object下边if(p1.y>p2.y+d2.height));returnfalse;returntrue;}图3.7积分成绩显示 核心代码如下:/***积分成绩显示*/publicclassLabel{publicstaticString[]numName={"./number/0.png","./number/1.png","./number/2.png","./number/3.png","./number/6.png","./number/9.png"};publicstaticvoid"./number/4.png","./number/7.png",showNum(intnum)"./number/5.png","./number/8.png",{StringscoreStr=String.valueOf(num);intlen=scoreStr.length();intx,y;//积分牌在中间,共6张数字图片for(inti=0;i<3;i++){GameImagenumber;//各个位置的数字安排if(i<len){charch=scoreStr.charAt(len-i-1);number=newGameImage(numName[ch-'0']);}else{number=newGameImage(numName[0]);}number.setPosition(x,y);x=x-40;}}publicstaticvoidshowScore(intscore){StringscoreStr=String.valueOf(score);intlen=scoreStr.length();intx,y
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025小型工程建筑合同(监控)
- 2025租房合同原件丢失怎么办
- 2025电竞科技有限公司股权转让合同示例
- 趣味学习激发幼儿探索欲计划
- 2025年纺织品交易合同模板
- 农村桥梁建设合同标准文本
- 长形菜地规划方案范本
- 急救培训中心急救知识普及工作计划
- 义齿业务合同样本
- 企业资产收购合同标准文本
- 安全生产目标、责任制考核表
- 高考英语读后续写二轮备考:原文内容 续写范文 范文译文(20篇)
- HSF目标指标和方案削减计划管理程序
- 病媒生物防制消杀工作记录表全套资料
- 零星维修服务方案
- 外科游离皮瓣移植术后护理
- 后续服务的安排及保证措施
- 《科技论文写作》课程教学大纲
- 钢结构焊接工艺卡与返修工艺卡(共5页)
- 泰国橡胶木协会成员
- REVIT建模步骤
评论
0/150
提交评论