Beispiel #1
0
        public void TestCompleteVerbShouldFindWholeVerb()
        {
            Thing       thisThing  = new Thing("nothing");
            Func <bool> lookAction = new Func <bool>(() => { return(true); });

            thisThing.AddVerb("look", new Thing.AllowUseAloneDelegate(lookAction));

            Assert.IsTrue(thisThing.AllowUseAlone("look"));
        }
Beispiel #2
0
        public void TestCompleteVerbShouldFindPartialVerb()
        {
            Thing       thisThing  = new Thing("nothing");
            Func <bool> lookAction = new Func <bool>(() => {
                Messages.Action("{D0 v0look}", thisThing);
                return(true);
            });

            thisThing.AddVerb("l", new Thing.AllowUseAloneDelegate(lookAction));

            Assert.IsTrue(thisThing.AllowUseAlone("l"));
        }
Beispiel #3
0
        public void Parse(string input, Thing doer)
        {
            string[] words = input.ToLower().Split(' ');

            if (words.Length == 0)
            {
                doer.Tell(Messages.Nonsense());
                return;
            }

            string verb = doer.CompleteVerb(words[0]);

            if (verb == null)
            {
                doer.Tell(string.Format(Garbage, words[0]));
                return;
            }

            if (words.Length == 1)
            {
                if (doer.AllowUseAlone(verb))
                {
                    return;
                }

                Debug.Assert(false);
                return;
            }

            List <string> remainingWords = words.Skip(1).ToList <string>();
            List <Thing>  foundThings    = new List <Thing>();

            foreach (Thing thing in doer.Container.ShallowInventory)
            {
                if (thing.Matches(remainingWords))
                {
                    foundThings.Add(thing);
                }
            }

            foreach (Thing thing in doer.ShallowInventory)
            {
                if (thing.Matches(remainingWords))
                {
                    foundThings.Add(thing);
                }
            }

            if (foundThings.Count == 0)
            {
                doer.Tell(Messages.PersonalAction(doer, "I can't find {dt1}.", doer, new Thing(string.Join(" ", remainingWords))));
                return;
            }

            if (foundThings.Count > 1)
            {
                doer.Tell("I'm confused, which one do you mean?");
                return;
            }

            var foundThing = foundThings[0];

            if (!foundThing.AllowUsageAsDirObj(verb, doer))
            {
                var message = Messages.PersonalAction(doer, "{O0} can't {v0" + verb + "} that.", doer);
                doer.Tell(message);
                return;
            }

            if (doer.AllowUsageWithDirObj(verb, foundThing))
            {
                return;
            }

            doer.Tell(Messages.Nonsense());
            // Assume first word is the verb
            //if (doer.)
        }//