mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
47 lines
1016 B
C#
47 lines
1016 B
C#
namespace King;
|
|
|
|
internal class Game
|
|
{
|
|
const int TermOfOffice = 8;
|
|
|
|
private readonly IReadWrite _io;
|
|
private readonly IRandom _random;
|
|
|
|
public Game(IReadWrite io, IRandom random)
|
|
{
|
|
_io = io;
|
|
_random = random;
|
|
}
|
|
|
|
public void Play()
|
|
{
|
|
_io.Write(Resource.Title);
|
|
|
|
if (SetUpReign() is Reign reign)
|
|
{
|
|
_io.Write(reign);
|
|
}
|
|
|
|
_io.WriteLine();
|
|
_io.WriteLine();
|
|
}
|
|
|
|
private Reign? SetUpReign()
|
|
{
|
|
var response = _io.ReadString(Resource.InstructionsPrompt).ToUpper();
|
|
|
|
if (response.Equals("Again", StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
return _io.TryReadGameData(_random, out var reign) ? reign : null;
|
|
}
|
|
|
|
if (!response.StartsWith("N", StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
_io.Write(Resource.InstructionsText(TermOfOffice));
|
|
}
|
|
|
|
_io.WriteLine();
|
|
return new Reign(_io, _random);
|
|
}
|
|
}
|