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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

项目坦克大战设计分析报告.docx

1、项目坦克大战设计分析报告JAVA程序开发课程设计项目设计项目名称:TankWar 软件专业: 软件工程 班级:13软工1班 姓名:毛晨光 学号:一、 需求分析:基本功能:1.玩家控制的坦克能够四处移动并且打击敌方坦克;2.敌方坦克能够随机四处移动并且打击玩家控制的坦克;3.玩家控制的坦克拥有血量,而敌方坦克没有;4.坦克受到攻击时血条会缩短;5.敌方坦克被消灭完之后,提示游戏胜利;6.用户方坦克被消灭后提示游戏结束;特色功能:1. 坦克具有图片,不单单只是个圈圈。2. 增加了血包功能,地图上会随机出现一个血包,我方坦克开过会增加血量。二、系统设计: 1.TankMap类:实现游戏界面地图的初始

2、化。2.PainTread类:绘制和重绘功能。3.DirectionHandler:监听用户的键盘输入。4.Tank类:实现坦克的初始化,绘制,移动,发射等功能。5.EnemyTank:实现敌方坦克的初始化,绘制,移动,发射等功能。6.Shell类:实现炮弹的初始化,绘制,移动,攻击功能。7.Explor类:实现爆炸的初始化。绘制功能,爆炸效果由绘制半径从小到大再到小的圆实现 。8.Direction类:包含枚举。9.Blood类:用于实现血包的功能。三、功能实现。一绘制地图功能:public class TankMap extends Frame/定义地图的尺寸。 public static

3、 final int MAPWIDTH=800; public static final int MAPHEIGHT=600;/我方坦克 Tank t=null;/定义随机出现的血包 Random r=new Random(); Image bufferImage=null; /地方坦克集合-enemys=new ArrayList(); /爆炸集合public.static.jav /敌方坦克数量默认10个public int enemyCount=5;/主方法 public static void main(String args) TankMap tv=new TankMap(); tv

4、.init(); public void drawImage() /地图初始化方法public void init() /初始化地图this.setSize(MAPWIDTH,MAPHEIGHT); this.setTitle(TankWar); this.setVisible(true); /添加键盘监听器 this.addKeyListener(new DirectionHandler(); /添加穿口关闭监听器 this.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent arg0) Sy

