Beispiel #1
0
        public static void night()
        {
            var    logic  = new logic();
            Random random = new Random();

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("----------------进入夜晚-----------------------");
            logic.CrossroadConditionRed(true);
            logic.CrossroadConditionGreen(false);
            logic.QWQ();
            for (int i = 0; i < random.Next(3, 6); i++)
            {
                if (random.Next(0, 1) == 0)
                {
                    logic.MasterControl(false);
                    Console.WriteLine(GenerateVehicle());
                    logic.MasterControl(true);
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            vehicle dong = new vehicle()
            {
                name = "东"
            };
            vehicle xi = new vehicle()
            {
                name = "西",
            };
            vehicle nan = new vehicle()
            {
                name = "南",
            };
            vehicle bei = new vehicle()
            {
                name = "北",
            };
            Random random = new Random();
            Queue  queue  = new Queue();

            queue.Enqueue(false);
            queue.Enqueue(true);
            var logic = new logic();

            Console.WriteLine("东西道路为主道,南北则为支道");
            Console.WriteLine("三十秒等太久,五秒我觉得可以");
            Thread.Sleep(2000);
            Console.WriteLine("十字路口瞎控制系统启动");
            Thread.Sleep(1000);
            logic.QWQ();
            while (queue.Count == 2)
            {
                bool IAmTheMostHandsome = (bool)queue.Dequeue();
                logic.MasterControl(IAmTheMostHandsome);
                queue.Enqueue(IAmTheMostHandsome);
                foreach (var item in SimulationOfCarColumn())
                {
                    dong.queue.Enqueue(item);
                }
                foreach (var item in SimulationOfCarColumn())
                {
                    xi.queue.Enqueue(item);
                }
                foreach (var item in SimulationOfCarColumn())
                {
                    nan.queue.Enqueue(item);
                }
                foreach (var item in SimulationOfCarColumn())
                {
                    bei.queue.Enqueue(item);
                }
                if (IAmTheMostHandsome)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        if (dong.queue.Count != 0)
                        {
                            Console.WriteLine("现在" + dong.name + "车道" + dong.queue.Dequeue());
                        }
                        if (xi.queue.Count != 0)
                        {
                            Console.WriteLine("现在" + xi.name + "车道" + xi.queue.Dequeue());
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        if (nan.queue.Count != 0)
                        {
                            Console.WriteLine("现在" + nan.name + "车道" + nan.queue.Dequeue());
                        }
                        if (bei.queue.Count != 0)
                        {
                            Console.WriteLine("现在" + bei.name + "车道" + bei.queue.Dequeue());
                        }
                    }
                }
                Thread.Sleep(10000);
                if (random.Next(0, 4) == 0)
                {
                    night();
                    Console.WriteLine("-----------------------白天----------------------------");
                }
            }
            Console.ReadKey();
        }