CSHARP-72 Add game intro

This commit is contained in:
Andrew Cooper
2023-01-25 23:01:36 +11:00
parent 083a11f42f
commit 29636d5696
3 changed files with 40 additions and 2 deletions

34
72_Queen/csharp/Games.cs Normal file
View File

@@ -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);
}
}
}

View File

@@ -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();
using Queen;
new Game(new ConsoleIO(), new RandomNumberGenerator()).Play();