mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 23:26:40 -08:00
Fix game loop
This commit is contained in:
@@ -13,12 +13,11 @@ internal class Scoreboard
|
||||
_scores = new() { [home] = 0, [visitors] = 0 };
|
||||
Home = home;
|
||||
Visitors = visitors;
|
||||
Offense = home;
|
||||
_io = io;
|
||||
}
|
||||
|
||||
public bool ScoresAreEqual => _scores[Home] == _scores[Visitors];
|
||||
public Team Offense { get; set; }
|
||||
public Team? Offense { get; set; }
|
||||
public Team Home { get; }
|
||||
public Team Visitors { get; }
|
||||
|
||||
@@ -28,12 +27,16 @@ internal class Scoreboard
|
||||
|
||||
private void AddScore(uint score, string message)
|
||||
{
|
||||
if (Offense is null) { throw new InvalidOperationException("Offense must be set before adding to score."); }
|
||||
|
||||
_io.WriteLine(message);
|
||||
_scores[Offense] += score;
|
||||
Turnover();
|
||||
Display();
|
||||
}
|
||||
|
||||
public void StartPeriod() => Offense = null;
|
||||
|
||||
public void Turnover(string? message = null)
|
||||
{
|
||||
if (message is not null) { _io.WriteLine(message); }
|
||||
|
||||
Reference in New Issue
Block a user