예제 #1
0
 public static void Initialization()
 {
     Car           = new List <Cars>();
     Deleter       = new List <BaseClass>();
     R             = new Random(DateTime.Now.Millisecond);
     TrafficLights = new TrafficLight[4];
     RightTurn     = new RightTurn();
     LeftTurn      = new LeftTurn();
     MoveTimer     = new Timer {
         Interval = 10
     };
     MoveTimer.Tick += (sender, e) => Update();
     GenCarTimer     = new Timer {
         Interval = speedest * 1000
     };
     GenCarTimer.Tick += (sender, e) => GenerateCar_Tick();
     WorkTimer         = new Timer {
         Interval = 1000
     };
     WorkTimer.Tick += (sender, e) => Work_tick();
     LightsTimer     = new Timer {
         Interval = LightsInterval1
     };
     LightsTimer.Tick += (sender, e) => TrafficLight.SwitchLight();
 }
예제 #2
0
 public static void Update()
 {
     CurrentlyCarCount.Text = Car.Count.ToString();
     //Логика работы
     foreach (var c in Car)
     {
         if (Cars.Check(c))
         {
             c.Speed = 0;
         }
         else
         {
             c.Speed = Cars.CanMove(c);
             if (c.Turn == CTurn.Right)
             {
                 RightTurn.StartTurn(c);
             }
             else if (c.Turn == CTurn.Left)
             {
                 LeftTurn.StartTurn(c);
             }
         }
         Move(c);
         if (c.X < -50 || c.X > UserPanel.Width + 50 || c.Y < -50 || c.Y > UserPanel.Height + 50)
         {
             Deleter.Add(c);
         }
     }
     if (Deleter.Count != 0)
     {
         foreach (var d in Deleter)
         {
             if (d is Cars)
             {
                 Car.Remove((Cars)d);
             }
         }
     }
     UserPanel.Invalidate();
 }