/// <summary> /// Dig a rectangle-sized room into the coordinates given. It's assumed the whole space that's going to be /// dug and the surrounding area (1 tile wide) consist of walls /// </summary> /// <param name="roomX"></param> /// <param name="roomY"></param> /// <param name="roomWidth"></param> /// <param name="roomHeight"></param> /// <param name="possibleDoorways"></param> private void DigRoom(int roomX, int roomY, int roomWidth, int roomHeight, List <Point> possibleDoorways, GameEngine engine) { for (int x = roomX; x < roomX + roomWidth; x++) { for (int y = roomY; y < roomY + roomHeight; y++) { Map[x, y] = TileFactory.CreateDungeonFloor(engine); } } }
/// <summary> /// Create a hallway from a doorway then expand the hallway sideways in order to form another /// room. The room will not be dug unless it is able to grow from the hallway /// </summary> /// <param name="door"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> private bool GrowRoom(Point door, int width, int height, GameEngine engine) { // The coordinates to build the room if it's valid List <Point> Room = new List <Point>(); Room.Add(new Point(door.X, door.Y)); // Find which way to grow horizontally int dx = 0; if (Map[door.X + 1, door.Y].Name.Equals("Dungeon Floor")) { dx = -1; } else if (Map[door.X - 1, door.Y].Name.Equals("Dungeon Floor")) { dx = 1; } // Find which way to grow vertically int dy = 0; if (Map[door.X, door.Y + 1].Name.Equals("Dungeon Floor")) { dy = -1; } else if (Map[door.X, door.Y - 1].Name.Equals("Dungeon Floor")) { dy = 1; } // Build horizontally if (dx != 0) { // Check if good to build the room bool GoodToBuild = true; for (int i = 1; i < width; i++) { int newX = door.X + (i * dx); if (!InBounds(newX, door.Y)) { GoodToBuild = false; } else if (!Map[newX, door.Y].Name.Equals("Dungeon Wall")) { GoodToBuild = false; } } // Build the corridor from the doorway if (GoodToBuild) { for (int i = 1; i < width; i++) { int newX = door.X + (i * dx); if (InBounds(newX, door.Y) && Map[newX, door.Y].Name.Equals("Dungeon Wall")) { Room.Add(new Point(newX, door.Y)); } else { return(false); } } } else { return(false); } // Grow the rest of the room from the corridor for (int i = 1; i < height / 2; i++) { for (int n = 1; n < width; n++) { int x = door.X + (n * dx); int yTop = door.Y + i; int yBot = door.Y - i; if (InBounds(x, yTop) && InBounds(x, yBot)) { if (Map[x, yTop].Name.Equals("Dungeon Wall") && Map[x, yBot].Name.Equals("Dungeon Wall")) { Room.Add(new Point(x, yTop)); Room.Add(new Point(x, yBot)); } else { return(false); } } else { return(false); } } } } else if (dy != 0) { // Check if good to build the room bool GoodToBuild = true; for (int i = 1; i < height; i++) { int newY = door.Y + (i * dy); if (!InBounds(door.X, newY)) { GoodToBuild = false; } else if (!Map[door.X, newY].Name.Equals("Dungeon Wall")) { GoodToBuild = false; } } // Build the first bit of the room if (GoodToBuild) { for (int i = 1; i < height; i++) { int newY = door.Y + (i * dy); if (InBounds(door.X, newY) && Map[door.X, newY].Name.Equals("Dungeon Wall")) { Room.Add(new Point(door.X, newY)); } else { return(false); } } } else { return(false); } // Grow the rest of the room from the corridor build for (int i = 1; i < width / 2; i++) { for (int n = 1; n < height; n++) { int xRight = door.X + i; int xLeft = door.X - i; int y = door.Y + (n * dy); if (InBounds(xRight, y) && InBounds(xLeft, y)) { if (Map[xRight, y].Name.Equals("Dungeon Wall") && Map[xLeft, y].Name.Equals("Dungeon Wall")) { Room.Add(new Point(xRight, y)); Room.Add(new Point(xLeft, y)); } else { return(false); } } else { return(false); } } } } // Draw the room foreach (Point roomTile in Room) { Map[roomTile.X, roomTile.Y] = TileFactory.CreateDungeonFloor(engine); } return(true); }