属性配置

master
kn5886348135 3 years ago
parent 27b0107b7a
commit 0c4808ce8e

@ -4,8 +4,10 @@ public class Main {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
TankFrame tf = new TankFrame(); TankFrame tf = new TankFrame();
int initTankCount = Integer.valueOf(PropertyMgr.get("initTankCount"));
// 初始化敌方坦克 // 初始化敌方坦克
for (int i = 0; i < 5; i++) { for (int i = 0; i < initTankCount; i++) {
tf.tanks.add(new Tank(50 + i * 80, 200, Dir.DOWN, Group.BAD, tf)); tf.tanks.add(new Tank(50 + i * 80, 200, Dir.DOWN, Group.BAD, tf));
} }

@ -0,0 +1,29 @@
package com.example.tankbattle;
import java.io.IOException;
import java.util.Properties;
public class PropertyMgr {
private static Properties properties = new Properties();
static {
try {
properties.load(PropertyMgr.class.getClassLoader().getResourceAsStream("config.properties"));
} catch (IOException exception) {
exception.printStackTrace();
}
}
public static String get(String key) {
if (properties == null) {
return null;
}
return properties.getProperty(key);
}
//int getInt(key)
//getString(key)
public static void main(String[] args) {
System.out.println(PropertyMgr.get("initTankCount"));
}
}

@ -20,7 +20,8 @@ public class TankFrame extends Frame {
List<Explode> explodes = new ArrayList<>(); List<Explode> explodes = new ArrayList<>();
static final int GAME_WIDTH = 1080, GAME_HEIGHT = 960; static final int GAME_WIDTH = Integer.valueOf(PropertyMgr.get("gameWidth"));
static final int GAME_HEIGHT = Integer.valueOf(PropertyMgr.get("gameHeight"));
public TankFrame() { public TankFrame() {
setSize(GAME_WIDTH, GAME_HEIGHT); setSize(GAME_WIDTH, GAME_HEIGHT);

@ -0,0 +1,6 @@
# tanks count at initialization
initTankCount=10
tankSpeed=5
bulletSpeed=10
gameWidth=1080
gameHeight=720
Loading…
Cancel
Save