public void Init() { // Create the basic actor instances and behavior for test. this.witnessThing = new Thing() { Name = "WitnessThing", ID = TestThingID.Generate("testthing") }; this.actingThing = new Thing() { Name = "ActingThing", ID = TestThingID.Generate("testthing") }; this.openableThing = new Thing() { Name = "OpenableThing", ID = TestThingID.Generate("testthing") }; this.opensClosesBehavior = new OpensClosesBehavior(); // Set up the actors inside another (which we'll call a "room" although it needn't actually be a room). this.room = new Thing() { Name = "Room", ID = TestThingID.Generate("room") }; this.room.Add(witnessThing); this.room.Add(actingThing); this.room.Add(openableThing); // Prepare to verify correct eventing occurs. this.witnessThing.Eventing.MiscellaneousRequest += (root, e) => { this.lastWitnessRequest = e; }; this.witnessThing.Eventing.MiscellaneousEvent += (root, e) => { this.lastWitnessEvent = e; }; this.actingThing.Eventing.MiscellaneousRequest += (root, e) => { this.lastActorRequest = e; }; this.actingThing.Eventing.MiscellaneousEvent += (root, e) => { this.lastActorEvent = e; }; }
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. Verify.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); Verify.IsTrue(this.locksUnlocksBehavior.IsLocked); Verify.IsTrue(!opensClosesBehavior.IsOpen); // Verify that attempts to open an unlocked thing do work though. this.locksUnlocksBehavior.Unlock(this.actingThing); opensClosesBehavior.Open(this.actingThing); Verify.IsTrue(!this.locksUnlocksBehavior.IsLocked); Verify.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; Verify.IsTrue(isClosedAndLocked || isOpenAndUnlocked); }
/// <summary>Initializes a new instance of the OpensClosesBehaviorCommands class.</summary> /// <param name="opensClosesBehavior">The OpensClosesBehavior this class belongs to.</param> public OpensClosesBehaviorCommands(OpensClosesBehavior opensClosesBehavior) : base() { this.opensClosesBehavior = opensClosesBehavior; }
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(this.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. this.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(this.actingThing); exitBehaviorA.MoveThrough(this.actingThing); Verify.AreSame(roomA, this.actingThing.Parent); roomB.Add(this.actingThing); exitBehaviorB.MoveThrough(this.actingThing); Verify.AreSame(roomB, this.actingThing.Parent); // Ensure that the actingThing can open and move through each openable exit to get between rooms. opensClosesBehaviorB.Open(this.actingThing); exitBehaviorB.MoveThrough(this.actingThing); Verify.AreSame(roomA, this.actingThing.Parent); this.opensClosesBehavior.Open(this.actingThing); exitBehaviorA.MoveThrough(this.actingThing); Verify.AreSame(roomB, this.actingThing.Parent); }
/// <summary> /// Initializes a new instance of the OpensClosesBehaviorCommands class. /// </summary> /// <param name="opensClosesBehavior">The OpensClosesBehavior this class belongs to.</param> public OpensClosesBehaviorCommands(OpensClosesBehavior opensClosesBehavior) : base() { this.opensClosesBehavior = opensClosesBehavior; }