import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; /** * @author Chris Thiel, OFMCap * @version 16 May 2012 (Applet) * @version 5 Sept 2021 (Application) */ public class MakeMaze extends JPanel implements MouseListener { public static final int ROWS=6, COLS=6; public static final int WIDTH=575, HEIGHT=620; private Cell[][] m; String message="Making Maze"; public static void main(String[] args) { MakeMaze app= new MakeMaze(); JFrame window = new JFrame("Make Maze"); window.setSize(WIDTH, HEIGHT); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.getContentPane().add(app); window.setVisible(true); } public MakeMaze() { message="Making First Maze"; makeMaze(); message="First Maze done."; this.addMouseListener(this); } public void makeMaze() { m = new Cell[ROWS][COLS]; for (int r=0;r stack=new ArrayList(); while (unvisitedCells()){ Cell choice=currentCell.randomNeighbor(m); if (choice!=null){ stack.add(0, currentCell); currentCell.removeWall(choice); currentCell=choice; currentCell.incVisits(); }else{ stack.remove(0); currentCell=stack.get(0); } repaint(); } } private boolean unvisitedCells(){ int r=0; while(r