static void Main(string[] args) { int greenTime, yellowTime, redTime; int action; string str; Console.WriteLine("============交通信号灯============"); Input: while (true) { Console.Write("请输入绿灯持续时间:"); str = Console.ReadLine(); if (InputVerify(str)) { greenTime = Convert.ToUInt16(str); break; } } while (true) { Console.Write("请输入黄灯持续时间:"); str = Console.ReadLine(); if (InputVerify(str)) { yellowTime = Convert.ToUInt16(str); break; } } while (true) { Console.Write("请输入红灯持续时间:"); str = Console.ReadLine(); if (InputVerify(str)) { redTime = Convert.ToUInt16(str); break; } } while (true) { for (int i = greenTime; i > 0; i--) { Draw(i, ConsoleColor.Green); action = TrafficLight.Status(); switch (action) { case 2: Console.Clear(); goto Input; case 3: goto End; default: continue; } } for (int i = yellowTime; i > 0; i--) { Draw(i, ConsoleColor.Yellow); action = TrafficLight.Status(); switch (action) { case 2: Console.Clear(); goto Input; case 3: goto End; default: continue; } } for (int i = redTime; i > 0; i--) { Draw(i, ConsoleColor.Red); action = TrafficLight.Status(); switch (action) { case 2: Console.Clear(); goto Input; case 3: goto End; default: continue; } } } End: Console.WriteLine("\n程序结束,按任意键退出。"); Console.ReadKey(); }