Permalink
Browse files

AdventureSample - move Handle(Verb) method to VerbRoutines class

  • Loading branch information...
bobbymcr committed May 12, 2018
1 parent 777ad5e commit 8ce8eaf517ffd0449bb2c634e06fc342c1e47924
Showing with 12 additions and 12 deletions.
  1. +12 −12 projects/AdventureSample/src/Adventure/adventure.cs
@@ -603,7 +603,7 @@ private VerbResult Main()
{
Parser();
VerbResult ret = HandleVerb(verbRoutines, unknown);
VerbResult ret = verbRoutines.Handle(verb, unknown);
if (ret == VerbResult.Idle)
{
// NO-OP
@@ -652,17 +652,6 @@ private void AddVerb(VerbRoutines verbRoutines, string v, Func<VerbResult> handl
verbRoutines.D.Add(v, handler);
}
private VerbResult HandleVerb(VerbRoutines verbRoutines, Func<VerbResult> unknown)
{
Func<VerbResult> verbRoutine;
if (!verbRoutines.D.TryGetValue(verb, out verbRoutine))
{
verbRoutine = unknown;
}
return verbRoutine();
}
private VerbResult UnknownVerb()
{
PRINT("I DON'T KNOW HOW TO DO THAT");
@@ -1363,5 +1352,16 @@ public VerbRoutines()
}
public Dictionary<string, Func<VerbResult>> D => verbRoutines;
public VerbResult Handle(string verb, Func<VerbResult> unknown)
{
Func<VerbResult> verbRoutine;
if (!this.verbRoutines.TryGetValue(verb, out verbRoutine))
{
verbRoutine = unknown;
}
return verbRoutine();
}
}
}

0 comments on commit 8ce8eaf

Please sign in to comment.