mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
Add main game loop
This commit is contained in:
36
34_Digits/csharp/Game.cs
Normal file
36
34_Digits/csharp/Game.cs
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
6
34_Digits/csharp/Program.cs
Normal file
6
34_Digits/csharp/Program.cs
Normal 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();
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user