コード例 #1
0
        public void CreateDenseMaze(Dungeon dungeon)
        {
            Point         currentLocation   = dungeon.PickRandomCellAndFlagItAsVisited();
            DirectionType previousDirection = DirectionType.North;

            while (!dungeon.AllCellsAreVisited)
            {
                DirectionPicker directionPicker = new DirectionPicker(previousDirection, changeDirectionModifier);
                DirectionType   direction       = directionPicker.GetNextDirection();

                while (!dungeon.HasAdjacentCellInDirection(currentLocation, direction) || dungeon.AdjacentCellInDirectionIsVisited(currentLocation, direction))
                {
                    if (directionPicker.HasNextDirection)
                    {
                        direction = directionPicker.GetNextDirection();
                    }
                    else
                    {
                        currentLocation = dungeon.GetRandomVisitedCell(currentLocation);                   // Get a new previously visited location
                        directionPicker = new DirectionPicker(previousDirection, changeDirectionModifier); // Reset the direction picker
                        direction       = directionPicker.GetNextDirection();                              // Get a new direction
                    }
                }

                currentLocation = dungeon.CreateCorridor(currentLocation, direction);
                dungeon.FlagCellAsVisited(currentLocation);
                previousDirection = direction;
            }
        }
コード例 #2
0
        public void RemoveDeadEnds(Dungeon dungeon)
        {
            foreach (Point deadEndLocation in dungeon.DeadEndCellLocations)
            {
                if (ShouldRemoveDeadend())
                {
                    Point currentLocation = deadEndLocation;

                    do
                    {
                        // Initialize the direction picker not to select the dead-end corridor direction
                        DirectionPicker directionPicker = new DirectionPicker(dungeon[currentLocation].CalculateDeadEndCorridorDirection(), 100);
                        DirectionType   direction       = directionPicker.GetNextDirection();

                        while (!dungeon.HasAdjacentCellInDirection(currentLocation, direction))
                        {
                            if (directionPicker.HasNextDirection)
                            {
                                direction = directionPicker.GetNextDirection();
                            }
                            else
                            {
                                throw new InvalidOperationException("This should not happen");
                            }
                        }
                        // Create a corridor in the selected direction
                        currentLocation = dungeon.CreateCorridor(currentLocation, direction);
                    } while (dungeon[currentLocation].IsDeadEnd); // Stop when you intersect an existing corridor.
                }
            }
        }