移动代码位置

master
kn5886348135 3 years ago
parent 22a515741c
commit b53ad2ca36

@ -62,55 +62,64 @@ public class Tank {
return moving; return moving;
} }
public void setMoving(boolean moving) { private void move() {
this.moving = moving; if (!moving) return;
}
public void setDir(Dir dir) {
this.dir = dir;
}
public void paint(Graphics g) {
if (!living) tf.tanks.remove(this);
switch (dir) { switch (dir) {
case LEFT: case LEFT:
g.drawImage(ResourceMgr.tankL, x, y, null); x -= SPEED;
break; break;
case UP: case UP:
g.drawImage(ResourceMgr.tankU, x, y, null); y -= SPEED;
break; break;
case RIGHT: case RIGHT:
g.drawImage(ResourceMgr.tankR, x, y, null); x += SPEED;
break; break;
case DOWN: case DOWN:
g.drawImage(ResourceMgr.tankD, x, y, null); y += SPEED;
break; break;
default: default:
break; break;
} }
move();
if (random.nextInt(10) > 5) this.fire();
} }
private void move() { public void paint(Graphics g) {
if (!moving) return; if (!living) tf.tanks.remove(this);
switch (dir) { switch (dir) {
case LEFT: case LEFT:
x -= SPEED; g.drawImage(ResourceMgr.tankL, x, y, null);
break; break;
case UP: case UP:
y -= SPEED; g.drawImage(ResourceMgr.tankU, x, y, null);
break; break;
case RIGHT: case RIGHT:
x += SPEED; g.drawImage(ResourceMgr.tankR, x, y, null);
break; break;
case DOWN: case DOWN:
y += SPEED; g.drawImage(ResourceMgr.tankD, x, y, null);
break; break;
default: default:
break; break;
} }
move();
}
if (random.nextInt(10) > 5) this.fire();
public void setMoving(boolean moving) {
this.moving = moving;
}
public void setDir(Dir dir) {
this.dir = dir;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
} }
public void die() { public void die() {

Loading…
Cancel
Save