4.3 读取property文件

master
terry 3 years ago
parent 8a420a013d
commit 848cf0fdb8

Binary file not shown.

@ -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));
}

@ -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));
}
}

@ -0,0 +1,5 @@
enemy.tank.number=8
tank.speed=5
bullet.speed=5
game.width=1080
game.height=720
Loading…
Cancel
Save