示例#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
    void Generate()
    {
        roomBuilder.ClearAllTiles();
        // Run the algorithm.
        int[,] map = Walk();
        map        = Merge4(map);
        map        = Merge2(map);

        // Place a rectangle to represent each room.
        for (int y = 0; y < map.GetLength(1); y++)
        {
            for (int x = 0; x < map.GetLength(0); x++)
            {
                roomBuilder.BuildRoom(x, y, map);
            }
        }
    }
        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);
        }
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        DrawDefaultInspector();
        RoomBuilder builder = (RoomBuilder)target;

        if (GUILayout.Button("Build Walls"))
        {
            builder.BuildWalls();
        }
        if (GUILayout.Button("Build Room"))
        {
            builder.BuildRoom();
        }
        if (GUILayout.Button("Clear"))
        {
            builder.ClearWalls();
            builder.ClearCorners();
        }
    }
示例#5
0
    public virtual void BuildMaze()
    {
        ClearMaze();

        rootObject.transform.position = transform.position;

        rooms = new GameObject[numRoomsX * numRoomsZ];
        Vector3 offset = GetOffset();
        int     i      = 0;

        for (int x = 0; x < numRoomsX; x++)
        {
            //roomBuilder.walls[3] = roomBuilder.walls[2] = WallType.Wall;

            for (int z = 0; z < numRoomsZ; z++)
            {
                Vector3 spawnPoint = new Vector3(x, 1, z);
                spawnPoint.Scale(roomSize);
                spawnPoint += offset;

                if (x > 0)
                {
                    roomBuilder.walls[3] = roomBuilder.walls[1];
                }
                if (z > 0)
                {
                    roomBuilder.walls[2] = roomBuilder.walls[0];
                }

                ChoosePassage();

                roomBuilder.BuildRoom(rootObject.transform);
                rooms[i] = roomBuilder.rootObject;
                rooms[i].transform.position = spawnPoint;
                rooms[i].transform.SetParent(rootObject.transform);
                i++;
            }
            //rooms[i] = Instantiate(roomPrefabs[0], spawnPoint, Quaternion.identity);
            //rooms[i].transform.SetParent(transform);
        }
    }
示例#6
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);
        }
示例#7
0
 public void BuildFirstRoom()
 {
     currentRoom = RoomLookup[InitialRoomID];
     roomBuilder.BuildRoom(CurrentRoom, Vector2.left);
 }
 public void BuildRoom(RoomBlueprint roomBlueprint, Vector2 startingPoint, ObjectRotation roomRotation)
 {
     _roomBuilder.BuildRoom(roomBlueprint, _buildingTileBuilder, _buildingPlotBuilder, startingPoint, roomRotation);
 }