Пример #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);
        }
Пример #2
0
        public void PlaceRoomsOnFloorDefault()
        {
            // place a line of rooms with one default
            string[] inGrid =
            {
                "A#B#C",
                ". . .",
                "0.0.0",
            };

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

            {
                var gen = new TestFloorPlanGen('A')
                {
                    ProposedSize = new Loc(5, 5)
                };
                gridPlan.PublicArrayRooms[0].RoomGen = gen;
            }

            {
                gridPlan.PublicArrayRooms[1].RoomGen    = new RoomGenDefault <IFloorPlanTestContext>();
                gridPlan.PublicArrayRooms[1].PreferHall = true;
            }

            {
                var gen = new TestFloorPlanGen('B')
                {
                    ProposedSize = new Loc(5, 5)
                };
                gridPlan.PublicArrayRooms[2].RoomGen = gen;
            }

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

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

            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);

            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(compareFloorPlan.RoomCount));
            for (int ii = 0; ii < floorPlan.RoomCount; ii++)
            {
                FloorRoomPlan plan        = floorPlan.PublicRooms[ii];
                FloorRoomPlan comparePlan = compareFloorPlan.PublicRooms[ii];
                Assert.That(plan.RoomGen, Is.EqualTo(comparePlan.RoomGen));
                Assert.That(plan.Adjacents, Is.EqualTo(comparePlan.Adjacents));
            }

            Assert.That(floorPlan.HallCount, Is.EqualTo(compareFloorPlan.HallCount));
            for (int ii = 0; ii < floorPlan.HallCount; ii++)
            {
                FloorHallPlan plan        = floorPlan.PublicHalls[ii];
                FloorHallPlan comparePlan = compareFloorPlan.PublicHalls[ii];
                if (ii != 0)
                {
                    Assert.That(plan.RoomGen, Is.EqualTo(comparePlan.RoomGen));
                }
                else
                {
                    // special case for the default
                    Assert.That(plan.RoomGen, Is.TypeOf <RoomGenDefault <IFloorPlanTestContext> >());
                    Assert.That(plan.RoomGen.Draw, Is.EqualTo(comparePlan.RoomGen.Draw));
                }

                Assert.That(plan.Adjacents, Is.EqualTo(comparePlan.Adjacents));
            }
        }
Пример #3
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);
        }