rendered paste bodypublic class MazeLoader {
private int[][] _file;
private int _curLine = 0;
public MazeLoader(String file) {
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String str;
initialize(in.readLine());
while ((str = in.readLine()) != null) {
process(str);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public int getNumAdj(int node) {
return 1;
}
public int getAdjTo(int source, int adjIndex) {
return 1;
}
private void initialize(String line) {
String[] split = line.split(",");
this.set_file(new int[Integer.parseInt(split[0])][Integer.parseInt(split[1])]);
}
private void process(String line) {
for(int i = 0; i < line.length(); i++) {
if(line.charAt(i) == 'X' ) {
this.get_file()[this.get_curLine()][i] = 0x0001;
} else if (line.charAt(i) == 'S') {
this.get_file()[this.get_curLine()][i] = 0x0010;
} else if (line.charAt(i) == 'E') {
this.get_file()[this.get_curLine()][i] = 0x0100;
} else if (line.charAt(i) == 'F') {
this.get_file()[this.get_curLine()][i] = 0x1000;
}
}
this.set_curLine(this.get_curLine()+1);
}
/**
* @return Returns the _file.
*/
public final int[][] get_file() {
return _file;
}
/**
* @param _file
* The _file to set.
*/
public final void set_file(int[][] _file) {
this._file = _file;
}
/**
* @return Returns the _curLine.
*/
public final int get_curLine() {
return _curLine;
}
/**
* @param line The _curLine to set.
*/
public final void set_curLine(int line) {
_curLine = line;
}
public String toString() {
return Arrays.deepToString(this.get_file());
}
}