Пример #1
0
        public void PlaceDoor_InRectangularTestRooms(StandardTestRoom testRoom)
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator();

            void SetupStandardRoom()
            {
                fakeRandomNumbers.PopulateRandomForTestRoom(testRoom)
                ;
            }

            void SetupDoorForStandardRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(0, 0)               // Door placement, top left corner, will try again
                .AddCoordinates(9, 0)               // Door placement, btm left corner, will try again
                .AddCoordinates(9, 5)               // Door placement, btm right corner, will try again
                .AddCoordinates(0, 5)               // Door placement, top right corner, will try again
                .AddCoordinates(0, 3)               // Door placement, vertical wall, will try again
                .AddCoordinates(4, 0)               // Door placement, horizontal wall, will try again
                .AddCoordinates(4, 3)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.North) // direction to walk to find a wall and place a door
                .AddCoordinates(4, 3)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.East)  // direction to walk to find a wall and place a door
                .AddCoordinates(4, 3)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.South) // direction to walk to find a wall and place a door
                .AddCoordinates(4, 3)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.West)  // direction to walk to find a wall and place a door
                ;
            }

            var registry = new DispatchRegistry();

            SetupStandardRoom();
            SetupDoorForStandardRoom();

            var fakeLogger = new FakeLogger(_output);

            var builder = new RoomBuilder(fakeRandomNumbers, fakeLogger, registry);

            var mazeDescriptor = FakeMazeDescriptorBuilder.MazeRoomsWithTwoBlocks();
            var detail         = mazeDescriptor[1];
            var room           = builder.BuildRoom(detail.BlocksPerRoom, detail.TilesPerBlock);

            room = room.AddDoor(1);
            room = room.AddDoor(2);
            room = room.AddDoor(3);
            room = room.AddDoor(4);

            var expected = GetExpectationForTestRoom(testRoom);
            var actual   = room.ToString();

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actual);
            _output.WriteLine('='.ToPaddedString(10));

            Assert.Equal(expected, actual);
        }
Пример #2
0
        public void PlaceTwoRooms_WherePlacingTheSecondRoomCausesMazeToGrow()
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator();

            void SetupTwoRooms()
            {
                fakeRandomNumbers
                .PopulateRandomForRoomCount(2)
                .PopulateRandomForTestRoom(StandardTestRoom.Second)
                .PopulateRandomForTestRoom(StandardTestRoom.Second)
                ;
            }

            void SetupDoorForFirstRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(0, 0)               // Door placement, should be empty tile to walk from, but it is a wall, top left corner
                .AddCoordinates(3, 3)               // Door placement, empty tile to start walk from
                .AddDirection(Compass8Points.South) // direction to walk to find a wall and place a door
                ;
            }

            void SetupDoorForSecondRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(5, 9)               // Door placement, should be empty tile to walk from, but it is a wall, bottom right corner
                .AddCoordinates(4, 8)               // Door placement, empty tile to start walk from
                .AddDirection(Compass8Points.North) // direction to walk to find a wall and place a door
                ;
            }

            void SetupCoordinatesForPlacingFirstRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(3, 3)     // should succeed
                ;
            }

            void SetupCoordinatesForPlacingSecondRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(17, 15)     // placing room outside of maze
                .AddCoordinates(17, 15)     // placing room outside of maze
                .AddCoordinates(17, 15)     // placing room outside of maze, show grow after third attempt
                .AddCoordinates(17, 15)     // placing room outside of old maze, now inside new maze so succeeds
                ;
            }

            var registry   = new DispatchRegistry();
            var dispatcher = new Dispatcher(registry);

            SetupTwoRooms();
            SetupDoorForFirstRoom();
            SetupDoorForSecondRoom();
            SetupCoordinatesForPlacingFirstRoom();
            SetupCoordinatesForPlacingSecondRoom();

            var fakeLogger     = new FakeLogger(_output);
            var mazeDescriptor = FakeMazeDescriptorBuilder.MazeRoomsWithTwoBlocks();

            var builder = new LevelBuilder(fakeRandomNumbers, mazeDescriptor, fakeLogger, dispatcher, registry);

            builder.Build(1, connectTunnels: false);

            var expected     = GetExpectation(2);
            var actual       = (Maze)registry.GetDispatchee("Maze1");
            var actualString = actual.ToString();

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actualString);
            _output.WriteLine('='.ToPaddedString(10));

            Assert.Equal(expected, actualString);
        }
