public int CalculateRoomPlacementScore(Point location, Room room, Dungeon dungeon) { if (dungeon.bounds.Contains(new Rectangle(location, new Size(room.Width + 1, room.Height + 1)))) { int roomPlacementScore = 0; 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); if ((room.HasAdjacentCellInDirection(dungeonLocation, Direction.DirectionType.North) && dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.DirectionType.North, dungeon))) roomPlacementScore++; if ((room.HasAdjacentCellInDirection(dungeonLocation, Direction.DirectionType.South) && dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.DirectionType.South, dungeon))) roomPlacementScore++; if ((room.HasAdjacentCellInDirection(dungeonLocation, Direction.DirectionType.East) && dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.DirectionType.East, dungeon))) roomPlacementScore++; if ((room.HasAdjacentCellInDirection(dungeonLocation, Direction.DirectionType.West) && dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.DirectionType.West, dungeon))) roomPlacementScore++; if (dungeon[dungeonLocation].IsCorridor) roomPlacementScore += 3; foreach (Room dungeonRoom in dungeon.Rooms) if (dungeonRoom.bounds.Contains(dungeonLocation)) roomPlacementScore += 100; } } return roomPlacementScore; } else { return int.MaxValue; } }
//a public void PlaceDoors(Dungeon dungeon) { foreach (Room room in dungeon.Rooms) { bool hasNorthDoor = false; bool hasSouthDoor = false; bool hasWestDoor = false; bool hasEastDoor = false; foreach (Point cellLocation in room.CellLocations) { Point dungeonLocation = new Point(room.bounds.X + cellLocation.X, room.bounds.Y + cellLocation.Y); if ((cellLocation.X == 0) && (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.DirectionType.West, dungeon)) && (!hasWestDoor)) { dungeon.CreateDoor(dungeonLocation, Direction.DirectionType.West); hasWestDoor = true; } if ((cellLocation.X == room.Width - 1) && (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.DirectionType.East, dungeon)) && (!hasEastDoor)) { dungeon.CreateDoor(dungeonLocation, Direction.DirectionType.East); hasEastDoor = true; } if ((cellLocation.Y == 0) && (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.DirectionType.North, dungeon)) && (!hasNorthDoor)) { dungeon.CreateDoor(dungeonLocation, Direction.DirectionType.North); hasNorthDoor = true; } if ((cellLocation.Y == room.Height - 1) && (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.DirectionType.South, dungeon)) && (!hasSouthDoor)) { dungeon.CreateDoor(dungeonLocation, Direction.DirectionType.South); hasSouthDoor = true; } } } }