Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//检测游戏结束
public void checkGameOverAction() {
//如果英雄机生命值为0
if (hero.isRemove() && gameOnOff) {
gameOnOff = false;
//游戏结束
timer.schedule(new TimerTask() {
public void run() {
state = OVER;
gameOnOff = true;
}
}, 1500);
}
}
/**
* 碰撞处理
*/
private void hitHandler() {
for (int i = 0; i < enemys.size(); i++) {
for (int j = 0; j < bullets.size(); j++) {
/**
* 敌机碰到子弹
*/
if (enemys.get(i).hit(bullets.get(j)) && enemys.get(i).isLive() && bullets.get(j).isLive()) {
enemys.get(i).reduceHP(bullets.get(j).life);
bullets.get(j).reduceHP(enemys.get(i).life);
if (enemys.get(i) instanceof Score && enemys.get(i).isDead()) {
Score s = (Score) enemys.get(i);
score += s.getScore();
} else if (enemys.get(i) instanceof Awarde && enemys.get(i).isDead()) {
Awarde a = (Awarde) enemys.get(i);
int type = a.getAwardType();
if (type == hero.getBulletType()){
type = 0;
}
switch (type) {
case Awarde.LIVE:
hero.addLive();
break;
case Awarde.BULLET_DOUBLE:
hero.addBulletDouble();
break;
case Awarde.BULLET_SHOTGUN:
hero.addBulletShotgun();
break;
}
}
}
}
/**
* 敌机碰到英雄
*/
if (enemys.get(i).hit(hero) && enemys.get(i).isLive() && hero.isLive()) {
/**
* 判断属于奖励还是分数接口
*/
if (enemys.get(i) instanceof Score) {
hero.reduceHP(enemys.get(i).life);
Score s = (Score) enemys.get(i);
score += s.getScore();