import java.io.*; import java.util.Arrays; /* * Created on Nov 15, 2006 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author gbrent * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ public 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) { String[] split = line.split(""); System.out.println("Length: " + split.length); System.out.println("Debug: " + Arrays.toString(split)); for(int i = 0; i < split.length; i++) { if(split[i].matches("[Xx]")) { this.get_file()[this.get_curLine()][i] = 0x0001; } else if (split[i].matches("[Ss]")) { this.get_file()[this.get_curLine()][i] = 0x0010; } else if (split[1].matches("[Ee]")) { this.get_file()[this.get_curLine()][i] = 0x0100; } else if (split[1].matches("[Ff]")) { 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 java.util.Arrays.toString(this.get_file()); } }