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); }
public void SparsifyMaze(Dungeon dungeon, int sparsenessModifier) { int noOfDeadEndCellsToRemove = (int)Math.Ceiling((decimal)sparsenessModifier / 100 * (dungeon.Width * dungeon.Height)); IEnumerator<Point> enumerator = dungeon.FindDeadEnds.GetEnumerator(); for (int i = 0; i < noOfDeadEndCellsToRemove; i++) { if (!enumerator.MoveNext()) { enumerator = dungeon.FindDeadEnds.GetEnumerator(); if (!enumerator.MoveNext()) break; } Point point = enumerator.Current; dungeon.CreateSide(point, (Direction.DirectionType)dungeon.CalculateDeadEndCorridorDirection(point), Cell.Sidetype.Wall); } }