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