Esempio n. 1
0
        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);

                }
            }
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
        public void PlaceRoom(Point location, Room room, Dungeon dungeon)
        {
            room.SetLocation(location);

            for (int x = 0; x < room.Width; x++)
            {
                for (int y = 0; y < room.Height; y++)
                {
                    Point dungeonLocation = new Point(location.X + x, location.Y + y);
                    dungeon[dungeonLocation].NorthSide = room[x, y].NorthSide;
                    dungeon[dungeonLocation].SouthSide = room[x, y].SouthSide;
                    dungeon[dungeonLocation].EastSide = room[x, y].EastSide;
                    dungeon[dungeonLocation].WestSide = room[x, y].WestSide;

                    if ((x == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.DirectionType.West))) dungeon.CreateSide(dungeonLocation, Direction.DirectionType.West, Cell.Sidetype.Wall);
                    if ((x == room.Width - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.DirectionType.East))) dungeon.CreateSide(dungeonLocation, Direction.DirectionType.East, Cell.Sidetype.Wall);
                    if ((y == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.DirectionType.North))) dungeon.CreateSide(dungeonLocation, Direction.DirectionType.North, Cell.Sidetype.Wall);
                    if ((y == room.Height - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.DirectionType.South))) dungeon.CreateSide(dungeonLocation, Direction.DirectionType.South, Cell.Sidetype.Wall);
                }
            }

            dungeon.rooms.Add(room);
        }