Пример #3
0
        public void PlaceTwoRooms_WhereFirstAndSecondDoNotOverlap()
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator();

            void SetupTwoRooms()
            {
                fakeRandomNumbers
                .PopulateRandomForRoomCount(2)
                .PopulateRandomForTestRoom(StandardTestRoom.First)
                .PopulateRandomForTestRoom(StandardTestRoom.First)
                ;
            }

            void SetupDoors()
            {
                fakeRandomNumbers
                .AddCoordinates(2, 2)              // Door placement, empty tile to start walk from
                .AddDirection(Compass8Points.West) // direction to walk to find a wall and place a door
                .AddCoordinates(3, 3)              // Door placement, empty tile to start walk from
                .AddDirection(Compass8Points.East) // direction to walk to find a wall and place a door
                ;
            }

            void SetupCoordinatesForPlacingFirstRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(1, 1)     // too close to edge of maze, should fail
                .AddCoordinates(2, 2)     // too close to edge of maze, should fail
                .AddCoordinates(3, 3)     // should succeed
                ;
            }

            void SetupCoordinatesForPlacingSecondRoom()
            {
                fakeRandomNumbers
                .AddCoordinates(4, 4)     // overlaps first so should fail
                .AddCoordinates(6, 6)     // too near first so should fail
                .AddCoordinates(17, 10)   // does not overlap and not close so should succeed
                ;
            }

            var registry   = new DispatchRegistry();
            var dispatcher = new Dispatcher(registry);

            SetupTwoRooms();
            SetupDoors();
            SetupCoordinatesForPlacingFirstRoom();
            SetupCoordinatesForPlacingSecondRoom();

            var fakeLogger     = new FakeLogger(_output);
            var mazeDescriptor = FakeMazeDescriptorBuilder.MazeRoomsWithTwoBlocks();

            var builder = new LevelBuilder(fakeRandomNumbers, mazeDescriptor, fakeLogger, dispatcher, registry);

            builder.Build(1, connectTunnels: false);

            var expected     = GetExpectation(1);
            var actual       = (Maze)registry.GetDispatchee("Maze1");
            var actualString = actual.ToString();

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actualString);
            _output.WriteLine('='.ToPaddedString(10));

            Assert.Equal(expected, actualString);
        }
Пример #4
0
        public void PlaceDoor_InLShapedTestRooms()
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator();

            void SetupStandardRoom()
            {
                fakeRandomNumbers.PopulateRandomForTestRoom(StandardTestRoom.Third)
                ;
            }

            void SetupDoorForStandardRoom()
            {
                fakeRandomNumbers
                // find walls
                .AddCoordinates(0, 0)               // Door placement, top left corner, will try again
                .AddCoordinates(0, 3)               // Door placement, top row, horizontal wall, will try again
                .AddCoordinates(0, 5)               // Door placement, top right corner of L, will try again
                .AddCoordinates(4, 5)               // Door placement, middle corner of L, will try again
                .AddCoordinates(4, 6)               // Door placement, horizontal wall in middle, will try again
                .AddCoordinates(4, 9)               // Door placement, far right corner of L, will try again
                .AddCoordinates(6, 9)               // Door placement, horizontal wall at far right L, will try again
                .AddCoordinates(9, 9)               // Door placement, bottom right corner of L, will try again
                .AddCoordinates(9, 6)               // Door placement, horizontal wall at bottom L, will try again
                .AddCoordinates(9, 0)               // Door placement, bottom left corner of L, will try again
                .AddCoordinates(9, 5)               // Door placement, horizontal wall at far left of L, will try again
                                                    //find rocks
                .AddCoordinates(0, 6)               // Door placement, rock outside room, will try again
                .AddCoordinates(0, 9)               // Door placement, rock edge of space, will try again
                .AddCoordinates(1, 8)               // Door placement, rock surrounded by other rocks, will try again
                                                    // find corner of L, starting from valid tile
                .AddCoordinates(4, 4)               // Door placement, valid tile
                .AddDirection(Compass8Points.East)  // direction to walk to find a wall and place a door, will find corner and try again
                .AddCoordinates(5, 5)               // Door placement, valid tile
                .AddDirection(Compass8Points.North) // // direction to walk to find a wall and place a door, will find corner and try again
                                                    // place doors
                .AddCoordinates(4, 4)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.North) // direction to walk to find a wall and place a door
                .AddCoordinates(5, 5)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.East)  // direction to walk to find a wall and place a door
                .AddCoordinates(5, 5)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.South) // direction to walk to find a wall and place a door
                .AddCoordinates(4, 4)               // Door placement, vertical wall to start walk from
                .AddDirection(Compass8Points.West)  // direction to walk to find a wall and place a door
                ;
            }

            var registry = new DispatchRegistry();

            SetupStandardRoom();
            SetupDoorForStandardRoom();

            var fakeLogger = new FakeLogger(_output);

            var builder = new RoomBuilder(fakeRandomNumbers, fakeLogger, registry);

            var mazeDescriptor = FakeMazeDescriptorBuilder.MazeRoomsWithThreeBlocks();
            var detail         = mazeDescriptor[1];
            var room           = builder.BuildRoom(detail.BlocksPerRoom, detail.TilesPerBlock);

            room = room.AddDoor(1);
            room = room.AddDoor(2);
            room = room.AddDoor(3);
            room = room.AddDoor(4);

            var expected = GetExpectationForTestRoom(StandardTestRoom.Third);
            var actual   = room.ToString();

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actual);
            _output.WriteLine('='.ToPaddedString(10));

            Assert.Equal(expected, actual);
        }