mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-09 03:43:01 -08:00
Add game loop and end
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
53_King/csharp/Resources/Goodbye.txt
Normal file
5
53_King/csharp/Resources/Goodbye.txt
Normal 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).
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user