コード例 #1
0
ファイル: Generator.cs プロジェクト: kstrasse/RandomDungeon1
        public static void RemoveDeadEnds(Dungeon dungeon, int deadEndRemovalModifier)
        {
            foreach (Point deadEndLocation in dungeon.FindDeadEnds)
            {
                if (ShouldRemoveDeadend(deadEndRemovalModifier))
                {
                    Point currentLocation = deadEndLocation;

                    do
                    {
                        Direction directionPicker = new Direction((Direction.DirectionType)dungeon.CalculateDeadEndCorridorDirection(currentLocation), 100);
                        Direction.DirectionType direction = directionPicker.GetNextDirection();

                        while (!dungeon.HasAdjacentCellInDirection(currentLocation, direction))
                        {
                            if (directionPicker.HasNextDirection)
                                direction = directionPicker.GetNextDirection();
                            else
                                throw new InvalidOperationException("This should not happen");
                        }

                        currentLocation = dungeon.CreateCorridor(currentLocation, direction);
                    } while (dungeon[currentLocation].IsDeadEnd);

                }
            }
        }
コード例 #2
0
ファイル: Generator.cs プロジェクト: kstrasse/RandomDungeon1
        public void SparsifyMaze(Dungeon dungeon, int sparsenessModifier)
        {
            int noOfDeadEndCellsToRemove = (int)Math.Ceiling((decimal)sparsenessModifier / 100 * (dungeon.Width * dungeon.Height));
            IEnumerator<Point> enumerator = dungeon.FindDeadEnds.GetEnumerator();

            for (int i = 0; i < noOfDeadEndCellsToRemove; i++)
            {
                if (!enumerator.MoveNext())
                {
                    enumerator = dungeon.FindDeadEnds.GetEnumerator();
                    if (!enumerator.MoveNext()) break;
                }
                Point point = enumerator.Current;
                dungeon.CreateSide(point, (Direction.DirectionType)dungeon.CalculateDeadEndCorridorDirection(point), Cell.Sidetype.Wall);
            }
        }