public static void Update() { CurrentlyCarCount.Text = Cars.Count.ToString(); foreach (var c in Cars) { if (Car.Check(c)) { c.Speed = 0; } else { c.Speed = Car.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 Car) { Cars.Remove((Car)d); } else if (d is People) { Peoples.Remove((People)d); } } } UserPanel.Invalidate(); }
public static void Initialization() { Cars = new List <Car>(); Peoples = new List <People>(); Deleter = new List <IMovementMember>(); R = new Random(); LightsInterval1 = 30; LightsInterval2 = 30; TrafficLights = new TrafficLight[4]; RightTurn = new RightTurn(); LeftTurn = new LeftTurn(); MoveTimer = new Timer { Interval = 10 }; MoveTimer.Tick += (sender, e) => Update(); PMoveTimer = new Timer { Interval = 100 }; PMoveTimer.Tick += (sender, e) => P_Move(); GenCarTimer = new Timer { Interval = 100 }; GenCarTimer.Tick += (sender, e) => GenerateCar_Tick(); GenPeopleTimer = new Timer { Interval = 1000 }; GenPeopleTimer.Tick += (sender, e) => GeneratePeople_Tick(); WorkTimer = new Timer { Interval = 1000 }; WorkTimer.Tick += (sender, e) => Work_tick(); LightsTimer = new Timer { Interval = LightsInterval1 }; LightsTimer.Tick += (sender, e) => TrafficLight.SwitchLight(); }