public void KnockDownWall(Cell theCell) { // find adjacent wall int theWallToKnockDown = FindAdjacentWall(theCell); Walls[theWallToKnockDown] = 0; int oppositeWall = (theWallToKnockDown + 2) % 4; theCell.Walls[oppositeWall] = 0; }
public int FindAdjacentWall(Cell theCell) { if (theCell.Row == Row) { if (theCell.Column < Column) return 0; else return 2; } else // columns are the same { if (theCell.Row < Row) return 1; else return 3; } }
public void Generate() { while (VisitedCells < TotalCells) { ArrayList AdjacentCells = GetNeighborsWithWalls(CurrentCell); if (AdjacentCells.Count > 0) { int randomCell = Cell.TheRandom.Next(0, AdjacentCells.Count); Cell theCell = ((Cell)AdjacentCells[randomCell]); CurrentCell.KnockDownWall(theCell); CellStack.Push(CurrentCell); CurrentCell = theCell; VisitedCells++; } else { CurrentCell = (Cell)CellStack.Pop(); } } }
private ArrayList GetNeighborsWithWalls(Cell aCell) { ArrayList Neighbors = new ArrayList(); int count = 0; for (int countRow = -1; countRow <= 1; countRow++) for (int countCol = -1; countCol <= 1; countCol++) { if ((aCell.Row + countRow < kDimension) && (aCell.Column + countCol < kDimension) && (aCell.Row + countRow >= 0) && (aCell.Column + countCol >= 0) && ((countCol == 0) || (countRow == 0)) && (countRow != countCol) ) { if (Cells[aCell.Row + countRow, aCell.Column + countCol].HasAllWalls()) { Neighbors.Add(Cells[aCell.Row + countRow, aCell.Column + countCol]); } } } return Neighbors; }
public void Initialize() { Cells = new Cell[kDimension, kDimension]; TotalCells = kDimension * kDimension; for (int i = 0; i < kDimension; i++) for (int j = 0; j < kDimension; j++) { Cells[i, j] = new Cell(); Cells[i, j].Row = i; Cells[i, j].Column = j; } CurrentCell = Cells[0, 0]; VisitedCells = 1; CellStack.Clear(); }