Question: Using java The goal is to generate a 2D maze. To accomplish this you will need two classes, Maze and Cell. The Cell class should
The goal is to generate a 2D maze. To accomplish this you will need two classes, Maze and Cell. The Cell class should be implemented as a private class inside the Maze class. That way you can directly access its attributes without the need for get and set methods The Cell class represents a single cell in the maze. It should have the following attributes: 1. north 2. east 3. south 4. west 5. visited 6. row 7. column The first 4 attributes are boolean and indicate if there is a wall between the current cell and one of its neighbors. For example if north is false that means that there is no wall between the current cell and its north neighbor. If south is true it means there is a wall between the current cell and its south neighbor. The attribute visited is used to mark whether a neighbor was visited or not. Row and column refer to the cell's location in the maze (the 2D array of cells mentioned below). The Maze class will have the following attributes: 1. 2D array of Cells representing the maze 2. nrRows-the number of rows 3. nrCols the number of columns It will also have the following methods: 1. A constructor that accepts as input the number of rows and columns 2. generateMaze(int startRow, int startCol)-that generates a random maze using the algorithm described below. 3. toString0 method that will print the maze To generate a maze you will use the following algorithm (known as Recursive Backtracker): Mark maze start as visited; create a stack with elements of type Cell using Java API. Push start onto the stack; while stack is not empty do Pop current cell off stack; if current cell has unvisited neighbors then Choose a random unvisited neighbor; Remove wall with neighbor Mark neighbor as visited
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
