From 29636d5696c8fb97464a6c4d0a5d3add7df1a709 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Wed, 25 Jan 2023 23:01:36 +1100 Subject: [PATCH] CSHARP-72 Add game intro --- 72_Queen/csharp/Games.cs | 34 +++++++++++++++++++ 72_Queen/csharp/Program.cs | 8 +++-- .../Resources/{YesyOrNo.txt => YesOrNo.txt} | 0 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 72_Queen/csharp/Games.cs rename 72_Queen/csharp/Resources/{YesyOrNo.txt => YesOrNo.txt} (100%) diff --git a/72_Queen/csharp/Games.cs b/72_Queen/csharp/Games.cs new file mode 100644 index 00000000..73a0b80b --- /dev/null +++ b/72_Queen/csharp/Games.cs @@ -0,0 +1,34 @@ +namespace Queen; + +internal class Game +{ + private readonly IReadWrite _io; + private readonly IRandom _random; + + public Game(IReadWrite io, IRandom random) + { + _io = io; + _random = random; + } + + internal void Play() + { + _io.Write(Streams.Title); + if (_io.ShouldDisplayInstructions()) { _io.Write(Streams.Instructions); } + } +} + +internal static class IOExtensions +{ + internal static bool ShouldDisplayInstructions(this IReadWrite io) + { + while (true) + { + var answer = io.ReadString(Prompts.Instructions).ToLower(); + if (answer == "yes") { return true; } + if (answer == "no") { return false; } + + io.Write(Streams.YesOrNo); + } + } +} diff --git a/72_Queen/csharp/Program.cs b/72_Queen/csharp/Program.cs index 0733c377..a32aded0 100644 --- a/72_Queen/csharp/Program.cs +++ b/72_Queen/csharp/Program.cs @@ -1,3 +1,7 @@ -using Games.Common.IO; +global using Games.Common.IO; +global using Games.Common.Randomness; +global using static Queen.Resources.Resource; -var io = new ConsoleIO(); \ No newline at end of file +using Queen; + +new Game(new ConsoleIO(), new RandomNumberGenerator()).Play(); \ No newline at end of file diff --git a/72_Queen/csharp/Resources/YesyOrNo.txt b/72_Queen/csharp/Resources/YesOrNo.txt similarity index 100% rename from 72_Queen/csharp/Resources/YesyOrNo.txt rename to 72_Queen/csharp/Resources/YesOrNo.txt