Permalink
Browse files

Game - use TextConsole

  • Loading branch information...
bobbymcr committed Nov 26, 2018
1 parent e2365d9 commit 809010a9d16508bb6ae82bc5a09e13cfec135ff5
Showing with 17 additions and 15 deletions.
  1. +15 −13 app/src/Game.cs
  2. +1 −1 app/src/Program.cs
  3. +1 −1 app/test/GameTest.cs
@@ -8,27 +8,29 @@ namespace Adventure.App

public sealed class Game
{
private readonly TextReader reader;
private readonly TextWriter writer;
private readonly MessageBus bus;
private readonly TextConsole console;

public Game(TextReader reader, TextWriter writer)
public Game(MessageBus bus, TextReader reader, TextWriter writer)
{
this.reader = reader;
this.writer = writer;
this.bus = bus;
this.console = new TextConsole(bus, reader, writer);
}

public void Run()
{
string line;
do
using (this.bus.Subscribe<InputMessage>(m => this.ProcessInput(m.Line)))
{
line = this.reader.ReadLine();
if (line == "hello")
{
this.writer.WriteLine("world");
}
this.console.Run();
}
}

private void ProcessInput(string line)
{
if (line == "hello")
{
this.bus.Send(new OutputMessage("world"));
}
while (line != null);
}
}
}
@@ -10,7 +10,7 @@ internal static class Program
{
private static void Main()
{
new Game(Console.In, Console.Out).Run();
new Game(new MessageBus(), Console.In, Console.Out).Run();
}
}
}
@@ -19,7 +19,7 @@ public void WalkthroughTest()
using (StreamReader reader = new StreamReader("walkthrough.in"))
using (StreamWriter writer = new StreamWriter(ActualOut))
{
new Game(reader, writer).Run();
new Game(new MessageBus(), reader, writer).Run();
}

File.ReadAllLines(ActualOut).Should().Equal(File.ReadAllLines(ExpectedOut));

0 comments on commit 809010a

Please sign in to comment.