Permalink
Browse files

Game - use QuitHandler

  • Loading branch information...
bobbymcr committed Dec 5, 2018
1 parent cc41d14 commit 75ef5cc23f1eff08d42005188e4d1b2c9b2c5425
Showing with 2 additions and 15 deletions.
  1. +2 −15 sample/src/Game.cs
@@ -5,7 +5,6 @@
namespace Adventure.Sample
{
using System.IO;
using System.Threading;

public sealed class Game
{
@@ -22,14 +21,13 @@ public Game(TextReader reader, TextWriter writer)

public void Run()
{
using (CancellationTokenSource cts = new CancellationTokenSource())
using (this.bus.Subscribe<SentenceMessage>(m => this.HandleQuit(m.Verb, cts)))
using (new SentenceParser(this.bus, this.words))
using (QuitHandler quit = new QuitHandler(this.bus, Verb.Quit))
using (InputLoop loop = this.console.NewLoop())
{
Room room = new MainRoom(this.bus);
room.Enter();
loop.Run(cts.Token);
loop.Run(quit.Token);
}
}

@@ -41,16 +39,5 @@ private static Words InitializeWords()
w.Add(Verb.Take, "get");
return w;
}

private bool HandleQuit(Word verb, CancellationTokenSource cts)
{
if (verb.Primary == Verb.Quit)
{
cts.Cancel();
return true;
}

return false;
}
}
}

0 comments on commit 75ef5cc

Please sign in to comment.