Пример #1
0
        public void DropShouldWork()
        {
            var adminThing = new AdminThing("some weirdo");
            var roomThing  = new RoomThing();

            adminThing.Move(roomThing);
            var uselessThing = new Thing("useless thing");

            //uselessThing.AddVerb("take", new Thing.AllowUsageAsDirObjDelegate((taker, myself) => { return true; }));
            uselessThing.AddDirectObjectHandler("take", new Func <Thing, Thing, bool>((taker, myself) => { return(true); }));
            uselessThing.AddDirectObjectHandler("drop", new Func <Thing, Thing, bool>((dropper, myself) =>
            {
                if (!dropper.ShallowInventory.Contains(myself))
                {
                    dropper.Tell(Messages.PersonalAction(dropper, "You aren't holding {d1}", dropper, myself));
                    return(false);
                }

                return(true);
            }));

            uselessThing.Move(roomThing);

            Repl repl = new Repl();

            repl.Parse("look", adminThing);

            Assert.IsFalse(adminThing.ShallowInventory.Contains(uselessThing));
            repl.Parse("take thing", adminThing);
            Assert.IsTrue(adminThing.ShallowInventory.Contains(uselessThing));

            repl.Parse("drop thing", adminThing);
            Assert.IsFalse(adminThing.ShallowInventory.Contains(uselessThing));

            Assert.IsTrue(roomThing.ShallowInventory.Contains(uselessThing));
        }
Пример #2
0
        public void TakeShouldWork()
        {
            var adminThing = new AdminThing("some weirdo");
            var roomThing  = new RoomThing();

            adminThing.Move(roomThing);
            var uselessThing = new Thing("useless thing");

            //uselessThing.AddVerb("take", new Thing.AllowUsageAsDirObjDelegate((taker, myself) => { return true; }));
            uselessThing.AddDirectObjectHandler("take", new Func <Thing, Thing, bool>((taker, myself) => { return(true); }));
            uselessThing.Move(roomThing);

            Repl repl = new Repl();

            repl.Parse("look", adminThing);

            Assert.IsFalse(adminThing.ShallowInventory.Contains(uselessThing));
            repl.Parse("take thing", adminThing);
            Assert.IsTrue(adminThing.ShallowInventory.Contains(uselessThing));
        }