mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
Split out play resolution
This commit is contained in:
@@ -8,20 +8,19 @@ internal class Scoreboard
|
||||
private readonly Dictionary<Team, uint> _scores;
|
||||
private readonly IReadWrite _io;
|
||||
|
||||
private Team _home;
|
||||
private Team _visitors;
|
||||
|
||||
public Scoreboard(Team home, Team visitors, IReadWrite io)
|
||||
{
|
||||
_scores = new() { [home] = 0, [visitors] = 0 };
|
||||
_home = home;
|
||||
_visitors = visitors;
|
||||
Home = home;
|
||||
Visitors = visitors;
|
||||
Offense = home;
|
||||
_io = io;
|
||||
}
|
||||
|
||||
public bool ScoresAreEqual => _scores[_home] == _scores[_visitors];
|
||||
public bool ScoresAreEqual => _scores[Home] == _scores[Visitors];
|
||||
public Team Offense { get; set; }
|
||||
public Team Home { get; }
|
||||
public Team Visitors { get; }
|
||||
|
||||
public void AddBasket(string message) => AddScore(2, message);
|
||||
|
||||
@@ -39,9 +38,9 @@ internal class Scoreboard
|
||||
{
|
||||
if (message is not null) { _io.WriteLine(message); }
|
||||
|
||||
Offense = Offense == _home ? _visitors : _home;
|
||||
Offense = Offense == Home ? Visitors : Home;
|
||||
}
|
||||
|
||||
public void Display(string? format = null) =>
|
||||
_io.WriteLine(format ?? Resource.Formats.Score, _home, _scores[_home], _visitors, _scores[_visitors]);
|
||||
_io.WriteLine(format ?? Resource.Formats.Score, Home, _scores[Home], Visitors, _scores[Visitors]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user