好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

坦克大战java源代码.doc

103页
  • 卖家[上传人]:re****.1
  • 文档编号:455057353
  • 上传时间:2024-01-09
  • 文档格式:DOC
  • 文档大小:171.50KB
  • / 103 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.------------------------------------------author------------------------------------------date坦克大战java源代码package com有些图片路径会出错 要注意package com.tankgame;import java.util.Vector;//坦克类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(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) { super(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); 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 Runnable{ 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 i=0;i=et.x&&this.x<=et.x+20&&this.y<=et.y+30&&this.y>et.y) { return true; } if(this.x+20>=et.x&&this.x+20<=et.x+20&&this.y<=et.y+30&&this.y>et.y) { return true; } } if(et.direct==1||et.direct==3) { if(this.x>=et.x&&this.x<=et.x+30&&this.y<=et.y+20&&this.y>et.y) { return true; } if(this.x+20>=et.x&&this.x+20<=et.x+30&&this.y<=et.y+20&&this.y>et.y) { return true; } } } } break; case 1: for(int i=0;i=et.x&&this.x+30<=et.x+20&&this.y<=et.y+30&&this.y>et.y) { return true; } if(this.x+30>=et.x&&this.x+30<=et.x+20&&this.y+20<=et.y+30&&this.y+20>et.y) { return true; } } if(et.direct==1||et.direct==3) { if(this.x+30>=et.x&&this.x+30<=et.x+30&&this.y<=et.y+20&&this.y>et.y) { return true; } if(this.x+30>=et.x&&this.x+30<=et.x+30&&this.y+20<=et.y+20&&this.y+20>et.y) { return true; } } } } break; case 2: for(int i=0;i=et.x&&this.x<=et.x+20&&this.y+30<=et.y+30&&this.y+30>et.y) { return true; } if(this.x+20>=et.x&&this.x+20<=et.x+20&&this.y+30<=et.y+30&&this.y+30>et.y) { return true; } } if(et.direct==1||et.direct==3) { if(this.x>=et.x&&this.x<=et.x+30&&this.y+30<=et.y+20&&this.y+30>et.y) { return true; } if(this.x+20>=et.x&&this.x+20<=et.x+30&&this.y+30<=et.y+20&&this.y+30>et.y) { return true; } } } } break; case 3: for(int i=0;i=et.x&&this.x+30<=et.x+20&&this.y<=et.y+30&&this.y>et.y) { return true; } if(this.x+30>=et.x&&this.x+30<=et.x+20&&this.y+20<=et.y+30&&this.y+20>et.y) { return true; } } if(et.direct==1||et.direct==3) { if(this.x+30>=et.x&&this.x+30<=et.x+30&&this.y<=et.y+20&&this.y>et.y) { return true; } if(this.x+30>=et.x&&this.x+30<=et.x+30&&this.y+20<=et.y+20&&this.y+20>et.y) 。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.