From 1f6e22bb26165588a943b38feea4fc00cc343765 Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Sat, 1 Dec 2018 07:58:19 -0800 Subject: [PATCH] Game - add synonyms ('greet' and 'quit') --- sample/src/Game.cs | 11 +++++++---- sample/test/walkthrough.in | 3 ++- sample/test/walkthrough.out | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sample/src/Game.cs b/sample/src/Game.cs index 0521d44..b5a3b4a 100644 --- a/sample/src/Game.cs +++ b/sample/src/Game.cs @@ -20,8 +20,11 @@ public Game(TextReader reader, TextWriter writer) public void Run() { + Words words = new Words(); + words.Add("greet", "hello", "hi"); + words.Add("quit", "exit"); using (CancellationTokenSource cts = new CancellationTokenSource()) - using (new SentenceParser(this.bus, new Words())) + using (new SentenceParser(this.bus, words)) using (this.bus.Subscribe(m => this.ProcessVerb(cts, m.Verb))) { this.console.Run(cts.Token); @@ -31,11 +34,11 @@ public void Run() private void ProcessVerb(CancellationTokenSource cts, Word verb) { 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(); } diff --git a/sample/test/walkthrough.in b/sample/test/walkthrough.in index 7c9c560..e80a162 100644 --- a/sample/test/walkthrough.in +++ b/sample/test/walkthrough.in @@ -1,4 +1,5 @@ hello heeyyyyyyyy -quit +HI +exit -- END -- \ No newline at end of file diff --git a/sample/test/walkthrough.out b/sample/test/walkthrough.out index 1980231..8f31859 100644 --- a/sample/test/walkthrough.out +++ b/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. +You say, "Hello," to no one in particular. No one answers.