Permalink
Browse files

Game - add 'take' routine

  • Loading branch information...
bobbymcr committed Dec 1, 2018
1 parent 1f6e22b commit f22b62d13406d6a561def10854a5b2ded166fd75
Showing with 12 additions and 2 deletions.
  1. +8 −2 sample/src/Game.cs
  2. +2 −0 sample/test/walkthrough.in
  3. +2 −0 sample/test/walkthrough.out
@@ -23,17 +23,19 @@ public void Run()
Words words = new Words();
words.Add("greet", "hello", "hi");
words.Add("quit", "exit");
words.Add("take", "get");
using (CancellationTokenSource cts = new CancellationTokenSource())
using (new SentenceParser(this.bus, words))
using (this.bus.Subscribe<SentenceMessage>(m => this.ProcessVerb(cts, m.Verb)))
using (this.bus.Subscribe<SentenceMessage>(m => this.ProcessSentence(cts, m)))
{
this.console.Run(cts.Token);
}
}

private void ProcessVerb(CancellationTokenSource cts, Word verb)
private void ProcessSentence(CancellationTokenSource cts, SentenceMessage sentence)
{
string output = null;
Word verb = sentence.Verb;
if (verb.Primary == "greet")
{
output = "You say, \"Hello,\" to no one in particular. No one answers.";
@@ -42,6 +44,10 @@ private void ProcessVerb(CancellationTokenSource cts, Word verb)
{
cts.Cancel();
}
else if (verb.Primary == "take")
{
output = "There is no " + sentence.Noun.Actual.ToLowerInvariant() + " here.";
}
else
{
output = "I don't know what '" + verb + "' means.";
@@ -1,5 +1,7 @@
hello
heeyyyyyyyy
HI
take care
GET KEY
exit
-- END --
@@ -1,3 +1,5 @@
You say, "Hello," to no one in particular. No one answers.
I don't know what 'heeyyyyyyyy' means.
You say, "Hello," to no one in particular. No one answers.
There is no care here.
There is no key here.

0 comments on commit f22b62d

Please sign in to comment.