【发布时间】:2016-01-06 12:20:33
【问题描述】:
我想用 Java 编写一个 pacmanstyle 迷宫游戏。
对于迷宫,我使用的是属性文件,其中坐标以以下格式存储(即 x=1,y=5 -> 墙)为字符串:79,13=0 79,12=0 79,11=0。
我想使用二维数组创建迷宫网格:int [][] maze。
我知道如何加载属性文件。然而,我的问题是,我不知道如何首先从属性中提取字符串变量,其次才是填充数组的正确方法。
public final class Labyrinth {
private int i;
private int j;
private static int [][] maze;
private String p;
private String l;
public void setMaze(int x, int y){
x = this.i;
y = this.j;
}
public static int[][] getMaze(){
return maze;
}
public Labyrinth(int rows, int cols) throws IOException{
try (FileInputStream in = new FileInputStream("level.properties")) {
Properties p1 = new Properties();
p1.load(in);
p = p1.getProperty("Height");
l = p1.getProperty("Width");
cols = parseInt(p);
rows = parseInt(l);
maze = new int[rows][cols];
for (i=0; i < rows; i++){
for(j=0; j < cols; j++){
setMaze(parseInt(p1.getProperty('ValueX,ValueY')),
parseInt(p1.getProperty('ValueX,ValueY')));
}
}
}
}
}
任何有帮助的想法都将受到高度赞赏!
【问题讨论】:
标签: java arrays properties