public void PlaceRoom(Vector2 location, csDungeonRoom room, csDungeon dungeon) { // Offset the room origin to the new location room.SetLocation(location); // Loop for each cell in the room foreach (Vector2 roomLocation in room.CellLocations) { // Translate the room cell location to its location in the dungeon Vector2 dungeonLocation = new Vector2(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, csDungeonCell.DirectionType.West))) { dungeon.CreateWall(dungeonLocation, csDungeonCell.DirectionType.West); } if ((roomLocation.x == room.Width - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, csDungeonCell.DirectionType.East))) { dungeon.CreateWall(dungeonLocation, csDungeonCell.DirectionType.East); } if ((roomLocation.y == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, csDungeonCell.DirectionType.North))) { dungeon.CreateWall(dungeonLocation, csDungeonCell.DirectionType.North); } if ((roomLocation.y == room.Height - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, csDungeonCell.DirectionType.South))) { dungeon.CreateWall(dungeonLocation, csDungeonCell.DirectionType.South); } } dungeon.AddRoom(room); }
public void SparsifyMaze(csDungeon 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(((double)sparsenessModifier / 100) * (dungeon.Width * dungeon.Height)); IEnumerator <Vector2> 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 } } Vector2 point = enumerator.Current; dungeon.CreateWall(point, dungeon[point].CalculateDeadEndCorridorDirection()); dungeon[point].IsCorridor = false; } }