Ejemplo n.º 1
0
        public void PlaceRoomMultiAdjacent()
        {
            // the new room touches adjacents of two sides of the old room
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 6, 6), new Rect(3, 1, 2, 2), new Rect(1, 3, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C') });
            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 1, 2, 2), new Rect(1, 3, 2, 2), new Rect(3, 3, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('C', 'B'), Tuple.Create('C', 'A') });

            ((TestFloorPlanGen)compareFloorPlan.GetRoom(0)).Identifier = 'B';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(1)).Identifier = 'C';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(2)).Identifier = 'D';

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

            var gen = new TestFloorPlanGen('D');

            gen.PrepareDraw(new Rect(3, 3, 2, 2));

            var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);
            var mockHalls = new Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            var pathGen = new AddSpecialRoomTestStep(mockRooms.Object, mockHalls.Object);

            pathGen.PlaceRoom(testRand.Object, floorPlan, gen, new RoomHallIndex(0, false));

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }
Ejemplo n.º 2
0
        public void GetSupportRect(int x, int y, Dir4 dir, int expectX, int expectY, int expectW, int expectH)
        {
            // the adjacent tile lines up perfectly
            // 2x2 rooms here
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 6, 6), new Rect(5, 9, 2, 2), new Rect(1, 5, 2, 2), new Rect(5, 1, 2, 2), new Rect(9, 5, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C'), Tuple.Create('A', 'D'), Tuple.Create('A', 'E') });

            IRoomGen oldGen = floorPlan.GetRoom(0);

            Mock <IRoomGen> mockTo = new Mock <IRoomGen>(MockBehavior.Strict);

            mockTo.SetupGet(p => p.Draw).Returns(new Rect(x, y, 2, 2));

            var indexLookup = new Dictionary <Dir4, int> {
                { Dir4.Down, 1 }, { Dir4.Left, 2 }, { Dir4.Up, 3 }, { Dir4.Right, 4 }
            };
            var adjacentsInDir = new List <RoomHallIndex> {
                new RoomHallIndex(indexLookup[dir], false)
            };

            Rect rect = AddSpecialRoomTestStep.GetSupportRect(floorPlan, oldGen, mockTo.Object, dir, adjacentsInDir);

            Assert.That(rect, Is.EqualTo(new Rect(expectX, expectY, expectW, expectH)));
        }
Ejemplo n.º 3
0
        public void GetSupportRectMultiple()
        {
            // the adjacent tile crosses past the border
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 6, 6), new Rect(3, 9, 2, 2), new Rect(7, 9, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C') });

            IRoomGen oldGen = floorPlan.GetRoom(0);

            Mock <IRoomGen> mockTo = new Mock <IRoomGen>(MockBehavior.Strict);

            mockTo.SetupGet(p => p.Draw).Returns(new Rect(5, 3, 2, 2));

            var adjacentsInDir = new List <RoomHallIndex>
            {
                new RoomHallIndex(1, false),
                new RoomHallIndex(2, false),
            };

            Rect rect = AddSpecialRoomTestStep.GetSupportRect(floorPlan, oldGen, mockTo.Object, Dir4.Down, adjacentsInDir);

            Assert.That(rect, Is.EqualTo(new Rect(3, 5, 6, 4)));
        }
Ejemplo n.º 4
0
        public void PlaceRoomOneSupport()
        {
            // needs a supporting hall for one side
            TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(3, 3, 6, 6), new Rect(5, 1, 2, 2), new Rect(5, 9, 2, 2) },
                Array.Empty <Rect>(),
                new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C') });
            TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext(
                new Loc(22, 14),
                new Rect[] { new Rect(5, 1, 2, 2), new Rect(5, 9, 2, 2), new Rect(5, 3, 2, 2) },
                new Rect[] { new Rect(5, 5, 2, 4) },
                new Tuple <char, char>[] { Tuple.Create('C', 'A'), Tuple.Create('C', 'a'), Tuple.Create('a', 'B') });

            ((TestFloorPlanGen)compareFloorPlan.GetRoom(0)).Identifier = 'B';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(1)).Identifier = 'C';
            ((TestFloorPlanGen)compareFloorPlan.GetRoom(2)).Identifier = 'D';

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

            var gen = new TestFloorPlanGen('D');

            gen.PrepareDraw(new Rect(5, 3, 2, 2));

            var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > > mockHalls = new Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict);

            mockHalls.Setup(p => p.Pick(testRand.Object)).Returns(new TestFloorPlanGen('a'));

            var pathGen = new AddSpecialRoomTestStep(mockRooms.Object, mockHalls.Object);

            pathGen.PlaceRoom(testRand.Object, floorPlan, gen, new RoomHallIndex(0, false));

            TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan);
        }