import java.awt.*; import java.applet.Applet; import java.awt.event.*; import java.lang.Math; public class maze extends Applet implements ActionListener { /* change these values for different size mazes: */ int bh = 20; // height of a graphical block int bw = 20; // width of a graphical block int mh = 25; // height and width of maze int mw = 25; int ah, aw; // height and width of graphical maze int yoff = 40; // init y-cord of maze; makes room for start button byte[][] M; // the array for the maze // it uses "byte" instead of "int" to save memory private Button startbutton; /* Use this method to set array value from 0 to 1, and draw a black rectangle on the applet to represent the "carving out" of this cell graphically: */ public void fill(int x, int y) // set array value and draw graphics { M[x][y] = 1; // set maze value to 1 (black) Graphics g; g = getGraphics(); // get drawing device for applet g.fill3DRect(x*bw,yoff+(y*bh),bw,bh,false); } /* Use this method to slow down your program so you can see better what's going on. x == 50 should be a good value. */ public void delay(int x) // real time delay of x milliseconds { try { Thread.sleep( x ); } catch ( InterruptedException e ) { System.out.println( e.toString() ); } } /* main algorithm */ public void digout(int x, int y) {/* most of your code will go here */ } /* leave this alone unless you know what you're doing: */ public void init() { startbutton = new Button("Begin"); startbutton.addActionListener( this ); add(startbutton); ah = bh*mh; aw = bw*mw; M = new byte[mw][mh]; // initialize maze (all 0's - walls). resize(aw+10,10+ah+yoff); // resize applet } public void paint(Graphics g) { int i, j; // draw initial maze: g.setColor(Color.green); g.fill3DRect(0,yoff,aw,ah,true); // fill raised rectangle g.setColor(Color.black); } // end of paint // start button handler public void actionPerformed( ActionEvent e ) { showStatus("Generating maze..."); digout(10,mh-1); // start digging! showStatus("Maze Complete!"); } } // end mazes