/* * Maze * Creates a grid of rooms, hallways between the rooms * Then, hallways are picked at random with their adjoining doors * opened up as specified in the lab. * * Author: Ron Cytron * Course: CS101 */ import cs101.terminal.*; import cs101.canvas.*; public class Maze { private CS101Canvas canvas; private int rows, // The number of rows and columns in this maze cols; private int pixs; // The number of pixels occupied by each room private RoomListList rll; // The master list of list of rooms (a RoomListList) private HallList halls; public Maze(int n) { this(n,n,18); } // a default maze public Maze(int rows, int cols, int pixs) { this.rows = rows; this.cols = cols; this.pixs = pixs; canvas = new CS101Canvas(); initMaze(); } /* * Generate the rooms and halls of the maze */ private void initMaze() { rll = null; // the master list of list of rooms for (int i=rows; i>=1; --i) { /* Generate a row of rooms in rl */ RoomList rl = null; for (int j=cols; j>=1; --j) { rl = new RoomList(new Room(i,j,pixs,canvas), rl); } rll = new RoomListList(rl, rll); } Terminal.println("The list of list of rooms is:\n" + rll); /* * Now create the hallways. First the horizontal ones */ halls = null; for (int i=1; i<=rows; ++i) { for (int j=1; j