|
|
@ -1,21 +1,21 @@
|
|
|
|
package com.demo.tank.course7;
|
|
|
|
package com.demo.tank.course7;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.demo.tank.course7.abstractFactory.BaseTank;
|
|
|
|
import com.demo.tank.enums.Direction;
|
|
|
|
import com.demo.tank.enums.Direction;
|
|
|
|
import com.demo.tank.enums.Group;
|
|
|
|
import com.demo.tank.enums.Group;
|
|
|
|
import com.demo.tank.util.PropertyManager;
|
|
|
|
|
|
|
|
import com.demo.tank.util.ResourceManager;
|
|
|
|
import com.demo.tank.util.ResourceManager;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.util.Random;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
|
|
public class Tank {
|
|
|
|
public class Tank extends BaseTank {
|
|
|
|
private int x,y;
|
|
|
|
private int x,y;
|
|
|
|
private Direction dir;
|
|
|
|
private Direction dir;
|
|
|
|
private static final int SPEED = 8;
|
|
|
|
private static final int SPEED = 8;
|
|
|
|
private boolean moving = true;
|
|
|
|
private boolean moving = true;
|
|
|
|
private boolean living = true;
|
|
|
|
private boolean living = true;
|
|
|
|
private Group group = Group.BAD;
|
|
|
|
private Group group = Group.BAD;
|
|
|
|
TankFrameV6 tankFrame = null;
|
|
|
|
TankFrameV7 tankFrame = null;
|
|
|
|
public static final int WIDTH = ResourceManager.tankD.getWidth();
|
|
|
|
public static final int WIDTH = ResourceManager.tankD.getWidth();
|
|
|
|
public static final int HEIGHT = ResourceManager.tankD.getHeight();
|
|
|
|
public static final int HEIGHT = ResourceManager.tankD.getHeight();
|
|
|
|
private Random random = new Random();
|
|
|
|
private Random random = new Random();
|
|
|
@ -23,7 +23,7 @@ public class Tank {
|
|
|
|
FireStrategy fireStrategy;
|
|
|
|
FireStrategy fireStrategy;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Tank(int x, int y, Direction dir, Group group, TankFrameV6 tankFrame) {
|
|
|
|
public Tank(int x, int y, Direction dir, Group group, TankFrameV7 tankFrame) {
|
|
|
|
this.x = x;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.y = y;
|
|
|
|
this.dir = dir;
|
|
|
|
this.dir = dir;
|
|
|
@ -36,9 +36,9 @@ public class Tank {
|
|
|
|
rect.height = Tank.HEIGHT;
|
|
|
|
rect.height = Tank.HEIGHT;
|
|
|
|
|
|
|
|
|
|
|
|
if(this.group == Group.GOOD) {
|
|
|
|
if(this.group == Group.GOOD) {
|
|
|
|
String className = PropertyManager.getString("good.tank.fire.strategy");
|
|
|
|
// String className = PropertyManager.getString("good.tank.fire.strategy");
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
fireStrategy = (FireStrategy) Class.forName(className).newInstance();
|
|
|
|
fireStrategy = (FireStrategy) Class.forName("com.demo.tank.course7.FourDirectionFireStrategy").newInstance();
|
|
|
|
System.out.println(fireStrategy);
|
|
|
|
System.out.println(fireStrategy);
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -50,6 +50,7 @@ public class Tank {
|
|
|
|
}else if(this.group == Group.BAD) fireStrategy = new DefaultFireStrategy();
|
|
|
|
}else if(this.group == Group.BAD) fireStrategy = new DefaultFireStrategy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
if(!living) tankFrame.enemyTanks.remove(this);
|
|
|
|
if(!living) tankFrame.enemyTanks.remove(this);
|
|
|
|
//根据方向绘制坦克
|
|
|
|
//根据方向绘制坦克
|
|
|
@ -103,9 +104,9 @@ public class Tank {
|
|
|
|
|
|
|
|
|
|
|
|
private void boundsCheck() {
|
|
|
|
private void boundsCheck() {
|
|
|
|
if(x < 0) x = 0;
|
|
|
|
if(x < 0) x = 0;
|
|
|
|
if(x > TankFrameV6.GAME_WIDTH - Tank.WIDTH) x = TankFrameV6.GAME_WIDTH - Tank.WIDTH;
|
|
|
|
if(x > TankFrameV7.GAME_WIDTH - Tank.WIDTH) x = TankFrameV7.GAME_WIDTH - Tank.WIDTH;
|
|
|
|
if(y < 30) y = 30; //算上菜单条
|
|
|
|
if(y < 30) y = 30; //算上菜单条
|
|
|
|
if(y > TankFrameV6.GAME_HEIGHT - Tank.HEIGHT) y = TankFrameV6.GAME_HEIGHT - Tank.HEIGHT;
|
|
|
|
if(y > TankFrameV7.GAME_HEIGHT - Tank.HEIGHT) y = TankFrameV7.GAME_HEIGHT - Tank.HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void randomDirection() {
|
|
|
|
private void randomDirection() {
|
|
|
@ -168,11 +169,11 @@ public class Tank {
|
|
|
|
this.group = group;
|
|
|
|
this.group = group;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TankFrameV6 getTankFrame() {
|
|
|
|
public TankFrameV7 getTankFrame() {
|
|
|
|
return tankFrame;
|
|
|
|
return tankFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setTankFrame(TankFrameV6 tankFrame) {
|
|
|
|
public void setTankFrame(TankFrameV7 tankFrame) {
|
|
|
|
this.tankFrame = tankFrame;
|
|
|
|
this.tankFrame = tankFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|