坦克大战(一期)-添加边界检测

Network
bingor_yhj 3 years ago
parent df25691dc0
commit 90f675cbdb

@ -71,13 +71,12 @@ public class Tank {
default: break;
}
// this.boundsCheck();
//敌方坦克随机发射炮弹
if(this.group == GroupEnum.BAD && random.nextInt(100) > 95) this.fire();
//敌方坦克随机改变方向进行
if(this.group == GroupEnum.BAD && random.nextInt(100) > 95) this.randomDir();
this.boundsCheck();
}
public void randomDir() {
@ -96,9 +95,10 @@ public class Tank {
}
public void boundsCheck() {
if(x<0 || y<0 || x>TankFrame.GAME_WIDTH || y>TankFrame.GAME_HEIGHT) {
this.setDir(DirEnum.valueOf(random.nextInt(30)%4));
}
if(this.x < 2) this.x = 2;
if(this.x > TankFrame.GAME_WIDTH-Tank.WIDTH-2) this.x = TankFrame.GAME_WIDTH-Tank.WIDTH-2;
if(this.y < 28) this.y = 28; //因为窗口顶上有菜单栏的高度
if(this.y > TankFrame.GAME_HEIGHT-Tank.HEIGHT-2) this.y = TankFrame.GAME_HEIGHT-Tank.HEIGHT-2;
}
public int getX() {

Loading…
Cancel
Save