坦克大战java源代码

上传人:cn****1 文档编号:464307667 上传时间:2022-09-08 格式:DOC 页数:19 大小:109KB
返回 下载 相关 举报
坦克大战java源代码_第1页
第1页 / 共19页
坦克大战java源代码_第2页
第2页 / 共19页
坦克大战java源代码_第3页
第3页 / 共19页
坦克大战java源代码_第4页
第4页 / 共19页
坦克大战java源代码_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《坦克大战java源代码》由会员分享,可在线阅读,更多相关《坦克大战java源代码(19页珍藏版)》请在金锄头文库上搜索。

1、有些图片路径会出错 要注意 package com.tankgame;/坦克类class Tankint 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 g

2、etDirect() 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 TankShot shot=null;Vector shotm=new V ector(); public Hero(int x,int y)super(x,y); this.color=5;/坦克具有一个打击敌人的方法

3、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)

4、; 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(); p

5、ublic 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.yet.y)return true;if(this.x+20=et

6、.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=et.x+20&this.yet.y)return true;if(this.x+30=et.x&this.x+30=et.x+20&this.

7、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&this.y+30et.y) return true;if(this.x+20=et.x&this.x+20=et.x+20&this.y+30et.y) re

8、turn 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.yet.y) return true; if(this.x+30=et.x&this.x+30=et.x+20&this.y+20et.y) return true; if(e

9、t.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.direct)case 0:for(int i=0;i0&this.isTouch()=false)y-=this.speed; try Thread.sleep(50); catch (Int

10、erruptedException 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) / TODO Auto-generated catch block e.printStackTrace(); break;case 2:for(int i=0;i30;i+) if(y2

11、70&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-=this.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()5)Shot es=null;switch(this.direct)case 0:es=new Shot(this.getX()+10,this.getY(),0);ensh.add(es);break;case 1:es=new Shot(this.getX()+30,this

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号