Add game loop and end

This commit is contained in:
Andrew Cooper
2022-11-02 08:00:27 +11:00
parent d4c5fb1df7
commit ab7f2c1182
5 changed files with 25 additions and 7 deletions

View File

@@ -17,9 +17,10 @@ internal class Game
{
_io.Write(Resource.Title);
if (SetUpReign() is Reign reign)
var reign = SetUpReign();
if (reign != null)
{
reign.PlayYear();
while (reign.PlayYear());
}
_io.WriteLine();

View File

@@ -26,7 +26,7 @@ internal static class IOExtensions
while (true)
{
var response = value = io.ReadNumber(prompt);
if (response < 0) { return false; }
if (response == 0) { return false; }
if (tests.All(test => test.IsValid(response, io))) { return true; }
}
}

View File

@@ -6,10 +6,10 @@ internal class Reign
private readonly IReadWrite _io;
private readonly Country _country;
private readonly float _year;
private float _year;
public Reign(IReadWrite io, IRandom random)
: this(io, new Country(io, random), 0)
: this(io, new Country(io, random), 1)
{
}
@@ -20,7 +20,7 @@ internal class Reign
_year = year;
}
public void PlayYear()
public bool PlayYear()
{
_io.Write(_country.Status);
@@ -28,6 +28,16 @@ internal class Reign
var playerDistributedRallods = _country.DistributeRallods();
var playerPlantedLand = _country.PlantLand();
var playerControlledPollution = _country.ControlPollution();
if (playerSoldLand || playerDistributedRallods || playerPlantedLand || playerControlledPollution)
{
_year++;
return true;
}
else
{
_io.Write(Goodbye);
return false;
}
}
}

View File

@@ -0,0 +1,5 @@
Goodbye.
(If you wish to continue this game at a later date, answer
'again' when asked if you want instructions at the start
of the game).

View File

@@ -59,6 +59,8 @@ internal static class Resource
public static string SavedLandPrompt => GetString();
public static string SavedLandError => GetString();
public static string Goodbye => GetString();
private static string GetString([CallerMemberName] string? name = null)
{
using var stream = GetStream(name);