import java.awt.*; import java.awt.event.*; import java.awt.Graphics; import javax.swing.*; public class mazesolver extends JFrame implements ActionListener { /* default values: */ private int bh = 10; // height of a graphical block private int bw = 10; // width of a graphical block private int mh = 41; // height and width of maze private int mw = 51; private int ah, aw; // height and width of graphical maze private int yoff = 40; // init y-cord of maze private Graphics g; private int dtime = 40; // 40 ms delay time byte[][] M; // the array for the maze private Button startbutton; public static final int SOUTH = 0; public static final int EAST = 1; public static final int NORTH = 2; public static final int WEST = 3; // args determine block size, maze height, and maze width public mazesolver(int bh0, int mh0, int mw0) { bh = bw = bh0; mh = mh0; mw = mw0; ah = bh*mh; aw = bw*mw; startbutton = new Button("Begin"); startbutton.setBounds((aw/2)-40,yoff+20,80,30); Container pane = this.getContentPane(); // the "content pane" of window pane.setLayout(null); // else java will place items automatically pane.add(startbutton); startbutton.addActionListener( this ); M = new byte[mh][mw]; // initialize maze (all 0's - walls). this.setBounds(0,0,aw+10,10+ah+yoff); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try{Thread.sleep(500);} catch(Exception e) {} // Synch with system g = getGraphics(); //g.setColor(Color.red); } public void paint(Graphics g) {} // override automatic repaint public void actionPerformed( ActionEvent e ) { startbutton.setVisible(false); g.setColor(Color.green); g.fill3DRect(0,yoff,aw,ah,true); // fill raised rectangle g.setColor(Color.black); // showStatus("Generating maze..."); digout(mh-2,mw-2); // start digging! // digout exit M[mh-1][mw-2] = 1; drawblock(mh-2,mw-1); solve(); // showStatus("Maze Complete!"); } public static void main(String[] args) { int blocksize = 16, mheight = 41, mwidth = 41; // need to be odd if (args.length==3) { mheight=Integer.parseInt(args[0]); mwidth=Integer.parseInt(args[1]); blocksize=Integer.parseInt(args[2]); } mazesolver W = new mazesolver(blocksize,mheight,mwidth); } /*************************************************************/ /*********************** Lab 9 *******************************/ public void drawblock(int y, int x) { g.setColor(Color.black); g.fillRect(x*bw,yoff+(y*bh),bw,bh); g.setColor(Color.yellow); // following line displays value of M[y][x] in the graphical maze: g.drawString(""+M[y][x],(x*bw)+(bw/2-4),yoff+(y*bh)+(bh/2+6)); } public void drawdot(int y, int x) { g.setColor(Color.red); g.fillOval(x*bw,yoff+(y*bh),bw,bh); try{Thread.sleep(140);} catch(Exception e) {} } /* *********** Paste your "digout" function here: ************* */ public void digout(int y, int x) {} /* Write a routine to solve the maze. Start at coordinates x=1, y=1, and stop at coordinates x=mw-2, y=mh-2. */ public void solve() { }//solve } // mazesolver class