关卡的解析
//初始化地图的元素块 level表示第几关
public void initMap(int level) {
tiles.clear();
try {
loadLeveal(level);
} catch (Exception e) {
e.printStackTrace();
}
//初始化大本营
house = new TankHouse();
addHouse();
}
/**
* 解析关卡信息
* @param level
*/
private void loadLeveal(int level) throws Exception{
Properties prop = new Properties();
prop.load(new FileInputStream("level/lv_"+level));
//将所有的地图信息都加载进来
int enemyCount = Integer.parseInt(prop.getProperty("enemyCount"));
//0,1 对敌人类型解析
String[] enemyType = prop.getProperty("enemyType").split(",");
//对敌人类型解析
int[] type = new int[enemyType.length];
for (int i = 0; i < type.length; i++) {
type[i] = Integer.parseInt(enemyType[i]);
}
String methodName = prop.getProperty("method");
int invokeCount = Integer.parseInt(prop.getProperty("invokeCount"));
//把实参传入数组中来
String[] params = new String[invokeCount];
for (int i = 1; i <= invokeCount; i++) {
params[i-1] = prop.getProperty("param"+i);
}
//将读取到的参数调用对应的方法
}