Beispiel #1
0
        private CarDrawing getCarDrawingForAddAfterForOvetaking(CarDrawing cdForOvertaking, StripeDrawing stripeDrawingForOvertaking)
        {
            CarDrawing returnedCarDrawing = null;

            if (stripeDrawingForOvertaking.carsDrawings.Count > 0)
            {
                for (int i = 0; i < stripeDrawingForOvertaking.carsDrawings.Count - 1; i++)
                {
                    if (cdForOvertaking.car.initialSpeed < 0)
                    {
                        if (cdForOvertaking.X + 55 < stripeDrawingForOvertaking.carsDrawings.ElementAt(i).X&& cdForOvertaking.X > stripeDrawingForOvertaking.carsDrawings.ElementAt(i + 1).X + 55)
                        {
                            returnedCarDrawing = stripeDrawingForOvertaking.carsDrawings.ElementAt(i);
                        }
                    }
                    else if (cdForOvertaking.car.initialSpeed > 0)
                    {
                        if (cdForOvertaking.X - 55 > stripeDrawingForOvertaking.carsDrawings.ElementAt(i).X&& cdForOvertaking.X < stripeDrawingForOvertaking.carsDrawings.ElementAt(i + 1).X - 55)
                        {
                            returnedCarDrawing = stripeDrawingForOvertaking.carsDrawings.ElementAt(i);
                        }
                    }
                }
            }
            return(returnedCarDrawing);
        }
Beispiel #2
0
        //public void drawControlStripe(Graphics g, int coordX, int coordY, int width, int height)
        //{
        //}

        public void overtaking()
        {
            if (Road.getRoad().checkOppurtunityForOvertaking())
            {
                //for(int i =0; i < carsDrawings.Count; i++)

                for (int i = 0; i < carsDrawings.Count; i++)//foreach (CarDrawing cd in carsDrawings)
                {
                    CarDrawing cd = carsDrawings.ElementAt(i);
                    if (cd.car.overtaking == true)
                    {
                        Stripe stripeForOverTaking = Road.getRoad().getStripeForOvertaking(this.stripe,
                                                                                           cd.car.initialSpeed < 0 ? "RIGHT" : "LEFT");
                        StripeDrawing stripeDrawingForOvertaking = RoadDrawing.getRoadDrawing().getStripeDrawingForOverTaking(stripeForOverTaking);
                        Car           car = cd.car;
                        this.stripe.CARS.Remove(cd.car);
                        CarDrawing carDrawing = cd;
                        this.carsDrawings.Remove(cd);

                        if (cd.car.initialSpeed < 0)
                        {
                            if (stripeDrawingForOvertaking.carsDrawings.Count > 0)
                            {
                                if (stripeDrawingForOvertaking.carsDrawings.First.Value.X + 55 < cd.X)
                                {
                                    stripeDrawingForOvertaking.carsDrawings.AddFirst(cd);
                                    stripeDrawingForOvertaking.stripe.CARS.AddFirst(car);
                                    cd.Y              = stripeDrawingForOvertaking.Y + height / 2;
                                    cd.car.speed      = cd.car.initialSpeed;
                                    cd.car.overtaking = false;
                                }
                                else if (stripeDrawingForOvertaking.carsDrawings.Last.Value.X - 55 > cd.X)
                                {
                                    stripeDrawingForOvertaking.carsDrawings.AddLast(cd);
                                    stripeDrawingForOvertaking.stripe.CARS.AddLast(car);
                                    cd.Y              = stripeDrawingForOvertaking.Y + height / 2;
                                    cd.car.speed      = cd.car.initialSpeed;
                                    cd.car.overtaking = false;
                                }
                                else
                                {
                                    if (getCarDrawingForAddAfterForOvetaking(cd, stripeDrawingForOvertaking) != null)
                                    {
                                        stripeDrawingForOvertaking.carsDrawings.AddAfter(stripeDrawingForOvertaking.carsDrawings.Find(getCarDrawingForAddAfterForOvetaking(cd, stripeDrawingForOvertaking)), cd);
                                        stripeDrawingForOvertaking.stripe.CARS.AddLast(car);
                                        cd.Y              = stripeDrawingForOvertaking.Y + height / 2;
                                        cd.car.speed      = cd.car.initialSpeed;
                                        cd.car.overtaking = false;
                                    }
                                }
                            }
                            else
                            {
                                stripeDrawingForOvertaking.carsDrawings.AddFirst(cd);
                                stripeDrawingForOvertaking.stripe.CARS.AddFirst(car);
                                cd.Y              = stripeDrawingForOvertaking.Y + height / 2;
                                cd.car.speed      = cd.car.initialSpeed;
                                cd.car.overtaking = false;
                            }
                        }
                        else if (cd.car.initialSpeed > 0)
                        {
                            if (stripeDrawingForOvertaking.carsDrawings.Count > 0)
                            {
                                if (stripeDrawingForOvertaking.carsDrawings.First.Value.X - 55 > cd.X)
                                {
                                    stripeDrawingForOvertaking.carsDrawings.AddFirst(cd);
                                    stripeDrawingForOvertaking.stripe.CARS.AddFirst(cd.car);
                                    cd.Y              = stripeDrawingForOvertaking.Y + height / 2;
                                    cd.car.speed      = cd.car.initialSpeed;
                                    cd.car.overtaking = false;
                                }
                                else if (stripeDrawingForOvertaking.carsDrawings.Last.Value.X + 55 < cd.X)
                                {
                                    stripeDrawingForOvertaking.carsDrawings.AddFirst(cd);
                                    stripeDrawingForOvertaking.stripe.CARS.AddLast(car);
                                    cd.Y              = stripeDrawingForOvertaking.Y + height / 2;
                                    cd.car.speed      = cd.car.initialSpeed;
                                    cd.car.overtaking = false;
                                }
                                else
                                {
                                    if (getCarDrawingForAddAfterForOvetaking(cd, stripeDrawingForOvertaking) != null)
                                    {
                                        stripeDrawingForOvertaking.carsDrawings.AddAfter(stripeDrawingForOvertaking.carsDrawings.Find(getCarDrawingForAddAfterForOvetaking(cd, stripeDrawingForOvertaking)), cd);
                                        stripeDrawingForOvertaking.stripe.CARS.AddLast(car);
                                        cd.Y              = stripeDrawingForOvertaking.Y + height / 2;
                                        cd.car.speed      = cd.car.initialSpeed;
                                        cd.car.overtaking = false;
                                    }
                                }
                            }
                            else
                            {
                                stripeDrawingForOvertaking.carsDrawings.AddFirst(cd);
                                stripeDrawingForOvertaking.stripe.CARS.AddFirst(cd.car);
                                cd.Y              = stripeDrawingForOvertaking.Y + height / 2;
                                cd.car.speed      = cd.car.initialSpeed;
                                cd.car.overtaking = false;
                            }
                        }
                    }
                }
            }
        }