import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import java.util.ArrayList; /** * @author Chris Thiel, OFMCap * @version 16 May 2012 */ public class Cell { public static final int GAP=10, SIZE=40, LEFT=40, TOP=60; public static final int NORTH=0, SOUTH=1, EAST=2, WEST=3; private int visits, row, col; private boolean[] wall; private Rectangle box; public Cell(int r, int c) { visits=-1; row=r; col=c; wall=new boolean[4]; box = new Rectangle (LEFT+col*(SIZE+GAP), TOP+row*(SIZE+GAP), SIZE, SIZE); for (int i=0;i<4;i++) wall[i]=true; } /** * * @return a random neighboring Cell, or null if all neighbors have been visited */ public Cell randomNeighbor(Cell[][] m){ ArrayList n = new ArrayList(); //NORTH if (row>0 && m[row-1][col].getVisits()<0) n.add(m[row-1][col]); //SOUTH if (row0 && m[row][col-1].getVisits()<0) n.add(m[row][col-1]); //EAST if (col1) g.setColor(Color.RED); g.fillRect(box.x, box.y, box.width, box.height); if (!wall[SOUTH]) g.fillRect(box.x, box.y+SIZE, box.width, GAP); if (!wall[EAST]) g.fillRect(box.x+SIZE, box.y, GAP, box.width); g.setColor(oldColor); } public Rectangle getBox(){return box;} public int getRow(){return row;} public int getCol(){return col;} public int getVisits(){return visits;} public void setVisits(int i){visits=i;} public void incVisits(){visits++;} public void setWall(int direction, boolean value){ wall[direction]=value; } /** * removes the walls between this cell and the other cell * @param other */ public void removeWall(Cell other) { if (other.getRow()>row){//other cell is below this one this.setWall(SOUTH, false); other.setWall(NORTH, false); } if (other.getRow()col){//other cell is east of this one this.setWall(EAST, false); other.setWall(WEST, false); } if (other.getCol()