5、stem.exit(0); ); /初始化我方坦克 t=new Tank(this); /初始化敌方坦克for(int i=0;ienemyCount;i+) enemys.add(new EnemyTank(40+30*i,80,Color.YELLOW); /启动绘制线程 new Thread(new PaintThread().start(); /Override public void paint(Graphics g) /画地图Color c=g.getColor(); g.setColor(Color.GREEN); g.fillRect(0,0,MAPWIDTH,MAPHEIGH

6、T); g.setColor(Color.RED); g.drawString(当前炮弹数目:+shells.size(),20,40); g.drawString(生命值:,20,60); g.fillRect(65,55,t.getLife(),5); g.setColor(c); /画坦克 t.draw(g); if(r.nextInt(10)=9 & bloods.size()=0) bloods.add(new Blood(); if(r.nextInt(60)=7 & bloods.size()=1) bloods.remove(0); for(int i=0;ienemys.si

7、ze();i+) EnemyTank et=enemys.get(i); et.draw(g); /画爆炸 for(int i=0;iexplors.size();i+) Explor e=explors.get(i); e.draw(g); /绘制血包 for(int i=0;ibloods.size();i+) Blood b=bloods.get(i); b.bloodb(t); b.draw(g); /画炮弹 for(int i=0;ishells.size();i+) Shell s=shells.get(i); if(s.islive&s.isgood) s.hitTanks(en

8、emys); else if(s.islive&!s.isgood) s.hitTank(t); s.draw(g); /双缓冲,防止游戏地图“频闪” public void update(Graphics g) paint(g); if(bufferImage=null) bufferImage=this.createImage(MAPWIDTH,MAPHEIGHT); Graphics gbuffer=bufferImage.getGraphics(); Color c=gbuffer.getColor(); gbuffer.setColor(Color.GREEN); gbuffer.f

9、illRect(0, 0, MAPWIDTH, MAPHEIGHT); gbuffer.setColor(Color.RED); gbuffer.drawString(当前炮弹数目:+shells.size(),20,40); gbuffer.drawString(生命值:, 20, 60); gbuffer.fillRect(65,55,t.getLife(),5); gbuffer.setColor(c); paint(gbuffer); g.drawImage(bufferImage, 0, 0, null); /内部类,主要通过调用repaint方法,实现绘图功能 class Pain

10、tThread implements Runnable Override public void run() while(true) repaint(); try Thread.sleep(260); catch(InterruptedException e) e.printStackTrace(); /内部类,键盘监听器 class DirectionHandler extends KeyAdapter Override public void keyPressed(KeyEvent arg0) t.checkDirection(arg0); 二.绘制坦克功能:public class Ta

11、nk /坦克的尺寸和移动速度public static final int WIDTH=50,HEIGHT=50,xspeed=5,yspeed=5;/坦克的初始位置public int x=400,y=300;/坦克的初始化方向,STOP即停止,Direction是自定义的枚举常量,见枚举源代码public Direction direction=Direction.STOP;/地图TankMap tm;/坦克是否存活 boolean isLive=true;/坦克属于哪一方,true为用户方,false为敌方 boolean isgood=true;/坦克初始化生命值int life=10

12、0;/定义坦克的初始化方向,以便插图坦克的图片public int zhuanxiang=1;/获取和设置存活状况 public boolean isLive() return isLive; public void setLive(boolean isLive) this.isLive=isLive; /获取和设置生命值public int getLife() return life; public void setLife(int life) this.life=life; /构造方法 public Tank(); public Tank(TankMap t) tm=t; /绘制坦克/根据

13、坦克的移动方向,插入不同的坦克的图片public void draw(Graphics g) if(zhuanxiang=1) ImageIcon icon=new ImageIcon(Etank_shang.gif); Image tankImage=icon.getImage(); g.drawImage(tankImage,x,y,null); else if(zhuanxiang=-2) ImageIcon icon=new ImageIcon(Etank_you.gif); Image tankImage=icon.getImage(); g.drawImage(tankImage,

14、x,y,null); else if(zhuanxiang=2) ImageIcon icon=new ImageIcon(Etank_zuo.gif); Image tankImage=icon.getImage(); g.drawImage(tankImage,x,y,null); else ImageIcon icon=new ImageIcon(Etank_xia.gif); Image tankImage=icon.getImage(); g.drawImage(tankImage,x,y,null); /*Color c=g.getColor(); g.setColor(Color

15、.RED); g.fillOval(x,y,WIDTH,HEIGHT); g.setColor(c);*/ move(direction); /根据方向,移动坦克,不允许坦克移出地图尺寸public void move(Direction d) if(d=Direction.STOP) else if(d=Direction.UP) zhuanxiang=1; y -= yspeed; if(y=800-WIDTH) x=800-WIDTH; else if(d=Direction.DOWN) zhuanxiang=-1; y+=yspeed; if(y=600-HEIGHT) y=600-H

16、EIGHT; else if(d=Direction.LEFT) zhuanxiang=2; x-=xspeed; if(x36) fire(); /确定敌方的坦克的移动 if(direction=Direction.UP) y-=yspeed; zhuanxiang=1; if(y=800-WIDTH) x=800-WIDTH; else if(direction=Direction.DOWN) y+=yspeed; zhuanxiang=-1; if(y=600-HEIGHT) y=600-HEIGHT; else if(direction=Direction.LEFT) x-=xspee

17、d; zhuanxiang=2; if(x=0) x=0; Override public void fire() Shell(this.x+WIDTH/2,this.y+HEIGHT/2,this.direction,tm,Color.BLUE,false); public Rectangle getRec() return new Rectangle(this.x,this.y,this.WIDTH,this.HEIGHT); 四.炮弹绘制方法public class Shell /初始化炮弹的基本属性 public final int WIDTH=5,HEIGHT=5,xspeed=14

18、,yspeed=14; public int x,y; Direction dir=Direction.STOP; public boolean islive=true; TankMap tm=null; Color color=Color.RED; boolean isgood=true; boolean isLive=true; /构造方法 public Shell() public Shell(int xd,int yd,Direction d,TankMap t) x=xd; y=yd; dir=d; tm=t; public Shell(int xd,int yd,Direction

19、 d,TankMap t,Color c,boolean g) x=xd; y=yd; dir=d; tm=t; color=c; isgood=g; /绘制炮弹 public void draw(Graphics g) if(islive) Color c=g.getColor(); g.setColor(color); g.fillOval(x,y,WIDTH,HEIGHT); g.setColor(c); move(dir); else /炮弹的移动,如果炮弹移动出了地图尺寸,则设定炮弹死亡 public void move(Direction d) if(d=Direction.UP)

20、 y-=yspeed; if(y=800)islive=false; else if(d=Direction.DOWN) y+=yspeed; if(y=600)islive=false; else if(d=Direction.LEFT) x-=xspeed; if(x=0)islive=false; public Rectangle getRec() return new Rectangle(this.x,this.y,this.WIDTH,this.HEIGHT); /打击坦克方法public boolean hitTank(Tank t) if(this.isLive&t.isLive

21、&this.getRec().intersects(t.getRec() /用户坦克生命值减20 t.setLife(t.getLife()-20); /如果用户坦克生命值=0,游戏结束 if(t.getLife()=0) t.setLive(false); t.direction=Direction.STOP; JOptionPane.showMessageDialog(tm,Game Over!); System.exit(0); /炮弹死亡 this.isLive=false; /产生爆炸 Explor e=new Explor(x-3,y-3,this.tm); return true; return false; /用户坦克打击敌方坦克的方法 public boo

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

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