Esempio n. 1
0
        public void PlaceRoomsOnFloorIntrusiveHalls()
        {
            // place a ring of rooms connected by halls
            string[] inGrid =
            {
                "A.0",
                ". .",
                "A#B",
                ". .",
                "0.B",
            };

            TestGridFloorPlan gridPlan = TestGridFloorPlan.InitGridToContext(inGrid, 5, 5);

            for (int ii = 0; ii < gridPlan.RoomCount; ii++)
            {
                var gen = new TestFloorPlanGen(((TestGridRoomGen)gridPlan.GetRoom(ii)).Identifier)
                {
                    ProposedSize = new Loc(2, 2),
                };

                gridPlan.PublicArrayRooms[ii].RoomGen = gen;
            }

            gridPlan.PublicHHalls[0][1].SetGen(new TestFloorPlanGen('a'));

            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                gridPlan.Size,
                new Rect[] { new Rect(0, 0, 2, 2), new Rect(9, 15, 2, 2) },
                new Rect[] { new Rect(2, 1, 4, 10), new Rect(6, 6, 3, 10) },
                new Tuple <char, char>[] { Tuple.Create('A', 'a'), Tuple.Create('a', 'b'), Tuple.Create('b', 'B') });

            ((TestFloorPlanGen)compareFloorPlan.PublicHalls[1].RoomGen).Identifier = 'a';

            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            Moq.Language.ISetupSequentialResult <int> seq = testRand.SetupSequence(p => p.Next(4));
            seq = seq.Returns(0);
            seq = seq.Returns(3);
            seq = testRand.SetupSequence(p => p.Next(10));
            seq = seq.Returns(0);
            seq = seq.Returns(9);

            var floorPlan = new TestFloorPlan();

            floorPlan.InitSize(gridPlan.Size);

            Mock <IFloorPlanTestContext> mockMap = new Mock <IFloorPlanTestContext>(MockBehavior.Strict);

            mockMap.SetupGet(p => p.Rand).Returns(testRand.Object);
            mockMap.SetupGet(p => p.RoomPlan).Returns(floorPlan);

            gridPlan.PlaceRoomsOnFloor(mockMap.Object);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
Esempio n. 2
0
        public void PlaceRoomsOnFloorRing()
        {
            // place a ring of rooms connected by halls
            string[] inGrid =
            {
                "A#B",
                "# #",
                "D#C",
            };

            TestGridFloorPlan gridPlan = TestGridFloorPlan.InitGridToContext(inGrid, 5, 5);

            for (int ii = 0; ii < gridPlan.RoomCount; ii++)
            {
                var gen = new TestFloorPlanGen(((TestGridRoomGen)gridPlan.GetRoom(ii)).Identifier)
                {
                    ProposedSize = new Loc(5, 5),
                };
                gridPlan.PublicArrayRooms[ii].RoomGen = gen;
            }

            gridPlan.PublicVHalls[0][0].SetGen(new TestFloorPlanGen('a'));
            gridPlan.PublicVHalls[1][0].SetGen(new TestFloorPlanGen('b'));
            gridPlan.PublicHHalls[0][0].SetGen(new TestFloorPlanGen('c'));
            gridPlan.PublicHHalls[0][1].SetGen(new TestFloorPlanGen('d'));

            TestFloorPlan compareFloorPlan;
            {
                var links = new Tuple <char, char>[]
                {
                    Tuple.Create('A', 'a'),
                    Tuple.Create('a', 'D'),
                    Tuple.Create('B', 'b'),
                    Tuple.Create('b', 'C'),
                    Tuple.Create('A', 'c'),
                    Tuple.Create('c', 'B'),
                    Tuple.Create('D', 'd'),
                    Tuple.Create('d', 'C'),
                };
                compareFloorPlan = TestFloorPlan.InitFloorToContext(
                    gridPlan.Size,
                    new Rect[] { new Rect(0, 0, 5, 5), new Rect(6, 0, 5, 5), new Rect(6, 6, 5, 5), new Rect(0, 6, 5, 5) },
                    new Rect[] { new Rect(0, 5, 5, 1), new Rect(6, 5, 5, 1), new Rect(5, 0, 1, 5), new Rect(5, 6, 1, 5) },
                    links);
            }

            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            testRand.Setup(p => p.Next(It.IsAny <int>())).Returns(0);

            var floorPlan = new TestFloorPlan();

            floorPlan.InitSize(gridPlan.Size);

            Mock <IFloorPlanTestContext> mockMap = new Mock <IFloorPlanTestContext>(MockBehavior.Strict);

            mockMap.SetupGet(p => p.Rand).Returns(testRand.Object);
            mockMap.SetupGet(p => p.RoomPlan).Returns(floorPlan);

            gridPlan.PlaceRoomsOnFloor(mockMap.Object);

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }