任务
代码
给 Tank 类加上属性 life,和 get/set 方法
private int life = 100;
public int getLife() {
return life;
}
public void setLife(int life) {
this.life = life;
}
在 Missile 类的 fire() 类中,当子弹击中我方坦克,扣 20 血,如果血量小于 0 ,我方坦克死亡
public boolean hitTank(Tank t) {
if(this.live && this.getRect().intersects(t.getRect()) && t.isLive() && this.good != t.isGood()) {
if(t.isGood()) {
t.setLife(t.getLife()-20);
if(t.getLife() <= 0)
t.setLive(false);
}else {
t.setLive(false);
}
this.live = false;
tc.explodes.add(new Explode(x, y, tc));
return true;
}
return false;
}