Exemple #1
0
        public void TestOpeningClosingAndMovementForExits()
        {
            // Create two one-way exits and two rooms to attach them to.
            var openableExitA = new Thing()
            {
                Name = "OpenableExitA", Id = TestThingID.Generate("testthing")
            };
            var openableExitB = new Thing()
            {
                Name = "OpenableExitB", Id = TestThingID.Generate("testthing")
            };
            var roomA = new Thing(new RoomBehavior())
            {
                Name = "Room A", Id = TestThingID.Generate("testroom")
            };
            var roomB = new Thing(new RoomBehavior())
            {
                Name = "Room B", Id = TestThingID.Generate("testroom")
            };

            roomA.Add(openableExitA);
            roomB.Add(openableExitB);

            // Attach ExitBehavior and OpensClosesBehaviors in different orders though, to verify in test that
            // eventing and such work correctly regardless of attachment order.
            var exitBehaviorA        = new ExitBehavior();
            var exitBehaviorB        = new ExitBehavior();
            var opensClosesBehaviorB = new OpensClosesBehavior();

            openableExitA.Behaviors.Add(exitBehaviorA);
            openableExitA.Behaviors.Add(opensClosesBehavior);
            openableExitB.Behaviors.Add(opensClosesBehaviorB);
            openableExitB.Behaviors.Add(exitBehaviorB);

            // Rig up behaviors so the actor can move, and move from one A to B, and from B to A.
            actingThing.Behaviors.Add(new MovableBehavior());
            exitBehaviorA.AddDestination("toB", roomB.Id);
            exitBehaviorB.AddDestination("toA", roomA.Id);

            // Ensure that the actingThing cannot move through either exit while it is in default (closed) state.
            roomA.Add(actingThing);
            exitBehaviorA.MoveThrough(actingThing);
            Assert.AreSame(roomA, actingThing.Parent);

            roomB.Add(actingThing);
            exitBehaviorB.MoveThrough(actingThing);
            Assert.AreSame(roomB, actingThing.Parent);

            // Ensure that the actingThing can open and move through each openable exit to get between rooms.
            opensClosesBehaviorB.Open(actingThing);
            exitBehaviorB.MoveThrough(actingThing);
            Assert.AreSame(roomA, actingThing.Parent);

            opensClosesBehavior.Open(actingThing);
            exitBehaviorA.MoveThrough(actingThing);
            Assert.AreSame(roomB, actingThing.Parent);
        }
Exemple #2
0
        public void TestOneWayExitBehavior()
        {
            // Put the exit in room A only, and register an exit command to travel one way.
            roomA.Add(exit);
            exitBehavior.AddDestination("east", roomB.Id);

            // Ensure the exit is rigged up to the correct location now, but does not work the other way around.
            Assert.AreSame(exitBehavior.GetDestination(roomA), roomB);
            Assert.AreSame(exitBehavior.GetDestination(roomA), roomB);
            Assert.AreNotSame(exitBehavior.GetDestination(roomB), roomA);

            // Create an unmovable actor, and ensure that said actor cannot move through.
            actor = new Thing()
            {
                Name = "Actor"
            };
            roomA.Add(actor);
            exitBehavior.MoveThrough(actor);
            Assert.AreSame(actor.Parent, roomA);

            // Make the actor movable, and try moving the actor through again.
            actor.Behaviors.Add(new MovableBehavior());
            exitBehavior.MoveThrough(actor);
            Assert.AreSame(actor.Parent, roomB);

            // Ensure the actor does not end up in room A if we try to shove the actor through again.
            exitBehavior.MoveThrough(actor);
            Assert.AreSame(actor.Parent, roomB);

            // TODO: Place the actor back in room A, and try using the context command to move it?
            roomA.Add(actor);
        }