ex-oop-02-horse-race/HorseRace/HorseRace.cs
github-classroom[bot] a681bc9dcb
Initial commit
2024-10-15 17:16:17 +00:00

92 lines
2.1 KiB
C#

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; }
/// <summary>
/// Prints the starting list for all horses in this race.
/// </summary>
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);
}
/// <summary>
/// Starts and performs the race by moving and drawing the horses, until at least one
/// horse has reached the finish line.
/// </summary>
public void PerformRace()
{
IsFinished = false;
while (!IsFinished)
{
MoveHorses();
DrawHorses();
Thread.Sleep(DelayMilliseconds);
}
AssignRanks();
}
/// <summary>
/// Prints the race results to the terminal; only if the race is finished.
/// </summary>
public void PrintResults()
{
// TODO
}
/// <summary>
/// Moves all horses and checks, if any of the horses has reached the finish line.
/// </summary>
private void MoveHorses()
{
// TODO
}
/// <summary>
/// Draws each horse with label, current position and finish line.
/// </summary>
private void DrawHorses()
{
Console.Clear();
// TODO
}
/// <summary>
/// Assigns ranks to the horses, according to their individual position in the race.
/// </summary>
private void AssignRanks()
{
SortByPosition();
// TODO
}
/// <summary>
/// Sorts the array of horses by position and then by starting number.
/// </summary>
private void SortByPosition()
{
// TODO
}
}