Permalink
Browse files

Game - extract Verb constants

  • Loading branch information...
bobbymcr committed Dec 1, 2018
1 parent 88bc667 commit 7fbad8d0ca6240c2bca8dd2b5e3727ea6f2e6431
Showing with 13 additions and 6 deletions.
  1. +13 −6 sample/src/Game.cs
@@ -33,9 +33,9 @@ public void Run()
private static Words InitializeWords()
{
Words w = new Words();
w.Add("greet", "hello", "hi");
w.Add("quit", "exit");
w.Add("take", "get");
w.Add(Verb.Greet, "hello", "hi");
w.Add(Verb.Quit, "exit");
w.Add(Verb.Take, "get");
return w;
}

@@ -52,16 +52,23 @@ private string Process(CancellationTokenSource cts, Word verb, Word noun)
{
switch (verb.Primary)
{
case "greet":
case Verb.Greet:
return "You say, \"Hello,\" to no one in particular. No one answers.";
case "take":
case Verb.Take:
return "There is no " + noun.Actual.ToLowerInvariant() + " here.";
case "quit":
case Verb.Quit:
cts.Cancel();
return null;
default:
return "I don't know what '" + verb + "' means.";
}
}

private static class Verb
{
public const string Greet = "greet";
public const string Take = "take";
public const string Quit = "quit";
}
}
}

0 comments on commit 7fbad8d

Please sign in to comment.