mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-15 06:23:15 -08:00
CSHARP-72 Add game intro
This commit is contained in:
34
72_Queen/csharp/Games.cs
Normal file
34
72_Queen/csharp/Games.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user