Skip to content

Instantly share code, notes, and snippets.

@lubaochuan
Created October 24, 2017 16:22
Show Gist options
  • Save lubaochuan/40223d4a5bfa616fd4b8ba9cce7431df to your computer and use it in GitHub Desktop.
Save lubaochuan/40223d4a5bfa616fd4b8ba9cce7431df to your computer and use it in GitHub Desktop.
public Maze(String fileName) throws FileNotFoundException{
Scanner scan = new Scanner(new File(fileName));
cols = Integer.parseInt(scan.next());
rows = Integer.parseInt(scan.next());
grid = new Square[rows][cols];
// remove line break;
scan.nextLine();
// read maze configuration
for(int i=0; i<rows; i++){
String row = scan.nextLine();
for(int j=0; j<cols; j++){
// create a square from the char representation
SquareType type = SquareType.fromChar(row.charAt(j));
Square s = new Square(type, i, j);
grid[i][j] = s;
// remember the square as "start" if it is the starting point
if(type == SquareType.START){
start = s;
}
//System.out.print(row.charAt(j));
}
//System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment