the clock will automatically run myclock.Tick and display on the console. and i would like to reset the clock when i press spacebar.
however, it seems i can't end the loop when i press the spacebar.
So, how can i reset the clock by keyinput?
it is because of the console.readkey
Correct Program.cs:
public static void Main(string[] args)
{
Clock myclock = new Clock();
while (true)
{
Console.WriteLine("Press 'spacebar' to view the time and 'r' to reset the time");
if (Console.ReadKey().Key == ConsoleKey.Spacebar)
{
for (int i = 0; i < 86400;i++)
{
myclock.displayTime();
Thread.Sleep(1000);
myclock.Update();
if (Console.KeyAvailable)
{
ConsoleKeyInfo cki = Console.ReadKey(true);
if (cki.Key == ConsoleKey.R)
{
myclock.ClockReset();
Console.WriteLine("\nClock has been reset");
break;
}
}
}
}
}