/** * Cell.java * CIS 260 * David Klick * 2012-03-09 * * This class holds the properties and functionality * that a single cell in a maze needs. * * @author Dave Klick * @version 1.0 2012-03-09 */ import java.util.ArrayList; public class Cell { // each cell is aware of its position within the grid private int row, col; // walls indicate barriers between cells or an exterior edge private boolean wallN, wallE, wallS, wallW; // edges indicate an exterior edge private boolean edgeN, edgeE, edgeS, edgeW; // the visited field is available for use by algorithms private boolean visited; // allow storage for arbitrary content within a cell private int value; private String strValue; public ArrayList getNeighbors() { // ***** ***** // ***** THIS METHOD MUST BE IMPLEMENTED ***** // ***** ***** } public Cell(int r, int c) { // Cells are initialized as if they are a 1x1 grid, // with all sides set to be both walls and exterior // edges. wallN = wallE = wallS = wallW = true; edgeN = edgeE = edgeS = edgeW = false; // Clear all internal storage for algorithms to use. visited = false; value = 0; strValue = ""; // It helps if cells are self-aware of their location. row = r; col = c; } public String toString() { return "Cell[" + row + "][" + col + "]"; } public int getRow() { return row; } public int getCol() { return col; } public int getValue() { return value; } public String getStringValue() { return strValue; } public boolean isVisited() { return visited; } public boolean hasWall(Direction d) { boolean result = true; switch (d) { case NORTH: result = wallN; break; case EAST: result = wallE; break; case SOUTH: result = wallS; break; case WEST: result = wallW; break; } return result; } public boolean hasEdge(Direction d) { boolean result = true; switch (d) { case NORTH: result = edgeN; break; case EAST: result = edgeE; break; case SOUTH: result = edgeS; break; case WEST: result = edgeW; break; } return result; } public void setValue(int n) { value = n; } public void setStringValue(String s) { strValue = s; } public void setVisited(boolean v) { visited = v; } public void setVisited() { visited = true; } public void clearVisited() { visited = false; } public void setWall(Direction d, boolean b) { switch (d) { case NORTH: wallN = b; break; case EAST: wallE = b; break; case SOUTH: wallS = b; break; case WEST: wallW = b; break; } } public void setWall(Direction d) { setWall(d, true); } public void clearWall(Direction d) { setWall(d, false); } public void setEdge(Direction d, boolean b) { switch (d) { case NORTH: edgeN = b; break; case EAST: edgeE = b; break; case SOUTH: edgeS = b; break; case WEST: edgeW = b; break; } } public void setEdge(Direction d) { setEdge(d, true); } public void clearEdge(Direction d) { setEdge(d, false); } public int getNumberOfWalls() { return (wallN?1:0)+(wallE?1:0)+(wallS?1:0)+(wallW?1:0); } public boolean equals(Object obj) { if (! (obj instanceof Cell)) return false; Cell c = (Cell) obj; return c.row == row && c.col == col; } }