|
|
|
@ -13,6 +13,7 @@ public class Tank {
|
|
|
|
|
private int x,y;
|
|
|
|
|
private DirEnum dir;
|
|
|
|
|
private static final int SPEED = 10;
|
|
|
|
|
private boolean move = false;
|
|
|
|
|
|
|
|
|
|
public Tank(int x, int y, DirEnum dir) {
|
|
|
|
|
this.x = x;
|
|
|
|
@ -22,6 +23,16 @@ public class Tank {
|
|
|
|
|
|
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
|
g.fillRect(x, y, 50, 50);
|
|
|
|
|
moving();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDir(DirEnum dir) {
|
|
|
|
|
this.dir = dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void moving() {
|
|
|
|
|
|
|
|
|
|
if( ! move) return;
|
|
|
|
|
|
|
|
|
|
switch (dir) {
|
|
|
|
|
case UP: y -= SPEED; break;
|
|
|
|
@ -30,9 +41,10 @@ public class Tank {
|
|
|
|
|
case RIGHT: x += SPEED; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDir(DirEnum dir) {
|
|
|
|
|
this.dir = dir;
|
|
|
|
|
public void setMove(boolean move) {
|
|
|
|
|
this.move = move;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|