namespace HorseRace;
public sealed class HorseRace
{
public const int MaxSteps = 20;
private const int DelayMilliseconds = 100;
private readonly Horse[] _horses;
public HorseRace(Horse[] horses)
{
// TODO
}
private bool IsFinished { get; set; }
///
/// Prints the starting list for all horses in this race.
///
public void PrintStartList()
{
string nl = Environment.NewLine;
var s = "Starting List";
s += $"{nl}{new string('=', s.Length)}{nl}"
;
foreach (var horse in _horses)
{
s += string.Format($"{horse.StartNumber,3} {horse.Name,-10} {horse.Age,2}{nl}");
}
Console.WriteLine(s);
}
///
/// Starts and performs the race by moving and drawing the horses, until at least one
/// horse has reached the finish line.
///
public void PerformRace()
{
IsFinished = false;
while (!IsFinished)
{
MoveHorses();
DrawHorses();
Thread.Sleep(DelayMilliseconds);
}
AssignRanks();
}
///
/// Prints the race results to the terminal; only if the race is finished.
///
public void PrintResults()
{
// TODO
}
///
/// Moves all horses and checks, if any of the horses has reached the finish line.
///
private void MoveHorses()
{
// TODO
}
///
/// Draws each horse with label, current position and finish line.
///
private void DrawHorses()
{
Console.Clear();
// TODO
}
///
/// Assigns ranks to the horses, according to their individual position in the race.
///
private void AssignRanks()
{
SortByPosition();
// TODO
}
///
/// Sorts the array of horses by position and then by starting number.
///
private void SortByPosition()
{
// TODO
}
}