|
|
@ -22,6 +22,7 @@ public class Tank {
|
|
|
|
private boolean live = true;
|
|
|
|
private boolean live = true;
|
|
|
|
private Random random = new Random();
|
|
|
|
private Random random = new Random();
|
|
|
|
private GroupEnum group = GroupEnum.BAD;
|
|
|
|
private GroupEnum group = GroupEnum.BAD;
|
|
|
|
|
|
|
|
// private Rectangle rectangle;
|
|
|
|
|
|
|
|
|
|
|
|
public Tank(int x, int y, DirEnum dir, GroupEnum group, TankFrame tankFrame) {
|
|
|
|
public Tank(int x, int y, DirEnum dir, GroupEnum group, TankFrame tankFrame) {
|
|
|
|
this.x = x;
|
|
|
|
this.x = x;
|
|
|
@ -29,6 +30,7 @@ public class Tank {
|
|
|
|
this.dir = dir;
|
|
|
|
this.dir = dir;
|
|
|
|
this.group = group;
|
|
|
|
this.group = group;
|
|
|
|
this.tankFrame = tankFrame;
|
|
|
|
this.tankFrame = tankFrame;
|
|
|
|
|
|
|
|
// this.rectangle = new Rectangle(x, y, WIDTH, HEIGHT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
public void paint(Graphics g) {
|
|
|
@ -52,6 +54,10 @@ public class Tank {
|
|
|
|
this.dir = dir;
|
|
|
|
this.dir = dir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DirEnum getDir() {
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void moving() {
|
|
|
|
public void moving() {
|
|
|
|
|
|
|
|
|
|
|
|
if( ! move) return;
|
|
|
|
if( ! move) return;
|
|
|
@ -64,8 +70,17 @@ public class Tank {
|
|
|
|
default: break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(random.nextInt(10) > 8) this.fire();
|
|
|
|
// this.boundsCheck();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//敌方坦克随机发射炮弹
|
|
|
|
|
|
|
|
if(this.group == GroupEnum.BAD && random.nextInt(100) > 95) this.fire();
|
|
|
|
|
|
|
|
//敌方坦克随机改变方向进行
|
|
|
|
|
|
|
|
if(this.group == GroupEnum.BAD && random.nextInt(100) > 95) this.randomDir();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void randomDir() {
|
|
|
|
|
|
|
|
this.dir = DirEnum.values()[random.nextInt(4)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setMove(boolean move) {
|
|
|
|
public void setMove(boolean move) {
|
|
|
@ -79,6 +94,12 @@ public class Tank {
|
|
|
|
tankFrame.bullets.add(new Bullet(bX, bY, this.dir, this.group, tankFrame));
|
|
|
|
tankFrame.bullets.add(new Bullet(bX, bY, this.dir, this.group, tankFrame));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void boundsCheck() {
|
|
|
|
|
|
|
|
if(x<0 || y<0 || x>TankFrame.GAME_WIDTH || y>TankFrame.GAME_HEIGHT) {
|
|
|
|
|
|
|
|
this.setDir(DirEnum.valueOf(random.nextInt(30)%4));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int getX() {
|
|
|
|
public int getX() {
|
|
|
|
return x;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -95,4 +116,9 @@ public class Tank {
|
|
|
|
public GroupEnum getGroup() {
|
|
|
|
public GroupEnum getGroup() {
|
|
|
|
return group;
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*public Rectangle getRectangle() {
|
|
|
|
|
|
|
|
return rectangle;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|