Пример #1
0
        //打印方法
        public void PrintNumber(string color)
        {
            for (int row = 0; row < light01.GetLength(0); row++)
            {
                for (int col01 = 0; col01 < light01.GetLength(1); col01++)
                {
                    if (light01[row, col01] == true)
                    {
                        PrintCustom.PrintUseColor(color, "●");
                    }
                    else
                    {
                        PrintCustom.PrintUseColor("white", "●");
                    }
                }
                Console.Write("\t");
                for (int col02 = 0; col02 < light01.GetLength(1); col02++)
                {
                    if (light02[row, col02] == true)
                    {
                        PrintCustom.PrintUseColor(color, "●");
                    }
                    else
                    {
                        PrintCustom.PrintUseColor("white", "●");
                    }
                }

                Console.WriteLine();
            }
            Console.Write("\n\n\n");
            PrintCustom.PrintUseColor("cyan", "【暂停/启动:Space   重新设定时间:Enter    结束:End】");
        }
Пример #2
0
        static void Main(string[] args)
        {
ReInput:
            //让用户输入红灯、黄灯、绿灯的倒计时时间
            Console.Clear();
            int greenTime, yellowTime, redTime;

            while (true)
            {
                PrintCustom.PrintUseColor("green", "请输入绿灯的时间:");
                string str = Console.ReadLine();
                if (CheckInput(str))
                {
                    greenTime = Convert.ToInt32(str);
                    break;
                }
            }
            while (true)
            {
                PrintCustom.PrintUseColor("yellow", "请输入黄灯的时间:");
                string str = Console.ReadLine();
                if (CheckInput(str))
                {
                    yellowTime = Convert.ToInt32(str);
                    break;
                }
            }
            while (true)
            {
                PrintCustom.PrintUseColor("red", "请输入红灯的时间:");
                string str = Console.ReadLine();
                if (CheckInput(str))
                {
                    redTime = Convert.ToInt32(str);
                    break;
                }
            }


            //如何让这三个颜色的灯交替循环倒计时
            //一直在做!直到---循环
            while (true)
            {
                //绿灯倒计时
                for (int i = greenTime; i > 0; i--)
                {
                    TrafficLight objTraf = new TrafficLight(i);
                    Console.Clear();
                    objTraf.PrintNumber("green");
                    //捕获键盘响应
                    int action = TrafficLight.Wart();
                    if (action == 1)
                    {
                        continue;
                    }
                    else if (action == 2)
                    {
                        goto ReInput;
                    }
                    else if (action == 3)
                    {
                        goto End;
                    }
                }
                //黄灯倒计时
                for (int i = yellowTime; i > 0; i--)
                {
                    TrafficLight objTraf = new TrafficLight(i);
                    Console.Clear();
                    objTraf.PrintNumber("yellow");
                    System.Threading.Thread.Sleep(1000);
                    //捕获键盘响应
                    int action = TrafficLight.Wart();
                    if (action == 1)
                    {
                        continue;
                    }
                    else if (action == 2)
                    {
                        goto ReInput;
                    }
                    else if (action == 3)
                    {
                        goto End;
                    }
                }
                //红灯倒计时
                for (int i = redTime; i > 0; i--)
                {
                    TrafficLight objTraf = new TrafficLight(i);
                    Console.Clear();
                    objTraf.PrintNumber("red");
                    System.Threading.Thread.Sleep(1000);
                    //捕获键盘响应
                    int action = TrafficLight.Wart();
                    if (action == 1)
                    {
                        continue;
                    }
                    else if (action == 2)
                    {
                        goto ReInput;
                    }
                    else if (action == 3)
                    {
                        goto End;
                    }
                }
            }
End:
            Common.PrintCustom.PrintUseColor("red", "\n程序已退出,按任意键结束!");
            Console.ReadKey();
        }