diff --git a/docs/坦克大战笔记.docx b/docs/坦克大战笔记.docx index 2cb4723..cf2339f 100644 Binary files a/docs/坦克大战笔记.docx and b/docs/坦克大战笔记.docx differ diff --git a/src/com/demo/tank/course4/MainV4.java b/src/com/demo/tank/course4/MainV4.java index 0c799f5..1d10fd2 100644 --- a/src/com/demo/tank/course4/MainV4.java +++ b/src/com/demo/tank/course4/MainV4.java @@ -1,13 +1,15 @@ package com.demo.tank.course4; import com.demo.tank.util.Audio; +import com.demo.tank.util.PropertyManager; import java.io.IOException; public class MainV4 { public static void main(String[] args) throws InterruptedException, IOException { TankFrameV4 tf = new TankFrameV4(); - for(int i = 0; i < 5; i++){ + int enemyTankNum = PropertyManager.getInt("enemy.tank.number"); + for(int i = 0; i < enemyTankNum; i++){ tf.enemyTanks.add(new Tank(50 + i*80, 200, Direction.DOWN, Group.BAD, tf)); } diff --git a/src/com/demo/tank/util/PropertyManager.java b/src/com/demo/tank/util/PropertyManager.java new file mode 100644 index 0000000..c0abe45 --- /dev/null +++ b/src/com/demo/tank/util/PropertyManager.java @@ -0,0 +1,22 @@ +package com.demo.tank.util; + + +import java.io.IOException; +import java.util.Properties; + +public class PropertyManager { + static Properties property = new Properties(); + + static { + try { + property.load(PropertyManager.class.getClassLoader().getResourceAsStream("config")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static int getInt(String key){ + if(property == null) return 0; + return Integer.valueOf((String)property.get(key)); + } +} diff --git a/src/config b/src/config new file mode 100644 index 0000000..00285eb --- /dev/null +++ b/src/config @@ -0,0 +1,5 @@ +enemy.tank.number=8 +tank.speed=5 +bullet.speed=5 +game.width=1080 +game.height=720 \ No newline at end of file