Beispiel #1
0
        public void TestOpeningAndClosingOfLockedAndUnlockedThings()
        {
            // Make our lockable thing also openable.
            var opensClosesBehavior = new OpensClosesBehavior();

            this.lockableThing.Behaviors.Add(opensClosesBehavior);
            this.lockableThing.Behaviors.Add(this.locksUnlocksBehavior);

            // Verify that the thing is still in the default locked state.
            Assert.IsTrue(this.locksUnlocksBehavior.IsLocked);

            // Verify that attempts to open the locked thing do not work.
            // (Note that adding player-convenience features like automatic unlock attempts on behalf of the
            // player when trying to open something, depending on their settings or whatnot, may require such
            // tests to become much more robust here.)
            opensClosesBehavior.Open(this.actingThing);
            Assert.IsTrue(this.locksUnlocksBehavior.IsLocked);
            Assert.IsTrue(!opensClosesBehavior.IsOpen);

            // Verify that attempts to open an unlocked thing do work though.
            this.locksUnlocksBehavior.Unlock(this.actingThing);
            opensClosesBehavior.Open(this.actingThing);
            Assert.IsTrue(!this.locksUnlocksBehavior.IsLocked);
            Assert.IsTrue(opensClosesBehavior.IsOpen);

            // Verify that trying to lock an open thing is either cancelled (leaving it open and unlocked)
            // or is automatically closed for the actor since the intent could be implied.
            this.locksUnlocksBehavior.Lock(this.actingThing);
            bool isClosedAndLocked = !opensClosesBehavior.IsOpen && this.locksUnlocksBehavior.IsLocked;
            bool isOpenAndUnlocked = opensClosesBehavior.IsOpen && !this.locksUnlocksBehavior.IsLocked;

            Assert.IsTrue(isClosedAndLocked || isOpenAndUnlocked);
        }
Beispiel #2
0
        public void TestUnattachedOpensClosesBehavior()
        {
            // Verify that an unattached behavior does not change state between Open/Close attempts, and
            // that such attempts do not throw. (This keeps the behavior solid in the face of the parent
            // being destroyed or whatnot as a race versus a user trying to activate it.)
            bool initialState = opensClosesBehavior.IsOpen;

            opensClosesBehavior.Close(actingThing);
            Assert.AreEqual(initialState, opensClosesBehavior.IsOpen);
            opensClosesBehavior.Open(actingThing);
            Assert.AreEqual(initialState, opensClosesBehavior.IsOpen);
        }
Beispiel #3
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);
        }