// Maze class // Written by: // Date: // This maze class adds a bit more functionality from last week's // for example, the ability to load a maze from an array of strings // you'll add more capability in the form of the multiBFS function and // some helper functions... import java.io.BufferedReader; // This is required for dealing with files import java.io.FileReader; // This is required for dealing with files class Maze1 { // MazeCell - an inner class supporting Maze // // The following convention is used in mazes: // Walls are represented by '*' // Empty area is represented by the blank symbol ' ' // Starting point is represented by 'S' // Destination (SPAM!) is represented by 'D' class MazeCell { private int row; // The row at which this cell is located private int col; // The col at which this cell is located private char contents; // Each cell has contents (a char) private boolean visited; // A cell can be marked as visited. private MazeCell parent; // parent is where we came from! // Constructor of the MazeElement at row, col, with contents c // "visited" is set to false, and "parent" is set to null private MazeCell(int row, int col, char c) { this.row = row; // this is required to avoid name confusion! this.col = col; // ditto this.contents = c; this.visited = false; // we haven't been here yet... this.parent = null; // ... so we have no parent yet } // toString returns the string representation of a MazeElement public String toString() { return "[" + row + "," + col + "," + contents + "]"; } private boolean isWall() { return this.contents == '*'; } private boolean isOpen() { return this.contents == ' ' || this.contents == 'D'; } } /* data member for the Maze class... * a 2d rectangular array of MazeCells */ protected MazeCell[][] maze; // this is the maze! /* method: constructor * input: file name * output: a maze containing that file's data */ public Maze1(String filename) { this.maze = null; this.loadMazeFromFile(filename); } /* method: constructor * input: none * output: a maze containing ththe data in mazeStrings, below */ protected Maze1() { int HEIGHT = mazeStrings.length; int WIDTH = mazeStrings[0].length(); this.maze = new MazeCell[HEIGHT][WIDTH]; for (int r=0 ; r