mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-05 09:39:32 -08:00
Split out play resolution
This commit is contained in:
32
07_Basketball/csharp/Clock.cs
Normal file
32
07_Basketball/csharp/Clock.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Basketball.Resources;
|
||||
using Games.Common.IO;
|
||||
|
||||
namespace Basketball;
|
||||
|
||||
internal class Clock
|
||||
{
|
||||
private readonly IReadWrite _io;
|
||||
private int time;
|
||||
|
||||
public Clock(IReadWrite io) => _io = io;
|
||||
|
||||
public bool IsHalfTime => time == 50;
|
||||
public bool IsFullTime => time >= 100;
|
||||
public bool TwoMinutesLeft => time == 92;
|
||||
|
||||
public void Increment(Scoreboard scoreboard)
|
||||
{
|
||||
time += 1;
|
||||
if (IsHalfTime)
|
||||
{
|
||||
scoreboard.Display(Resource.Formats.EndOfFirstHalf);
|
||||
// Loop back to center jump;
|
||||
}
|
||||
if (TwoMinutesLeft)
|
||||
{
|
||||
_io.Write(Resource.Streams.TwoMinutesLeft);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartOvertime() => time = 93;
|
||||
}
|
||||
Reference in New Issue
Block a user