private void SplitVertically(MazeRoom mazeRoom, Random rnd) { // height = 9 // possibles = 3, 5, 7 = 3+0, 3+2, 3+4 // 3 + (rand(3) * 2) // rand((9-3)/2 = 6/2 = 3) // height = 11 // possibles = 3, 5, 7, 9 = 3+0, 3+2, 3+4, 3+6 // 3 + (rand(4) * 2) // rand((11-3)/2 = 8/2 = 4) // int randomMax = (mazeRoom.height - 3) / 2; // int randomInt = rnd.Next(randomMax) * 2; // int randomHeight = 3 + randomInt; List <int> possibleHeights = mazeRoom.getAvailableVerticalSplits(); int randomIndex = rnd.Next(possibleHeights.Count); int randomHeight = possibleHeights[randomIndex] + 1; Console.WriteLine("splitting vertically at h=" + randomHeight); int randomX = (rnd.Next((mazeRoom.width - 1) / 2) * 2) + 1; Point2D newWallExit1 = new Point2D(randomX, randomHeight - 1); Console.WriteLine("newWallExit1: " + newWallExit1); List <Point2D> newExits1 = mazeRoom.FindMatchingExits(mazeRoom.width, randomHeight, new Point2D(0, 0)); newExits1.Add(newWallExit1); MazeRoom subMaze1 = new MazeRoom(new Maze(mazeRoom.width, randomHeight), newExits1); // Console.WriteLine("Sub Maze Exit At: "+splitExit1.ToString()); GenerateMazeSections(subMaze1, rnd); // AddOuterWalls(subMaze1); MergeMazeWalls(mazeRoom, subMaze1, new Point2D(0, 0)); Point2D newWallExit2 = new Point2D(randomX, 0); Console.WriteLine("newWallExit2: " + newWallExit2); List <Point2D> newExits2 = mazeRoom.FindMatchingExits( mazeRoom.width, mazeRoom.height - randomHeight, new Point2D(0, randomHeight - 1)); newExits2.Add(newWallExit2); MazeRoom subMaze2 = new MazeRoom( new Maze(mazeRoom.width, mazeRoom.height - randomHeight + 1), newExits2); GenerateMazeSections(subMaze2, rnd); // AddOuterWalls(subMaze2); MergeMazeWalls(mazeRoom, subMaze2, new Point2D(0, randomHeight - 1)); }
private int CanBeSubdivided(MazeRoom mazeRoom) { List <int> horizontalSplits = mazeRoom.getAvailableHorizontalSplits(); List <int> verticalSplits = mazeRoom.getAvailableVerticalSplits(); bool horizontally = horizontalSplits.Count > 0; bool vertically = verticalSplits.Count > 0; if (vertically & horizontally) { return(SPLITTABLE_BOTH); } if (vertically) { return(SPLITTABLE_VERTICALLY); } if (horizontally) { return(SPLITTABLE_HORIZONTALLY); } return(SPLITTABLE_NONE); }