diff --git a/53_King/csharp/Game.cs b/53_King/csharp/Game.cs index 198ff14f..92d8063f 100644 --- a/53_King/csharp/Game.cs +++ b/53_King/csharp/Game.cs @@ -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(); diff --git a/53_King/csharp/IOExtensions.cs b/53_King/csharp/IOExtensions.cs index c2707c0d..e59bf4c0 100644 --- a/53_King/csharp/IOExtensions.cs +++ b/53_King/csharp/IOExtensions.cs @@ -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; } } } diff --git a/53_King/csharp/Reign.cs b/53_King/csharp/Reign.cs index 58e89b66..2bdc9b89 100644 --- a/53_King/csharp/Reign.cs +++ b/53_King/csharp/Reign.cs @@ -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; + } } } diff --git a/53_King/csharp/Resources/Goodbye.txt b/53_King/csharp/Resources/Goodbye.txt new file mode 100644 index 00000000..325890a5 --- /dev/null +++ b/53_King/csharp/Resources/Goodbye.txt @@ -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). diff --git a/53_King/csharp/Resources/Resource.cs b/53_King/csharp/Resources/Resource.cs index 37ff09eb..cf555583 100644 --- a/53_King/csharp/Resources/Resource.cs +++ b/53_King/csharp/Resources/Resource.cs @@ -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);