Beispiel #1
0
        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));
        }
Beispiel #2
0
        private void SplitHorizontally(MazeRoom mazeRoom, Random rnd)
        {
            List <int> possibleWidths = mazeRoom.getAvailableHorizontalSplits();
            int        randomIndex    = rnd.Next(possibleWidths.Count);
            int        randomWidth    = possibleWidths[randomIndex] + 1;

            Console.WriteLine("splitting vertically at w=" + randomWidth);

            int randomY = (rnd.Next((mazeRoom.height - 1) / 2) * 2) + 1;

            Point2D newWallExit1 = new Point2D(randomWidth - 1, randomY);

            Console.WriteLine("newWallExit1: " + newWallExit1);
            List <Point2D> newExits1 = mazeRoom.FindMatchingExits(randomWidth, mazeRoom.height, new Point2D(0, 0));

            newExits1.Add(newWallExit1);

            MazeRoom subMaze1 = new MazeRoom(new Maze(randomWidth, mazeRoom.height), newExits1);

            GenerateMazeSections(subMaze1, rnd);
            // AddOuterWalls(subMaze1);
            MergeMazeWalls(mazeRoom, subMaze1, new Point2D(0, 0));

            Point2D newWallExit2 = new Point2D(0, randomY);

            Console.WriteLine("newWallExit2: " + newWallExit2);
            List <Point2D> newExits2 = mazeRoom.FindMatchingExits(
                mazeRoom.width - randomWidth,
                mazeRoom.height,
                new Point2D(randomWidth - 1, 0));

            newExits2.Add(newWallExit2);

            MazeRoom subMaze2 = new MazeRoom(
                new Maze(mazeRoom.width - randomWidth + 1, mazeRoom.height), newExits2);

            GenerateMazeSections(subMaze2, rnd);
            // AddOuterWalls(subMaze2);
            MergeMazeWalls(mazeRoom, subMaze2, new Point2D(randomWidth - 1, 0));
        }