diff --git a/resources/config.properties b/resources/config.properties new file mode 100644 index 0000000..fb36f7e --- /dev/null +++ b/resources/config.properties @@ -0,0 +1,6 @@ +#tanks count at initialization +initTankCount=10 +tankSpeed=5 +bulletSpeed=10 +gameWidth=1080 +gameHeight=720 \ No newline at end of file diff --git a/src/com/msb/PropertyMgr.java b/src/com/msb/PropertyMgr.java new file mode 100644 index 0000000..0570e0f --- /dev/null +++ b/src/com/msb/PropertyMgr.java @@ -0,0 +1,33 @@ +package com.msb; + +import java.io.IOException; +import java.util.Objects; +import java.util.Properties; + +/** + * @Author bingor + * @Date 2022-10-05 22:35 + * @Description: com.msb + * @Version: 1.0 + */ +public class PropertyMgr { + + private static Properties props = new Properties(); + + static { + try { + props.load(PropertyMgr.class.getClassLoader().getResourceAsStream("config.properties")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static Object get(String key) { + return props.get(key); + } + + public static void main(String[] args) { + System.out.println(get("initTankCount")); + } + +} diff --git a/src/com/msb/Tank.java b/src/com/msb/Tank.java index 9904705..4b5dfd7 100644 --- a/src/com/msb/Tank.java +++ b/src/com/msb/Tank.java @@ -13,7 +13,7 @@ public class Tank { private int x,y; private DirEnum dir; - private static final int SPEED = 2; + private static final int SPEED = 4; private boolean move = true; //为了解决能够在坦克中发射子弹,将创建的子弹通过坦克发射出来,那么需要在坦克类中持有游戏窗口的引用 private TankFrame tankFrame; @@ -75,15 +75,15 @@ public class Tank { default: break; } - rectangle.x = this.x; - rectangle.y = this.y; - //敌方坦克随机发射炮弹 if(this.group == GroupEnum.BAD && random.nextInt(100) > 95) this.fire(); //敌方坦克随机改变方向进行 if(this.group == GroupEnum.BAD && random.nextInt(100) > 95) this.randomDir(); this.boundsCheck(); + + rectangle.x = this.x; + rectangle.y = this.y; } public void randomDir() { diff --git a/src/com/msb/TankDemo.java b/src/com/msb/TankDemo.java index 4a6b454..e657abc 100644 --- a/src/com/msb/TankDemo.java +++ b/src/com/msb/TankDemo.java @@ -14,8 +14,10 @@ public class TankDemo { TankFrame tankFrame = new TankFrame(); Random random = new Random(); + int initTankCount = Integer.parseInt((String) PropertyMgr.get("initTankCount")); + //创建5个敌方坦克 - for (int i=0; i<5; i++) { + for (int i=0; i bullets = new ArrayList<>(); List tanks = new ArrayList<>(); //敌方坦克 List explodes = new ArrayList<>(); //爆炸效果 - public static final int GAME_WIDTH = 800; - public static final int GAME_HEIGHT = 600; + public static final int GAME_WIDTH = 1000; + public static final int GAME_HEIGHT = 800; public TankFrame() {