Add main game loop

This commit is contained in:
Andrew Cooper
2022-07-30 16:19:50 +10:00
parent a2dc514955
commit aedfd73e8c
3 changed files with 43 additions and 7 deletions

36
34_Digits/csharp/Game.cs Normal file
View File

@@ -0,0 +1,36 @@
namespace Digits
{
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.Introduction);
if (_io.ReadNumber(Prompts.ForInstructions) != 0)
{
_io.Write(Streams.Instructions);
}
do
{
PlayOne();
} while (_io.ReadNumber(Prompts.WantToTryAgain) == 1);
_io.Write(Streams.Thanks);
}
private void PlayOne()
{
}
}
}

View File

@@ -0,0 +1,6 @@
global using Digits;
global using Games.Common.IO;
global using Games.Common.Randomness;
global using static Digits.Resources.Resource;
new Game(new ConsoleIO(), new RandomNumberGenerator()).Play();

View File

@@ -1,7 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Chomp.Resources;
namespace Digits.Resources;
internal static class Resource
{
@@ -24,12 +24,6 @@ internal static class Resource
public static string WantToTryAgain => GetString();
}
internal static class Strings
{
public static string TooManyColumns => GetString();
public static string TooManyRows => GetString();
}
private static string GetString([CallerMemberName] string? name = null)
{
using var stream = GetStream(name);