예제 #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);
        }
        internal static int GetNumBlocks(StandardTestRoom testRoom)
        {
            switch (testRoom)
            {
            case StandardTestRoom.First:
            case StandardTestRoom.Second: return(2);

            case StandardTestRoom.Third:
            case StandardTestRoom.Fourth:
            case StandardTestRoom.Fifth:
            case StandardTestRoom.Sixth:
                return(3);

            default: throw new ArgumentException($"Didn't have Generator for [{testRoom}]");
            }
        }
예제 #3
0
        private string GetExpectationForTestRoom(StandardTestRoom room)
        {
            switch (room)
            {
            case StandardTestRoom.First: return
                    (@" |012345
--------
0|╔══1═╗
1|║    ║
2|║    ║
3|║    ║
4|4    2
5|║    ║
6|║    ║
7|║    ║
8|║    ║
9|╚══3═╝");

            case StandardTestRoom.Second: return
                    (@" |0123456789
------------
0|╔══1═════╗
1|║        ║
2|║        ║
3|║        ║
4|4        2
5|╚══3═════╝");

            case StandardTestRoom.Third: return
                    (@" |0123456789
------------
0|╔═══1╗████
1|║    ║████
2|║    ║████
3|║    ║████
4|4    ╚═══╗
5|║        2
6|║        ║
7|║        ║
8|║        ║
9|╚════3═══╝");
            }

            throw new ArgumentException($"No expectation for test room [{room}]");
        }
        public void BuildRoom_ShouldBuildARoom_WithWalls(StandardTestRoom testRoom)
        {
            var fakeRandomNumbers = new FakeRandomNumberGenerator().PopulateRandomForTestRoom(testRoom);
            var registry          = new DispatchRegistry();
            var builder           = new RoomBuilder(fakeRandomNumbers, new FakeLogger(_output), registry);

            var room   = builder.BuildRoom(GetNumBlocks(testRoom), 4);
            var actual = room.ToString();

            var expected = StandardTestRooms.GetExpectation(testRoom);

            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine("Test Room " + testRoom);
            _output.WriteLine(expected);
            _output.WriteLine('='.ToPaddedString(10));
            _output.WriteLine(actual);

            Assert.Equal(expected, actual);
        }
        internal static string GetExpectation(StandardTestRoom testRoom)
        {
            switch (testRoom)
            {
            case StandardTestRoom.First:
                return(" |012345" + Environment.NewLine +
                       "--------" + Environment.NewLine +
                       "0|╔════╗" + Environment.NewLine +
                       "1|║    ║" + Environment.NewLine +
                       "2|║    ║" + Environment.NewLine +
                       "3|║    ║" + Environment.NewLine +
                       "4|║    ║" + Environment.NewLine +
                       "5|║    ║" + Environment.NewLine +
                       "6|║    ║" + Environment.NewLine +
                       "7|║    ║" + Environment.NewLine +
                       "8|║    ║" + Environment.NewLine +
                       "9|╚════╝");

            case StandardTestRoom.Second:
                return(" |0123456789" + Environment.NewLine +
                       "------------" + Environment.NewLine +
                       "0|╔════════╗" + Environment.NewLine +
                       "1|║        ║" + Environment.NewLine +
                       "2|║        ║" + Environment.NewLine +
                       "3|║        ║" + Environment.NewLine +
                       "4|║        ║" + Environment.NewLine +
                       "5|╚════════╝");

            case StandardTestRoom.Third:
                return(" |0123456789" + Environment.NewLine +
                       "------------" + Environment.NewLine +
                       "0|╔════╗████" + Environment.NewLine +
                       "1|║    ║████" + Environment.NewLine +
                       "2|║    ║████" + Environment.NewLine +
                       "3|║    ║████" + Environment.NewLine +
                       "4|║    ╚═══╗" + Environment.NewLine +
                       "5|║        ║" + Environment.NewLine +
                       "6|║        ║" + Environment.NewLine +
                       "7|║        ║" + Environment.NewLine +
                       "8|║        ║" + Environment.NewLine +
                       "9|╚════════╝");

            case StandardTestRoom.Fourth:
                return(" |0123456789" + Environment.NewLine +
                       "------------" + Environment.NewLine +
                       "0|╔════════╗" + Environment.NewLine +
                       "1|║        ║" + Environment.NewLine +
                       "2|║        ║" + Environment.NewLine +
                       "3|║        ║" + Environment.NewLine +
                       "4|║        ║" + Environment.NewLine +
                       "5|╚═══╗    ║" + Environment.NewLine +
                       "6|████║    ║" + Environment.NewLine +
                       "7|████║    ║" + Environment.NewLine +
                       "8|████║    ║" + Environment.NewLine +
                       "9|████╚════╝");

            case StandardTestRoom.Fifth:
                return(" |0123456789" + Environment.NewLine +
                       "------------" + Environment.NewLine +
                       "0|╔════════╗" + Environment.NewLine +
                       "1|║        ║" + Environment.NewLine +
                       "2|║        ║" + Environment.NewLine +
                       "3|║        ║" + Environment.NewLine +
                       "4|║        ║" + Environment.NewLine +
                       "5|║    ╔═══╝" + Environment.NewLine +
                       "6|║    ║████" + Environment.NewLine +
                       "7|║    ║████" + Environment.NewLine +
                       "8|║    ║████" + Environment.NewLine +
                       "9|╚════╝████");

            case StandardTestRoom.Sixth:
                return(" |0123456789" + Environment.NewLine +
                       "------------" + Environment.NewLine +
                       "0|████╔════╗" + Environment.NewLine +
                       "1|████║    ║" + Environment.NewLine +
                       "2|████║    ║" + Environment.NewLine +
                       "3|████║    ║" + Environment.NewLine +
                       "4|╔═══╝    ║" + Environment.NewLine +
                       "5|║        ║" + Environment.NewLine +
                       "6|║        ║" + Environment.NewLine +
                       "7|║        ║" + Environment.NewLine +
                       "8|║        ║" + Environment.NewLine +
                       "9|╚════════╝");

            default: throw new ArgumentException($"Didn't have Generator for [{testRoom}]");
            }
        }
        internal static FakeRandomNumberGenerator PopulateRandomForTestRoom(this FakeRandomNumberGenerator generator, StandardTestRoom testRoom)
        {
            switch (testRoom)
            {
            case StandardTestRoom.First:
                generator.PopulateEnum(Compass4Points.South);
                generator.PopulateDice(0, 1);
                break;

            case StandardTestRoom.Second:
                generator.PopulateEnum(Compass4Points.West);
                generator.PopulateDice(0, 1);
                break;

            case StandardTestRoom.Third:
                generator.PopulateEnum(Compass4Points.South, Compass4Points.East);
                generator.PopulateDice(0, 1);
                break;

            case StandardTestRoom.Fourth:
                generator.PopulateEnum(Compass4Points.East, Compass4Points.South);
                generator.PopulateDice(0, 1);
                break;

            case StandardTestRoom.Fifth:
                generator.PopulateEnum(Compass4Points.West, Compass4Points.South);
                generator.PopulateDice(0, 1);
                break;

            case StandardTestRoom.Sixth:
                generator.PopulateEnum(Compass4Points.South, Compass4Points.West);
                generator.PopulateDice(0, 1);
                break;

            default: throw new ArgumentException($"Didn't have Generator for [{testRoom}]");
            }

            return(generator);
        }