示例#1
0
    public void CreateDenseMaze(csDungeon dungeon)
    {
        Vector2 currentLocation = dungeon.PickRandomCellAndFlagItAsVisited();

        csDungeonCell.DirectionType previousDirection = csDungeonCell.DirectionType.North;

        while (!dungeon.AllCellsAreVisited)
        {
            csDirectionPicker directionPicker = new csDirectionPicker();
            directionPicker.Constructor(previousDirection, changeDirectionModifier);
            csDungeonCell.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 csDirectionPicker();
                    directionPicker.Constructor(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(csDungeon dungeon)
    {
        foreach (Vector2 deadEndLocation in dungeon.DeadEndCellLocations)
        {
            if (ShouldRemoveDeadend())
            {
                Vector2 currentLocation = deadEndLocation;

                do
                {
                    // Initialize the direction picker not to select the dead-end corridor direction
                    csDirectionPicker directionPicker = new csDirectionPicker();
                    directionPicker.Constructor(dungeon[currentLocation].CalculateDeadEndCorridorDirection(), 100);
                    csDungeonCell.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.
            }
        }
    }