Exemplo n.º 1
0
        public Dungeon Generate(int width, int height, int changeDirectionModifier, int sparesnessModifier)
        {
            Dungeon dungeon = new Dungeon(width, height);
            Point location = dungeon.PickRandomCellMarkVisited();
            Direction.DirectionType previousDirection = Direction.DirectionType.North;

            while (dungeon.visitedCells < dungeon.Height * dungeon.Width)
            {
                Direction DirectionPicker = new Direction(previousDirection, changeDirectionModifier);
                Direction.DirectionType direction = DirectionPicker.GetNextDirection();
                while (!dungeon.HasAdjacentCellInDirection(location, direction) || dungeon.AdjacentCellInDirectionVisited(location, direction))
                {
                    if (DirectionPicker.HasNextDirection)
                    {
                        direction = DirectionPicker.GetNextDirection();
                    }

                    else
                    {
                        location = dungeon.PickRandomVisitedCell(location);
                        DirectionPicker = new Direction(previousDirection, changeDirectionModifier);
                        direction = DirectionPicker.GetNextDirection();
                    }

                }

                location = dungeon.CreateCorridor(location, direction);
                dungeon.MarkCellsAsVisited(location);
                previousDirection = direction;
            }

            SparsifyMaze(dungeon, sparesnessModifier);
            RemoveDeadEnds(dungeon, 70);
            roomGenerator.GenerateRooms(dungeon);
            PlaceDoors(dungeon);
            return dungeon;
        }