diff --git a/src/com/msb/Tank.java b/src/com/msb/Tank.java index 0ea3832..cd8bdb8 100644 --- a/src/com/msb/Tank.java +++ b/src/com/msb/Tank.java @@ -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() {