Exemple #1
0
        public void PlaceRoom(Point location, Room room, Dungeon dungeon)
        {
            // Offset the room origin to the new location
            room.SetLocation(location);

            // Loop for each cell in the room
            foreach (Point roomLocation in room.CellLocations)
            {
                // Translate the room cell location to its location in the dungeon
                Point dungeonLocation = new Point(location.X + roomLocation.X, location.Y + roomLocation.Y);
                dungeon[dungeonLocation].NorthSide = room[roomLocation].NorthSide;
                dungeon[dungeonLocation].SouthSide = room[roomLocation].SouthSide;
                dungeon[dungeonLocation].WestSide  = room[roomLocation].WestSide;
                dungeon[dungeonLocation].EastSide  = room[roomLocation].EastSide;

                // Create room walls on map (either side of the wall)
                if ((roomLocation.X == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, DirectionType.West)))
                {
                    dungeon.CreateWall(dungeonLocation, DirectionType.West);
                }
                if ((roomLocation.X == room.Width - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, DirectionType.East)))
                {
                    dungeon.CreateWall(dungeonLocation, DirectionType.East);
                }
                if ((roomLocation.Y == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, DirectionType.North)))
                {
                    dungeon.CreateWall(dungeonLocation, DirectionType.North);
                }
                if ((roomLocation.Y == room.Height - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, DirectionType.South)))
                {
                    dungeon.CreateWall(dungeonLocation, DirectionType.South);
                }
            }

            dungeon.AddRoom(room);
        }
        public void SparsifyMaze(Dungeon dungeon)
        {
            // Calculate the number of cells to remove as a percentage of the total number of cells in the dungeon
            int noOfDeadEndCellsToRemove = (int)Math.Ceiling(((decimal)sparsenessModifier / 100) * (dungeon.Width * dungeon.Height));

            IEnumerator <Point> enumerator = dungeon.DeadEndCellLocations.GetEnumerator();

            for (int i = 0; i < noOfDeadEndCellsToRemove; i++)
            {
                if (!enumerator.MoveNext())                                    // Check if there is another item in our enumerator
                {
                    enumerator = dungeon.DeadEndCellLocations.GetEnumerator(); // Get a new enumerator
                    if (!enumerator.MoveNext())
                    {
                        break;                         // No new items exist so break out of loop
                    }
                }

                Point point = enumerator.Current;
                dungeon.CreateWall(point, dungeon[point].CalculateDeadEndCorridorDirection());
                dungeon[point].IsCorridor = false;
            }
        }