// Craig Duttweiler CS 193i June, 1996 // MazeApplet is a java applet that implements a maze through which // three monsters move randomly and one player moves by keyboard input import java.awt.*; import java.applet.*; import java.lang.Math; import java.awt.image.*; import java.net.*; import RandomBag; import Coordinates; //-------------------------------------------------------------------------- // Keep track of what's going on in one square of the maze. class Room { // array over the four directions: N, E, S, W boolean[] walls = {true, true, true, true}; byte state = Maze.FarFromMaze; Player inhabitant = null; }; //-------------------------------------------------------------------------- class Maze extends Canvas { // constants public static final byte FarFromMaze = 0; public static final byte NearMaze = 1; public static final byte InMaze = 2; int xRooms, yRooms, xRoomSize, yRoomSize; Room[][] rooms; public Maze(int XRooms, int YRooms, int XRoomSize, int YRoomSize) { int i,j; xRooms = XRooms; yRooms = YRooms; xRoomSize = XRoomSize; yRoomSize = YRoomSize; // allocate the rooms rooms = new Room[xRooms][yRooms]; for (i=0; i 0){ //Attach to the maze one randomly chosen adjacent square addToMaze(near, (Coordinates)near.randomRemove()); } } private void build() { byte seedX = (byte)(Math.random()*xRooms); byte seedY = (byte)(Math.random()*yRooms); carve(seedX, seedY); } // clear out the old maze, rebuild it, and repaint it public void rebuild() { int i,j, wallnum; for (i=0; i