Exemplo n.º 1
0
        private void drawTonnel(Graphics g, int width, int height)
        {
            StripeDrawing sd = new StripeDrawing(0, height / 2 - height / 14); //7 - потому что максимум 6 полос + 2 полосы для знаков и светофоров(эти полосы равны половине от обычных)

            sd.drawStripe(g, width, height / 7);
            sd.stripe = Road.getRoad().WAYS.First.Value.stripes.First.Value;
            stripeDrawings.AddLast(sd);
        }
Exemplo n.º 2
0
        public StripeDrawing getStripeDrawingForOverTaking(Stripe stripeForOverTaking)
        {
            StripeDrawing returnedStripeDrawing = null;

            foreach (StripeDrawing sd in stripeDrawings)
            {
                if (sd.stripe.Equals(stripeForOverTaking))
                {
                    returnedStripeDrawing = sd;
                }
            }
            return(returnedStripeDrawing);
        }
Exemplo n.º 3
0
        private void drawMagistral(Graphics g, int width, int height)
        {
            g.Clear(Color.WhiteSmoke);

            if (Road.getRoad().COUNTOFWAYS == 2)
            {
                for (int i = 0; i < Road.getRoad().COUNTOFSTRIPES; i++)
                {
                    StripeDrawing leftWaySD = new StripeDrawing(0, height / 2 - (i + 1) * height / 7);
                    leftWaySD.stripe = Road.getRoad().WAYS.First.Value.stripes.ElementAt(i);
                    leftWaySD.drawStripe(g, width, height / 7);
                    stripeDrawings.AddLast(leftWaySD);
                    StripeDrawing rightWaySD = new StripeDrawing(0, height / 2 + i * height / 7);
                    rightWaySD.stripe = Road.getRoad().WAYS.Last.Value.stripes.ElementAt(i);
                    rightWaySD.drawStripe(g, width, height / 7);
                    stripeDrawings.AddLast(rightWaySD);
                    if (i < Road.getRoad().COUNTOFSTRIPES - 1)
                    {
                        LineDrawing ld1 = new LineDrawing(0, height / 2 - (i + 1) * height / 7, width, height / 2 - (i + 1) * height / 7);
                        ld1.drawBrokenLine(g);
                        ld1.whichLine = true;
                        lineDrawings.AddLast(ld1);
                        LineDrawing ld2 = new LineDrawing(0, height / 2 + (i + 1) * height / 7 - 2, width, height / 2 + (i + 1) * height / 7 - 2);
                        ld2.drawBrokenLine(g);
                        ld2.whichLine = true;
                        lineDrawings.AddLast(ld2);

                        //lineDrawing.drawBrokenLine(g, 0, height / 2 - (i + 1) * height / 7, width, height / 2 - (i + 1) * height / 7);
                        //lineDrawing.drawBrokenLine(g, 0, height / 2 + (i + 1) * height / 7 - 2, width, height / 2 + (i + 1) * height / 7 - 2);
                    }
                }
                //lineDrawing.drawSolidLine(g, 0, height / 2 - 1, width, height / 2 - 1);
                //lineDrawing.drawSolidLine(g, 0, height / 2 + 1, width, height / 2 + 1);
                LineDrawing solidLD1 = new LineDrawing(0, height / 2 - 1, width, height / 2 - 1);
                solidLD1.drawSolidLine(g);
                solidLD1.whichLine = false;
                lineDrawings.AddLast(solidLD1);
                LineDrawing solidLD2 = new LineDrawing(0, height / 2 + 1, width, height / 2 + 1);
                solidLD2.drawSolidLine(g);
                solidLD2.whichLine = false;
                lineDrawings.AddLast(solidLD2);
            }
            else
            {
                if (Road.getRoad().COUNTOFSTRIPES % 2 == 0)
                {
                    for (int i = 0; i < Road.getRoad().COUNTOFSTRIPES; i++)
                    {
                        StripeDrawing sd = new StripeDrawing(0, height / 2 + (Road.getRoad().COUNTOFSTRIPES / 2 - 1) * height / 7 - i * height / 7);
                        sd.stripe = Road.getRoad().WAYS.First.Value.stripes.ElementAt(i);
                        sd.drawStripe(g, width, height / 7);
                        if (i < Road.getRoad().COUNTOFSTRIPES - 1)
                        {
                            //lineDrawing.drawBrokenLine(g, 0, height / 2 + (Road.getRoad().COUNTOFSTRIPES / 2 - 1) * height / 7 - i * height / 7, width,
                            //                                height / 2 + (Road.getRoad().COUNTOFSTRIPES / 2 - 1) * height / 7 - i * height / 7);
                            LineDrawing ld = new LineDrawing(0, height / 2 + (Road.getRoad().COUNTOFSTRIPES / 2 - 1) * height / 7 - i * height / 7, width,
                                                             height / 2 + (Road.getRoad().COUNTOFSTRIPES / 2 - 1) * height / 7 - i * height / 7);
                            ld.drawBrokenLine(g);
                            ld.whichLine = true;
                            lineDrawings.AddLast(ld);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < Road.getRoad().COUNTOFSTRIPES; i++)
                    {
                        StripeDrawing sd = new StripeDrawing(0, height / 2 + (Road.getRoad().COUNTOFSTRIPES - 3) / 2 *
                                                             height / 7 + height / 14 - i * height / 7);
                        sd.drawStripe(g, width, height / 7);
                        sd.stripe = Road.getRoad().WAYS.First.Value.stripes.ElementAt(i);     //пофиксить ошибку с вылетом(выход за пределы)
                        stripeDrawings.AddLast(sd);
                        if (i < Road.getRoad().COUNTOFSTRIPES - 1)
                        {
                            //lineDrawing.drawBrokenLine(g, 0, height / 2 + (Road.getRoad().COUNTOFSTRIPES - 3) / 2 *
                            //                                    height / 7 + height / 14 - i * height / 7, width, height / 2 + (Road.getRoad().COUNTOFSTRIPES - 3) / 2 *
                            //                                    height / 7 + height / 14 - i * height / 7);
                            LineDrawing ld = new LineDrawing(0, height / 2 + (Road.getRoad().COUNTOFSTRIPES - 3) / 2 *
                                                             height / 7 + height / 14 - i * height / 7, width, height / 2 + (Road.getRoad().COUNTOFSTRIPES - 3) / 2 *
                                                             height / 7 + height / 14 - i * height / 7);
                            ld.drawBrokenLine(g);
                            ld.whichLine = true;
                            lineDrawings.AddLast(ld);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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;
                            }
                        }
                    }
                }
            }
        }