/// <param name="sparsenessFactor">Percentage of the map (0.0 to 1.0) turned to walls.</param> private void SparsifyMaze(LabyrinthDungeon map, double sparsenessFactor) { // Calculate the number of cells to remove as a percentage of the total number of cells in the map: var noOfDeadEndCellsToRemove = (int)System.Math.Ceiling(sparsenessFactor * map.Rows * map.Columns); var points = map.DeadEndCellLocations; for (var i = 0; i < noOfDeadEndCellsToRemove; i++) { if (points.Count == 0) { // check if there is another item in our enumerator points = map.DeadEndCellLocations; // get a new list if (points.Count == 0) { break; // no new items exist so break out of loop } } var index = _random.Next(0, points.Count); var point = points[index]; points.RemoveAt(index); if (map[point].IsDeadEnd) { // make sure the status of the cell hasn't change map.CreateWall(point, map[point].CalculateDeadEndCorridorDirection()); } } }
private void PlaceRoom(Vector2I location, LabyrinthDungeon dungeon, Room room) { // Offset the room origin to the new location. room.SetLocation(location); // Loop for each cell in the room for (var row = 0; row < room.Rows; row++) { for (var column = 0; column < room.Columns; column++) { // Translate the room cell location to its location in the dungeon. var dungeonLocation = location + new Vector2I(column, row); dungeon[dungeonLocation].NorthSide = room[row, column].NorthSide; dungeon[dungeonLocation].SouthSide = room[row, column].SouthSide; dungeon[dungeonLocation].WestSide = room[row, column].WestSide; dungeon[dungeonLocation].EastSide = room[row, column].EastSide; // TODO: This part may be unnecessary. // Create room walls on map (either side of the wall) if ((column == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.West))) { dungeon.CreateWall(dungeonLocation, Direction.West); } if ((column == room.Columns - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.East))) { dungeon.CreateWall(dungeonLocation, Direction.East); } if ((row == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.North))) { dungeon.CreateWall(dungeonLocation, Direction.North); } if ((row == room.Rows - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.South))) { dungeon.CreateWall(dungeonLocation, Direction.South); } } } dungeon.Rooms.Add(room); }