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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

坦克大战java源代码.docx

1、坦克大战java源代码有些图片路径会出错 要注意package com.tankgame;import ;/坦克类class Tank int x=0; int y=0; int color=0; int speed=1; int direct=0; boolean isLive=true; public Tank(int x,int y) this.x=x; this.y=y; public int getX() return x; public void setX(int x) this.x = x; public int getY() return y; public void setY

2、(int y) this.y = y; public int getDirect() return direct; public void setDirect(int direct) this.direct = direct; public int getColor() return color; public void setColor(int color) this.color = color; /我的坦克class Hero extends Tank Shot shot=null; Vector shotm=new Vector(); public Hero(int x,int y) s

3、uper(x,y); this.color=5; /坦克具有一个打击敌人的方法 public void shotenemy(int x,int y,int direct) switch(direct) case 0: shot=new Shot(this.x+10,this.y,0); shotm.add(shot); break; case 1: shot=new Shot(this.x+30,this.y+10,1); shotm.add(shot); break; case 2: shot=new Shot(this.x+10,this.y+30,2); shotm.add(shot);

4、 break; case 3: shot=new Shot(this.x,this.y+10,3); shotm.add(shot); break; Thread th=new Thread(shot); th.start(); /调整速度 public void moveup() y-=speed; public void moveright() x+=speed; public void movedown() y+=speed; public void moveleft() x-=speed; /敌人的坦克class EnemyTank extends Tank implements Ru

5、nnable Vectorensh=new Vector(); Vectorets=new Vector(); public EnemyTank(int x, int y) super(x, y); this.setColor(2); this.setDirect(2); /获取MPanel上的敌人坦克 public void setets(Vector vv) this.ets=vv; /判断敌人的坦克是否碰撞 public boolean isTouch() boolean b=false; EnemyTank et=null; switch(direct) case 0: for(int

6、 i=0;i=et.x&this.x=et.x+20&this.yet.y) return true; if(this.x+20=et.x&this.x+20=et.x+20&this.yet.y) return true; if(et.direct=1|et.direct=3) if(this.x=et.x&this.x=et.x+30&this.yet.y) return true; if(this.x+20=et.x&this.x+20=et.x+30&this.yet.y) return true; break; case 1: for(int i=0;i=et.x&this.x+30

7、=et.x+20&this.yet.y) return true; if(this.x+30=et.x&this.x+30=et.x+20&this.y+20et.y) return true; if(et.direct=1|et.direct=3) if(this.x+30=et.x&this.x+30=et.x+30&this.yet.y) return true; if(this.x+30=et.x&this.x+30=et.x+30&this.y+20et.y) return true; break; case 2: for(int i=0;i=et.x&this.x=et.x+20&

8、this.y+30et.y) return true; if(this.x+20=et.x&this.x+20=et.x+20&this.y+30et.y) return true; if(et.direct=1|et.direct=3) if(this.x=et.x&this.x=et.x+30&this.y+30et.y) return true; if(this.x+20=et.x&this.x+20=et.x+30&this.y+30et.y) return true; break; case 3: for(int i=0;i=et.x&this.x+30=et.x+20&this.y

9、et.y) return true; if(this.x+30=et.x&this.x+30=et.x+20&this.y+20et.y) return true; if(et.direct=1|et.direct=3) if(this.x+30=et.x&this.x+30=et.x+30&this.yet.y) return true; if(this.x+30=et.x&this.x+30=et.x+30&this.y+20et.y) return true; break; return b; public void run() while(true) switch(this.direc

10、t) case 0: for(int i=0;i0&this.isTouch()=false)y-=this.speed; try Thread.sleep(50); catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace(); break; case 1: for(int i=0;i30;i+) if(x365&this.isTouch()=false)x+=this.speed; try Thread.sleep(50); catch (InterruptedException e

11、) / TODO Auto-generated catch block e.printStackTrace(); break; case 2: for(int i=0;i30;i+) if(y270&this.isTouch()=false)y+=this.speed; try Thread.sleep(50); catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace(); break; case 3: for(int i=0;i0&this.isTouch()=false)x-=th

12、is.speed; try Thread.sleep(50); catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace(); break; this.direct=(int)(Math.random()*4); if(this.isLive=false) break; if(ensh.size()0) lift-; else isLive=false; /子弹类class Shot implements Runnable int shotX; int shotY; int direct

13、; int shotspeed=1; boolean isLive=true; public Shot(int x,int y,int direct) this.shotX=x; this.shotY=y; this.direct=direct; public int getShotX() return shotX; public void setShotX(int shotX) this.shotX = shotX; public int getShotY() return shotY; public void setShotY(int shotY) this.shotY = shotY;

14、public int getShotspeed() return shotspeed; public void setShotspeed(int shotspeed) this.shotspeed = shotspeed; public void run() while(true) try Thread.sleep(50); catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace(); switch(direct) case 0: shotY-=shotspeed; break; ca

15、se 1: shotX+=shotspeed; break; case 2: shotY+=shotspeed; break; case 3: shotX-=shotspeed; break; if(shotX400|shotY300) isLive=false; break; /* * 功能:坦克大战4.0 */package com.tankgame4;import java.awt.*;import ;import ;import ;import ;import ;import java.io.*;import javax.swing.*;import javax.imageio.*;p

16、ublic class MyTankGame4 extends JFrame implements ActionListener MyPanel mp=null; MyStartPanel msp=null; /菜单定义 JMenuBar jmb=null; JMenu jm1=null; JMenuItem jmi1=null; public static void main(String args) / TODO Auto-generated method stub MyTankGame4 mtg=new MyTankGame4(); /构造函数 public MyTankGame4()

17、/创建菜单 jmb=new JMenuBar(); jm1=new JMenu(Game(G); jm1.setMnemonic(G); jmi1=new JMenuItem(New Game(N); jmi1.setMnemonic(N); jmi1.addActionListener(this); jmi1.setActionCommand(New Game); jm1.add(jmi1); jmb.add(jm1); this.setJMenuBar(jmb); msp=new MyStartPanel(); Thread st=new Thread(msp); st.start();

18、this.add(msp); this.setTitle(坦克大战); this.setSize(400, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); public void actionPerformed(ActionEvent arg0) if(arg0.getActionCommand().equals(New Game) this.remove(msp); mp=new MyPanel(); Thread mt=new Thread(mp); mt.start();

19、this.add(mp); this.addKeyListener(mp); this.setVisible(true); /游戏开始面板class MyStartPanel extends JPanel implements Runnable int times=0; public void paint(Graphics g) super.paint(g); g.fillRect(0, 0, 400, 300); if(times%2=0) Font myfont=new Font(行楷,Font.BOLD,30); g.setFont(myfont); g.setColor(Color.y

20、ellow); g.drawString(第一关, 130, 130); this.repaint(); public void run() while(true) try Thread.sleep(300); times+; catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace(); /我的面板class MyPanel extends JPanel implements KeyListener,Runnable /定义一个我的坦克 Hero hero=null; EnemyTank et=null; Image image1=null; Image image2=null; Image image3=null; Image im=null; Vector

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2