Пример #1
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();
 }
Пример #2
0
        public static bool Check(Cars c)
        {
            switch (c.CurrRoad)
            {
            case Side.Down:
                if (!RoadPass.CenterFive(c) && Engine.Car.Exists(
                        sc =>
                        sc.Y == c.Y &&
                        c.X + 60 >= sc.X && c.X + 10 <= sc.X))
                {
                    return(true);
                }
                if (c.Turn == CTurn.Left && Engine.TrafficLights[2].CurrLight == TrafficLight.Lights.Green && c.X <= Engine.UserPanel.Width / 2 - 60 && c.X >= Engine.UserPanel.Width / 2 - 65)
                {
                    return(true);
                }
                if (c.Turn == CTurn.Right &&
                    c.X >= Engine.UserPanel.Width / 2 - 50 * (Engine.CurrentRoad.VerticalRoadLeft + 1) + 20 &&
                    c.X <= Engine.UserPanel.Width / 2 - 50 * Engine.CurrentRoad.VerticalRoadLeft - 25 &&
                    Engine.Car.Exists(
                        sc =>
                        sc.X >= Engine.UserPanel.Width / 2 - 50 * Engine.CurrentRoad.VerticalRoadLeft &&
                        sc.X <= Engine.UserPanel.Width / 2 - 50 * (Engine.CurrentRoad.VerticalRoadLeft - 1) &&
                        sc.Y <= Engine.UserPanel.Height / 2 + Engine.CurrentRoad.HorizontRoadDown * 40 + 45 &&
                        sc.Y >= Engine.UserPanel.Height / 2 + Engine.CurrentRoad.HorizontRoadDown * 40 - 45 &&
                        sc != c))
                {
                    return(true);
                }
                break;

            case Side.Up:
                if (!RoadPass.CenterFive(c) && Engine.Car.Exists(
                        sc =>
                        sc.Y == c.Y &&
                        c.X - 60 <= sc.X && c.X - 10 >= sc.X))
                {
                    return(true);
                }
                if (c.Turn == CTurn.Left && Engine.TrafficLights[1].CurrLight == TrafficLight.Lights.Green && c.X >= Engine.UserPanel.Width / 2 + 5 && c.X <= Engine.UserPanel.Width / 2 + 10)
                {
                    return(true);
                }
                if (c.Turn == CTurn.Right && c.X >= Engine.UserPanel.Width / 2 + 50 * (Engine.CurrentRoad.VerticalRoadRight - 1) &&
                    c.X <= Engine.UserPanel.Width / 2 + 50 * Engine.CurrentRoad.VerticalRoadRight - 45 &&
                    Engine.Car.Exists(
                        sc =>
                        sc.X >= Engine.UserPanel.Width / 2 + 50 * (Engine.CurrentRoad.VerticalRoadRight - 2) &&
                        sc.X <= Engine.UserPanel.Width / 2 + 50 * (Engine.CurrentRoad.VerticalRoadRight - 1) &&
                        sc.Y <= Engine.UserPanel.Height / 2 - Engine.CurrentRoad.HorizontRoadUp * 40 + 65 &&
                        sc.Y >= Engine.UserPanel.Height / 2 - Engine.CurrentRoad.HorizontRoadUp * 40 - 65 &&
                        sc != c))
                {
                    return(true);
                }
                break;

            case Side.Right:
                if (!RoadPass.CenterFive(c) && Engine.Car.Exists(
                        sc =>
                        sc.X == c.X &&
                        c.Y - 60 <= sc.Y && c.Y - 10 >= sc.Y))
                {
                    return(true);
                }
                if (c.Turn == CTurn.Left && Engine.TrafficLights[3].CurrLight == TrafficLight.Lights.Green && c.Y <= Engine.UserPanel.Height / 2 + 15 && c.Y >= Engine.UserPanel.Height / 2 + 10)
                {
                    return(true);
                }
                if (c.Turn == CTurn.Right && c.Y >= Engine.UserPanel.Height / 2 + 50 * (Engine.CurrentRoad.HorizontRoadDown - 1) &&
                    c.Y <= Engine.UserPanel.Height / 2 + 50 * Engine.CurrentRoad.HorizontRoadDown - 45 &&
                    Engine.Car.Exists(
                        sc =>
                        sc.Y >= Engine.UserPanel.Height / 2 + 50 * (Engine.CurrentRoad.HorizontRoadDown - 2) &&
                        sc.Y <= Engine.UserPanel.Height / 2 + 50 * (Engine.CurrentRoad.HorizontRoadDown - 1) &&
                        sc.X <= Engine.UserPanel.Width / 2 + Engine.CurrentRoad.VerticalRoadRight * 40 + 45 &&
                        sc.X >= Engine.UserPanel.Width / 2 + Engine.CurrentRoad.VerticalRoadRight * 40 - 45 &&
                        sc != c))
                {
                    return(true);
                }
                break;

            case Side.Left:
                if (!RoadPass.CenterFive(c) && Engine.Car.Exists(
                        sc =>
                        sc.X == c.X &&
                        c.Y + 60 >= sc.Y && c.Y + 10 <= sc.Y))
                {
                    return(true);
                }
                if (c.Turn == CTurn.Left && Engine.TrafficLights[0].CurrLight == TrafficLight.Lights.Green && c.Y <= Engine.UserPanel.Height / 2 - 55 && c.Y >= Engine.UserPanel.Height / 2 - 60)
                {
                    return(true);
                }
                if (c.Turn == CTurn.Right && c.Y >= Engine.UserPanel.Height / 2 - 50 * (Engine.CurrentRoad.HorizontRoadDown + 1) + 20 &&
                    c.Y <= Engine.UserPanel.Height / 2 - 50 * Engine.CurrentRoad.HorizontRoadDown - 25 &&
                    Engine.Car.Exists(
                        sc =>
                        sc.Y >= Engine.UserPanel.Height / 2 - 50 * (Engine.CurrentRoad.HorizontRoadUp) &&
                        sc.Y <= Engine.UserPanel.Height / 2 - 50 * (Engine.CurrentRoad.HorizontRoadUp - 1) &&
                        sc.X <= Engine.UserPanel.Width / 2 - Engine.CurrentRoad.VerticalRoadLeft * 40 + 45 &&
                        sc.X >= Engine.UserPanel.Width / 2 - Engine.CurrentRoad.VerticalRoadLeft * 40 - 80 &&
                        sc != c))
                {
                    return(true);
                }
                break;
            }
            return(false);
        }