Skip to content

Commit

Permalink
Game - add synonyms ('greet' and 'quit')
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Dec 1, 2018
1 parent 43fa575 commit 1f6e22b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions sample/src/Game.cs
Expand Up @@ -20,8 +20,11 @@ public Game(TextReader reader, TextWriter writer)


public void Run() public void Run()
{ {
Words words = new Words();
words.Add("greet", "hello", "hi");
words.Add("quit", "exit");
using (CancellationTokenSource cts = new CancellationTokenSource()) using (CancellationTokenSource cts = new CancellationTokenSource())
using (new SentenceParser(this.bus, new Words())) using (new SentenceParser(this.bus, words))
using (this.bus.Subscribe<SentenceMessage>(m => this.ProcessVerb(cts, m.Verb))) using (this.bus.Subscribe<SentenceMessage>(m => this.ProcessVerb(cts, m.Verb)))
{ {
this.console.Run(cts.Token); this.console.Run(cts.Token);
Expand All @@ -31,11 +34,11 @@ public void Run()
private void ProcessVerb(CancellationTokenSource cts, Word verb) private void ProcessVerb(CancellationTokenSource cts, Word verb)
{ {
string output = null; string output = null;
if (verb.Actual == "hello") if (verb.Primary == "greet")
{ {
output = "world"; output = "You say, \"Hello,\" to no one in particular. No one answers.";
} }
else if (verb.Actual == "quit") else if (verb.Primary == "quit")
{ {
cts.Cancel(); cts.Cancel();
} }
Expand Down
3 changes: 2 additions & 1 deletion sample/test/walkthrough.in
@@ -1,4 +1,5 @@
hello hello
heeyyyyyyyy heeyyyyyyyy
quit HI
exit
-- END -- -- END --
3 changes: 2 additions & 1 deletion sample/test/walkthrough.out
@@ -1,2 +1,3 @@
world You say, "Hello," to no one in particular. No one answers.
I don't know what 'heeyyyyyyyy' means. I don't know what 'heeyyyyyyyy' means.
You say, "Hello," to no one in particular. No one answers.

0 comments on commit 1f6e22b

Please sign in to comment.