public void PlaceDoors(csDungeon dungeon) { foreach (csDungeonRoom room in dungeon.Rooms) { bool hasNorthDoor = false; bool hasSouthDoor = false; bool hasWestDoor = false; bool hasEastDoor = false; foreach (Vector2 cellLocation in room.CellLocations) { // Translate the room cell location to its location in the dungeon Vector2 dungeonLocation = new Vector2(room.Bounds.x + cellLocation.x, room.Bounds.y + cellLocation.y); // Check if we are on the west boundary of our room // and if there is a corridor to the west if ((cellLocation.x == 0) && (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, csDungeonCell.DirectionType.West)) && (!hasWestDoor)) { dungeon.CreateDoor(dungeonLocation, csDungeonCell.DirectionType.West); hasWestDoor = true; } // Check if we are on the east boundary of our room // and if there is a corridor to the east if ((cellLocation.x == room.Width - 1) && (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, csDungeonCell.DirectionType.East)) && (!hasEastDoor)) { dungeon.CreateDoor(dungeonLocation, csDungeonCell.DirectionType.East); hasEastDoor = true; } // Check if we are on the north boundary of our room // and if there is a corridor to the north if ((cellLocation.y == 0) && (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, csDungeonCell.DirectionType.North)) && (!hasNorthDoor)) { dungeon.CreateDoor(dungeonLocation, csDungeonCell.DirectionType.North); hasNorthDoor = true; } // Check if we are on the south boundary of our room // and if there is a corridor to the south if ((cellLocation.y == room.Height - 1) && (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, csDungeonCell.DirectionType.South)) && (!hasSouthDoor)) { dungeon.CreateDoor(dungeonLocation, csDungeonCell.DirectionType.South); hasSouthDoor = true; } } } }