Question: I need help refactoring my code so that the random maze that is generated does not have doors with no exits and rooms with no
I need help refactoring my code so that the random maze that is generated does not have "doors with no exits" and "rooms with no doors." Here's the code I have implemented:
private static void makeMazeRecursive(char[][]level, int startX, int startY, int endX, int endY){ // check if endX and endY is greater than 1 if(endX > 1 && endY > 1) { if(endX - startX >= 4 && endY - startY >= 4) { // generate random number Random random = new Random(); // initialize row and column int row = startY + random.nextInt(endY - startY); int column = startX + random.nextInt(endX - startX); for(int n = startX; n
Here's an example of the errors I am getting:

Here is the rest of the code:
import java.util.Random;
public class ser222_01_01_hw02_base { //standard console size in characters. private static final int LEVEL_HEIGHT = 25; private static final int LEVEL_WIDTH = 80; private static final char ICON_WALL = '#'; private static final char ICON_BLANK = ' ';
/** * Creates a random maze in a 2D array. */ private static char[][] makeMaze() { char level[][] = createBlankLevel(); makeMazeRecursive(level, 1, 1, LEVEL_WIDTH-2, LEVEL_HEIGHT-2); //TODO: may need to change but probably not. return level; }
/** * Creates an empty level of standard level height and width. Level will be * blank but bordered with wall characters. * * @return 2D array containing a maze */ private static char[][] createBlankLevel() { char level[][] = new char[LEVEL_HEIGHT][LEVEL_WIDTH]; //reset level to be entirely blank for (int y = 0; y
//TODO: complete method. private static void makeMazeRecursive(char[][]level, int startX, int startY, int endX, int endY) {
} /** * Displays a level in the console. * * @param level 2D array containing a maze */ private static void drawLevel(char[][] level) { int y, x; for (y = 0; y
/** * Entry point. * * @param args command line arguments */ public static void main(String[] args) { //show static maze (uncomment for sample output) //drawLevel(makeMazeStatic()); //show recursive maze drawLevel(makeMaze()); } }
# # # ## ## ##### ## DOOTS I Wants #### ## ## ##: = ## /** Returns a 2D array containing a statically created maze with dimentions 80x24. @return 2D array containing a maze */ private static char[][] makeMazeStatic() { //the following maze was generated with the recursive division method and then modified by hand. char level[][] {{'#','#' '#' {'#' {'#' {'#', {'# {'# {'# {'# {'#' {'#' {'#' {'#' {'#' {'# {'# {'#' {'#' {'# {'# {'# {'# {'# {'#' {'# {'# return level; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
