Exemplo n.º 1
0
 public Enums.WallOrientation FindAdjacentWall(Cell cell)
 {
     if (cell.Row == Row)
     {
         return cell.Column < Column ? Enums.WallOrientation.North : Enums.WallOrientation.South;
     }
     return cell.Row < Row ? Enums.WallOrientation.East : Enums.WallOrientation.West;
 }
Exemplo n.º 2
0
        public void RemoveWall(Cell cell)
        {
            // Each cell has four walls so, effectively, we have double walls separating cells.
            // Let's bust them both down. First break this cell's wall and then the neighbor's.
            var wallToRemove = FindAdjacentWall(cell);
            this.Walls[(int) wallToRemove] = Enums.WallStates.Down;

            var secondWallToRemove = FindOppositeWall(wallToRemove);
            cell.Walls[(int) secondWallToRemove] = Enums.WallStates.Down;
        }
Exemplo n.º 3
0
        public ArrayList GetCellNeighborsWithWallsWorthBreaking(Cell cell)
        {
            var neighbors = new ArrayList();

            for (int countRow = -1; countRow <= 1; countRow++)
            {
                for (int countCol = -1; countCol <= 1; countCol++)
                {
                    if (InMazeBounds(countRow, countCol, cell) && IsUpDownLeftRightAndNotSelf(countRow, countCol))
                    {
                        // The cell is left, right, above or below the current cell. Does it have all of it's walls?
                        if (Cells[cell.Row + countRow, cell.Column + countCol].HasAllWalls())
                        {
                            neighbors.Add(Cells[cell.Row + countRow, cell.Column + countCol]);
                        }
                    }
                }
            }

            return neighbors;
        }
Exemplo n.º 4
0
        public ArrayList GetCellNeighborsWhichHaveNotBeenVisited(Cell cell)
        {
            var neighbors = new ArrayList();

            // Look in each direction which cell can turn
            // If no wall and adject wall hasn't been visited.
            for (int countRow = -1; countRow <= 1; countRow++)
            {
                for (int countCol = -1; countCol <= 1; countCol++)
                {
                    if (InMazeBounds(countRow, countCol, cell) && IsUpDownLeftRightAndNotSelf(countRow, countCol))
                    {
                        if (Cells[cell.Row + countRow, cell.Column + countCol].HasAllWalls())
                        {
                            neighbors.Add(Cells[cell.Row + countRow, cell.Column + countCol]);
                        }
                    }
                }
            }

            return neighbors;
        }
Exemplo n.º 5
0
        public void Initialize()
        {
            Cells = new Cell[Dimension,Dimension];

            for (int i = 0; i < Dimension; i++)
            {
                for (int j = 0; j < Dimension; j++)
                {
                    Cells[i, j] = new Cell(i, j);
                }
            }
        }
Exemplo n.º 6
0
 private bool InMazeBounds(int countRow, int countCol, Cell cell)
 {
     return (cell.Row + countRow < Dimension) &&
            (cell.Row + countRow >= 0) &&
            (cell.Column + countCol < Dimension) &&
            (cell.Column + countCol >= 0);
 }
Exemplo n.º 7
0
        private static void DrawCellWalls(Cell cell, Graphics g)
        {
            var fillPen = new Pen(Color.Blue);

            if (cell.Walls[(int)Enums.WallOrientation.North] == Enums.WallStates.Up)
                DrawWallNorth(cell, g, fillPen);

            if (cell.Walls[(int)Enums.WallOrientation.East] == Enums.WallStates.Up)
                DrawWallEast(cell, g, fillPen);

            if (cell.Walls[(int)Enums.WallOrientation.South] == Enums.WallStates.Up)
                DrawWallSouth(cell, g, fillPen);

            if (cell.Walls[(int)Enums.WallOrientation.West] == Enums.WallStates.Up)
                DrawWallWest(cell, g, fillPen);
        }
Exemplo n.º 8
0
 private static void DrawWallWest(Cell cell, Graphics g, Pen fillPen)
 {
     g.DrawLine(fillPen, (cell.Row + 1) * CellSize + CellPadding, cell.Column * CellSize + CellPadding,
                (cell.Row + 1) * CellSize + CellPadding, (cell.Column + 1) * CellSize + CellPadding);
 }