1、+missiles.size(), 10, 50);explodes count:+explodes.size(), 10, 70);tanks count: +tanks.size(), 10, 90);tanks life:+myTank.getLife(), 10, 110);if(tanks.size() = 0) for(int i=1; i37) this.fire();if(x 10) x = 10;if(y TankWar.GAME_WIDTH-Tank.TANK_WIDTHTankWar.GAME_WIDTH - Tank.TANK_WIDTH - 8;if(y TankWa
2、r.GAME_HEIGHT - Tank.TANK_HEIGHT -8)y = TankWar.GAME_HEIGHT - Tank.TANK_HEIGHT -8;public void keyPressed (KeyEvent e) int key = e.getKeyCode();switch(key) case KeyEvent.VK_F2 :live = true;life = 100;break;case KeyEvent.VK_LEFT :bL = true;case KeyEvent.VK_UP :bU = true;-8)x=break;case KeyEvent.VK_RIG
3、HT :bR = true;case KeyEvent.VK_DOWN :bD = true;changeDir();public void keyReleased (KeyEvent e) case KeyEvent.VK_CONTROL :fire();bL = false;bU = false;bR = false;bD = false;case KeyEvent.VK_A :superFire();public void changeDir() if(bL & !bU &bR &bD) dir = Direction.L;else if(bL & bU &bD) dir = Direc
4、tion.LU;else if(!bL &bD) dir = Direction.U; bR &bD) dir = Direction.RU;bD) dir = Direction.R; bD) dir = Direction.RD; bD) dir = Direction.D; bD) dir = Direction.LD;bD) dir = Direction.STOP;public Missile fire() live) return null;int x = this.x + Tank.TANK_WIDTH/2 - Missile.MISSILE_WIDTH/2;int y = th
5、is.y + Tank.TANK_HEIGHT/2 - Missile.MISSILE_HEIGHT/2;Missile m = new Missile(x, y, ptDir, good, this.tc);tc.missiles.add(m);return m;public Missile fire(Direction dir) Missile m = new Missile(x, y, dir, good, this.tc);private void superFire() Direction dirs = Direction.values();dirs.length-1;/tc.mis
6、siles.add(fire(dirsi);fire(dirsi);public Rectangle getRect() return new Rectangle(x, y, this.TANK_WIDTH, this.TANK_HEIGHT);public boolean collidesWithWall(Wall w) if(this.live & this.getRect().intersects(w.getRect() /this.dir = Direction.STOP;stay();return true;return false;public boolean collidesWi
7、thTank(Tank t) if(this != t) t.live & this.getRect().intersects(t.getRect() this.stay();t.stay();return false;public boolean collidesWithTanks(java.util.List tanks) if(collidesWithTank(t) return true;public void stay() x = oldX;y = oldY;public boolean eat(Blood b) b.isLive() & this.getRect().interse
8、cts(b.getRect() this.life = 100;b.setLive(false);private class BloodBar public void draw(Graphics g) Color c = g.getColor();g.setColor(Color.WHITE);g.drawRect(x, y-20, TANK_WIDTH, 10);int w = TANK_WIDTH * life/100;g.setColor(Color.RED);g.fillRect(x, y-20, w, 10);/*添加子弹的类public class Missile public s
9、tatic final int XSPEED = 20;public static final int YSPEED = 20;public static final int MISSILE_WIDTH = 10;public static final int MISSILE_HEIGHT = 10;private boolean live = true;private boolean good;Tank.Direction dir;private TankWar tw;public Missile(int x, int y, Tank.Direction dir) public Missile(int x, int y, Tank.Direction dir, boolean good, TankWar tw) this(x, y, dir);this.tw = t
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1