From 90f675cbdb3a7df71dfa459a9ed1ef3268875676 Mon Sep 17 00:00:00 2001 From: bingor_yhj Date: Wed, 5 Oct 2022 20:42:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8B=E5=A4=A7=E6=88=98(=E4=B8=80?= =?UTF-8?q?=E6=9C=9F)-=E6=B7=BB=E5=8A=A0=E8=BE=B9=E7=95=8C=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/msb/Tank.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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() {