傻大方摘要:【基于|基于java的游戏坦克大战论文( 五 )|java|游戏|坦克|大战|论文】if(et.isLive) String st=et.x+ +et.y+ +et.direct; /写入 bw.write(st 。 32、+rn); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); finally try bw.close(); fw.close(); cat...
按关键词阅读: java 基于 论文 大战 坦克 游戏
if(et.isLive) String st=et.x+ +et.y+ +et.direct;
/写入 bw.write(st 。
32、+rn);
catch (IOException e) / TODO Auto-generated catch block e.printStackTrace();
finally try bw.close();
fw.close();
catch (IOException e) / TODO Auto-generated catch block e.printStackTrace();
public static int getAllEnNum() return allEnNum;
public static void setAllEnNum(int allEnNum) Recorder.a 。
33、llEnNum = allEnNum;
public static int getEnNum() return enNum;
public static void setEnNum(int enNum) Recorder.enNum = enNum;
public static int getMyLife() return myLife;
public static void setMyLife(int myLife) Recorder.myLife = myLife;
/减少敌人的数量 public static void reduceEnNum() enNum-;
/玩家总成绩 publi 。
34、c static void addEnNum() allEnNum+;
/坦克类 class Tank int x=0;
int y=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;
int direct=0;
public int getDirect() 。
35、 return direct;
public void setDirect(int direct) this.direct = direct;
/坦克的速度 int speed;
public int getSpeed() return speed;
public void setSpeed(int speed) this.speed = speed;
/敌人的坦克 , 把敌人做成线程 class EnemyTank extends Tank implements Runnable int speed=4;
/定义一个向量 , 可以访问 MyPanel 上所有敌人的坦克 Vector ets=new。
36、Vector();
/定义一个向量 , 可以存放敌人的子弹 Vector ss=new Vector();
/敌人添加子弹 , 应在刚刚创建坦克和敌人的坦克死亡后 public EnemyTank(int x,int y) super(x,y);
/得到 MyPanel 的敌人坦克向量 public void setEts(Vector vv) this.ets=vv;
/判断是否碰到别的敌人坦克 public boolean isTouchotherEnemy() boolean b=false;
switch(this.direct) case 0: /我的坦克向上 /取出所有敌人坦克 for(i 。
37、nt i=0;
iet.x-40 break;
case 1: /我的坦克向右 /取出所有敌人坦克 for(int i=0;
iet.x-60 break;
case 2: /我的坦克向下 /取出所有敌人坦克 for(int i=0;
iet.x-40 break;
case 3: /我的坦克向左 /取出所有敌人坦克 for(int i=0;
iet.x-60 break;
return b;
Override public void run() / TODO Auto-generated method stub int a=(int)(Math.random()*20+20);
while(true 。
38、) switch(this.direct) case 0:/说明坦克正在向上 for(int i=0;
i0 try Thread.sleep(50);
catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace();
break;
case 1:/向右 for(int i=0;
ia;
i+) if(x848 try Thread.sleep(50);
catch (InterruptedException e) / TODO Auto-generated catch block e.prin 。
39、tStackTrace();
break;
case 2:/向下 for(int i=0;
ia;
i+) if(y540 try Thread.sleep(50);
catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace();
break;
case 3:/向左 for(int i=0;
i10 try Thread.sleep(50);
catch (InterruptedException e) / TODO Auto-generated catch block e.printStac 。
40、kTrace();
break;
/让坦克随机产生一个新的方向 this.direct=(int)(Math.random()*4);
/System.out.println(this.direct+this.direct);
/判断是否需要给敌人坦克加入新的子弹 if(isLive) if(ss.size()0) life-;
else this.isLive=false;
/子弹类 class Shot implements Runnable int x;
int y;
int direct;
int speed=7;
boolean isLive=true;
public Shot(in 。
41、t x,int y,int direct) this.x=x;
this.y=y;
this.direct=direct;
Override public void run() / TODO Auto-generated method stub while (true) try Thread.sleep(50);
catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace();
switch(direct) case 0:/上 y-=speed;
break;
case 1: x+=spe 。
42、ed;
break;
case 2: y+=speed;
break;
case 3: x-=speed;
break;
/子弹(线程)死亡 if(x0|y900|y600) isLive=false;
break;
/我的坦克 class Hero extends Tank /声明一颗子弹 /Shot s=null;
int speed=7;
Vector ss=new Vector();
Shot s=null;
public Hero(int x,int y) super(x,y);
/坦克向上移动 public void moveUp() if(y2) y-=speed;
/向右 publi 。
43、c void moveRight() if(x848) x+=speed;
/向下 public void moveDown() if(y10) x-=speed;
/开火(子弹打出去) public void ShotEnemy() switch(this.direct) case 0: s=new Shot(x+18, y,0);
ss.add(s);
break;
case 1: s=new Shot(x-10+30+30, y+14+18,1);
ss.add(s);
break;
case 2: s=new Shot(x+18, y+30+30,2);
ss.add(s);
brea 。
44、k;
case 3: s=new Shot(x-10, y+14+18,3);
稿源:(未知)
【傻大方】网址:/a/2021/0621/0022536797.html
标题:基于|基于java的游戏坦克大战论文( 五 )