Exemplo n.º 1
0
 private void resetButton_Click(object sender, EventArgs e)
 {
     if (Road.getRoad().TRAFFICLIGHTS.Count > 0)
     {
         this.Controls.Remove(topDraggedTrafficLightPictureBox);
         if (Road.getRoad().COUNTOFWAYS == 2)
         {
             this.Controls.Remove(bottomTrafficLightPictureBox);
         }
         trafficLightPictureBox.Enabled = true;
         trafficLightPictureBox.Image   = Image.FromFile("..\\..\\images\\traffic_light_icon.jpg");
     }
     foreach (PictureBox pb in signsPictureBoxes)
     {
         this.Controls.Remove(pb);
     }
     //Road.getRoad().clearRoad();
     RoadDrawing.getRoadDrawing().clearRoadDrawing(mainPictureBox.CreateGraphics());
     resetButton.Enabled  = false;
     resetButton.Visible  = false;
     stopButton.Enabled   = false;
     stopButton.Visible   = false;
     resumeButton.Enabled = false;
     resumeButton.Visible = false;
     labelForCarAppereanceValue.Visible = false;
     labelForCarAppereanceTime.Visible  = false;
     labelForTrafficLightTime.Visible   = false;
     labelForTrafficLightValue.Visible  = false;
 }
Exemplo n.º 2
0
        private void mainPictureBox_Paint(object sender, PaintEventArgs e)
        {
            //getRoadDrawing().drawRoad(mainPictureBox.CreateGraphics(), mainPictureBox.Width, mainPictureBox.Height);
            RoadDrawing.getRoadDrawing().drawRoad(e.Graphics, mainPictureBox.Width, mainPictureBox.Height);
            LinkedList <StripeDrawing> stripeDrawings = RoadDrawing.getRoadDrawing().STRIPEDRAWINGS;

            foreach (StripeDrawing sd in stripeDrawings)
            {
                foreach (CarDrawing cd in sd.carsDrawings)
                {
                    cd.drawCar(e.Graphics);
                }
            }
        }
Exemplo n.º 3
0
        private void drawRoadButton_Click(object sender, EventArgs e)
        {
            if (Road.getRoad().COUNTOFWAYS > 1)//нарисована ли уже  дорога ?
            {
                RoadDrawing.getRoadDrawing().clearRoadDrawing(mainPictureBox.CreateGraphics());
                Road.getRoad().clearRoad();
            }
            Road.getRoad().COUNTOFSTRIPES = (int)chooseStripesCountNumericUpDown.Value;
            switch (chooseCountWayComboBox.SelectedItem.ToString())
            {
            case ("Однонаправленная"):
                Road.getRoad().COUNTOFWAYS = 1;
                Way way = new Way("LEFT");
                for (int i = 0; i < Road.getRoad().COUNTOFSTRIPES; i++)
                {
                    way.addStripe(new Stripe());
                }
                Road.getRoad().WAYS.AddLast(way);
                break;

            case ("Двунаправленная"):
                Road.getRoad().COUNTOFWAYS = 2;
                Way leftWay           = new Way("LEFT");
                Way rightWay          = new Way("RIGHT");
                LinkedList <Way> ways = new LinkedList <Way>();
                ways.AddLast(leftWay);
                ways.AddLast(rightWay);
                foreach (Way someWay in ways)
                {
                    for (int i = 0; i < Road.getRoad().COUNTOFSTRIPES; i++)
                    {
                        someWay.stripes.AddLast(new Stripe());
                    }
                }
                Road.getRoad().WAYS = ways;

                break;

            default:
                break;
            }

            Road r = Road.getRoad();

            Road.getRoad().ROADTYPE = chooseRoadTypeComboBox.SelectedItem.ToString();
            ConstrainsInstaller.setConstrains(chooseRoadTypeComboBox.SelectedItem.ToString());
            //new RoadDrawing(mainPictureBox.CreateGraphics(), mainPictureBox.Width, mainPictureBox.Height).drawRoad();
            RoadDrawing.getRoadDrawing().drawRoad(mainPictureBox.CreateGraphics(), mainPictureBox.Width, mainPictureBox.Height);
        }
Exemplo n.º 4
0
        private void generateCarTimer_Tick(object sender, EventArgs e)
        {
            Car        newCar        = new Car((int)GeneratorsHolder.getGeneratorsHolder().SPEEDSGENERATOR.getSpeed());
            CarDrawing newCarDrawing = new CarDrawing("..\\..\\images\\cars\\car" + rnd.Next(1, 5).ToString() + ".png", newCar);

            newCarDrawing.car = newCar;
            Stripe randomStripe = new Stripe();;
            Way    randomWay    = new Way();
            //int i = 0;
            //while (i < Road.getRoad().COUNTOFSTRIPES)
            //{
            int randowWayNumber = rnd.Next(0, Road.getRoad().COUNTOFWAYS);

            randomWay = Road.getRoad().WAYS.ElementAt(randowWayNumber);
            int randomStripeNumber = rnd.Next(0, randomWay.stripes.Count);

            randomStripe = randomWay.stripes.ElementAt(randomStripeNumber);
            foreach (StripeDrawing sd in RoadDrawing.getRoadDrawing().STRIPEDRAWINGS)
            {
                if (randomStripe.Equals(sd.stripe))
                {
                    if (sd.canGenerateNewCar(randomWay.way.Equals("LEFT") ? mainPictureBox.Width : 0, randomWay.way.Equals("LEFT") ? -1 : 1))
                    {
                        sd.carsDrawings.AddLast(newCarDrawing);
                        if (randomWay.way.Equals("RIGHT"))
                        {
                            newCar.speed       *= -1;
                            newCar.initialSpeed = newCar.speed;
                            newCarDrawing.carImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                            newCarDrawing.X = sd.X;
                            newCarDrawing.Y = sd.Y + mainPictureBox.Height / 14;
                        }
                        else
                        {
                            newCarDrawing.X = sd.X + mainPictureBox.Width;
                            newCarDrawing.Y = sd.Y + mainPictureBox.Height / 14;
                        }
                        mainPictureBox.Invalidate();
                    }
                }
            }
            //++i;
            //}

            randomStripe.addCar(newCar);
            generateCarTimer.Interval       = (int)(GeneratorsHolder.getGeneratorsHolder().TIMESGENERATOR.getTime() * 1000);
            labelForCarAppereanceValue.Text = (generateCarTimer.Interval / 1000).ToString();
        }
Exemplo n.º 5
0
        private void setTrafficLight()
        {
            TrafficLightDrawing t  = TrafficLightDrawing.getTrafficLightDrawing();
            TrafficLight        tl = Road.getRoad().TRAFFICLIGHTS.First.Value;

            if (tl.REDLIGHT)
            {
                trafficLightTimer.Interval             = tl.REDLIGHTTIME * 1000;
                labelForTrafficLightValue.Text         = tl.REDLIGHTTIME.ToString();
                topDraggedTrafficLightPictureBox.Image = t.REDSTATETOP;
                bottomTrafficLightPictureBox.Image     = t.REDSTATEBOTTOM;
                tl.REDLIGHT = false;
            }
            else
            {
                RoadDrawing.getRoadDrawing().resumeCarsTraffic();
                trafficLightTimer.Interval             = tl.GREENLIGHTTIME * 1000;
                labelForTrafficLightValue.Text         = tl.GREENLIGHTTIME.ToString();
                topDraggedTrafficLightPictureBox.Image = t.GREENSTATETOP;
                bottomTrafficLightPictureBox.Image     = t.GREENSTATEBOTTOM;
                tl.REDLIGHT = true;
            }
        }
Exemplo n.º 6
0
        private void animationTimer_Tick(object sender, EventArgs e)
        {
            LinkedList <StripeDrawing> stripeDrawings = RoadDrawing.getRoadDrawing().STRIPEDRAWINGS;

            if (Road.getRoad().TRAFFICLIGHTS.First != null)
            {
                if (!Road.getRoad().TRAFFICLIGHTS.First.Value.REDLIGHT)
                {
                    RoadDrawing.getRoadDrawing().stopCars(topDraggedTrafficLightPictureBox.Width, mainPictureBox.Location.X);
                }
            }
            if (Road.getRoad().ROADTYPE.Equals("Тоннель"))
            {
                foreach (Way way in Road.getRoad().WAYS)
                {
                    foreach (Stripe stripe in way.stripes)
                    {
                        if (stripe.CARS.First != null)
                        {
                            stripe.CARS.First.Value.speed = (int)firstCarSpeedNumericUpDown.Value;
                        }
                    }
                }
            }
            foreach (StripeDrawing sd in stripeDrawings)
            {
                LinkedList <CarDrawing> carDrawings = sd.carsDrawings;
                if (carDrawings.Count > 0)
                {
                    if (carDrawings.First.Value.car.speed < 0)
                    {
                        if (sd.firstCarIsLeaved(mainPictureBox.Width))
                        {
                            sd.stripe.CARS.Remove(sd.carsDrawings.First.Value.car);
                            sd.carsDrawings.RemoveFirst();
                            //sd.stripe.CARS.RemoveFirst();
                        }
                    }
                    else
                    {
                        if (sd.firstCarIsLeaved(0))
                        {
                            sd.carsDrawings.RemoveFirst();
                            sd.stripe.CARS.RemoveFirst();
                        }
                    }
                }
                sd.correctSpeeds();
                sd.overtaking();
                foreach (CarDrawing cd in carDrawings) //void move()
                {
                    cd.X -= cd.car.speed;
                }
                // Road r = Road.getRoad();
                if (Road.getRoad().SIGNS.Count > 0)
                {
                    if (Road.getRoad().COUNTOFWAYS == 2)
                    {
                        RoadDrawing.getRoadDrawing().correctSpeedBySigns(mainPictureBox.Height / 2, mainPictureBox.Location.X);
                    }
                    else
                    {
                        RoadDrawing.getRoadDrawing().correctSpeedBySigns(mainPictureBox.Location.X);
                    }
                }
            }
            mainPictureBox.Invalidate();
        }
Exemplo n.º 7
0
        private void initTopDraggedSignPictureBox() //args PictureBox...?????
        {
            startPoint = signPictureBox.Location;
            PictureBox newSignPictureBox = new PictureBox();

            signPictureBoxIsClicked     = true;
            newSignPictureBox.Image     = signPictureBox.Image;
            newSignPictureBox.Size      = signPictureBox.Size;
            newSignPictureBox.SizeMode  = PictureBoxSizeMode.StretchImage;
            newSignPictureBox.Location  = signPictureBox.Location;
            newSignPictureBox.BackColor = Color.WhiteSmoke;

            newSignPictureBox.MouseMove += (s, arg) =>
            {
                if (signPictureBoxIsClicked)
                {
                    newSignPictureBox.Left += signPictureBox.Location.X - startPoint.X;
                    newSignPictureBox.Top  += signPictureBox.Location.Y - startPoint.Y;
                }
            };
            newSignPictureBox.MouseClick += (s, arg) =>
            {
                if (signPictureBoxIsClicked)
                {
                    //if чтобы положить его сожно только в mainPB


                    signPictureBoxIsClicked  = false;
                    newSignPictureBox.Height = mainPictureBox.Height / 14;
                    newSignPictureBox.Width  = newSignPictureBox.Height;
                    SignDrawing addedSignDrawing = new SignDrawing();
                    addedSignDrawing.COORDINATS = newSignPictureBox.Location;
                    //signDrawings.AddLast(addedSignDrawing);
                    RoadDrawing.getRoadDrawing().signDrawings.AddLast(addedSignDrawing);
                    if (RoadDrawing.getRoadDrawing().signDrawings.Count == 4)
                    {
                        signPictureBox.Enabled = false;
                        signPictureBox.Image   = Image.FromFile("..\\..\\images\\not_enabled_sign_icon.png");
                    }
                    SetSignForm setSignForm = new SetSignForm(addedSignDrawing);
                    setSignForm.ShowDialog();
                    Road.getRoad().SIGNS.AddLast(addedSignDrawing.SIGN);
                    addedSignDrawing.getSignGraphic(Graphics.FromImage(newSignPictureBox.Image));
                    signsPictureBoxes.AddLast(newSignPictureBox);
                    newSignPictureBox.Invalidate(); newSignPictureBox.Invalidate(); newSignPictureBox.Invalidate();
                }
                else
                {
                    if (draggedSignPictureBoxIsClicked)
                    {
                        draggedSignPictureBoxIsClicked = false;
                        PictureBox pb = (PictureBox)s;
                        foreach (SignDrawing sd in RoadDrawing.getRoadDrawing().signDrawings)
                        {
                            if ((sd.COORDINATS.X == previousCoordinats.X) && (sd.COORDINATS.Y == previousCoordinats.Y))
                            {
                                sd.COORDINATS = pb.Location;
                            }
                        }
                    }
                    else
                    {
                        draggedSignPictureBoxIsClicked = true;
                        newSignPictureBoxMain          = signsPictureBoxes.Find((PictureBox)s).Value;
                        previousCoordinats             = newSignPictureBoxMain.Location;
                    }
                }
            };
            newSignPictureBox.DoubleClick += (s, arg) =>
            {
                draggedSignPictureBoxIsClicked = false;
                PictureBox pb = (PictureBox)s;
                foreach (SignDrawing sg in RoadDrawing.getRoadDrawing().signDrawings)
                {
                    if (sg.COORDINATS == pb.Location)
                    {
                        SetSignForm ssf = new SetSignForm(sg);
                        ssf.ShowDialog();
                        sg.getSignGraphic(Graphics.FromImage(pb.Image));
                        pb.Invalidate();
                    }
                }
                pb.Invalidate(); pb.Invalidate();
                newSignPictureBox.Invalidate(); newSignPictureBox.Invalidate(); newSignPictureBox.Invalidate();
            };

            newSignPictureBox.Paint += (s, arg) =>
            {
                PictureBox pb = (PictureBox)s;

                foreach (SignDrawing sg in RoadDrawing.getRoadDrawing().signDrawings)
                {
                    if (sg.COORDINATS.X == pb.Location.X && sg.COORDINATS.Y == pb.Location.Y)
                    {
                        sg.getSignGraphic(Graphics.FromImage(pb.Image));
                    }
                }
            };


            this.Controls.Add(newSignPictureBox);
            newSignPictureBoxMain = newSignPictureBox;
            signPictureBox.Image  = Image.FromFile("..\\..\\images\\sign_icon.png");
            newSignPictureBox.BringToFront();
        }
Exemplo n.º 8
0
 private void mainPictureBox_MouseMove(object sender, MouseEventArgs e)
 {
     if (signPictureBoxIsClicked)
     {
         newSignPictureBoxMain.Location = new Point(e.X + mainPictureBox.Location.X, e.Y + mainPictureBox.Location.Y);
     }
     else
     {
         if (draggedSignPictureBoxIsClicked)
         {
             newSignPictureBoxMain.Location = new Point(e.X + mainPictureBox.Location.X, newSignPictureBoxMain.Location.Y);
             if (newSignPictureBoxMain.Location.X + newSignPictureBoxMain.Width / 10 > mainPictureBox.Width + mainPictureBox.Location.X)
             {
                 SignDrawing removableSignDrawing = null;
                 foreach (SignDrawing sg in RoadDrawing.getRoadDrawing().signDrawings)
                 {
                     if (sg.COORDINATS.X == previousCoordinats.X && sg.COORDINATS.Y == previousCoordinats.Y)
                     {
                         removableSignDrawing = sg;
                     }
                 }
                 RoadDrawing.getRoadDrawing().signDrawings.Remove(removableSignDrawing);
                 if (RoadDrawing.getRoadDrawing().signDrawings.Count == 3)
                 {
                     signPictureBox.Enabled = true;
                     signPictureBox.Image   = Image.FromFile("..\\..\\images\\sign_icon.png");
                 }
                 this.Controls.Remove(newSignPictureBoxMain);
                 signsPictureBoxes.Remove(newSignPictureBoxMain);
                 draggedSignPictureBoxIsClicked = false;
             }
         }
     }
     if (trafficLightPictureBoxIsCLicked)
     {
         topDraggedTrafficLightPictureBox.Location = new Point(e.X + mainPictureBox.Location.X, e.Y + mainPictureBox.Location.Y);
     }
     else
     {
         if (draggedTrafficLightPictureBoxIsClicked)
         {
             topDraggedTrafficLightPictureBox.Location = new Point(e.X + mainPictureBox.Location.X, topDraggedTrafficLightPictureBox.Location.Y);
             if (Road.getRoad().COUNTOFWAYS == 2)
             {
                 bottomTrafficLightPictureBox.Location = new Point(e.X + mainPictureBox.Location.X, bottomTrafficLightPictureBox.Location.Y);
             }
             if (topDraggedTrafficLightPictureBox.Location.X + topDraggedTrafficLightPictureBox.Width / 10 > mainPictureBox.Width + mainPictureBox.Location.X)
             {
                 if (Road.getRoad().COUNTOFWAYS == 2)
                 {
                     this.Controls.Remove(bottomTrafficLightPictureBox);
                 }
                 this.Controls.Remove(topDraggedTrafficLightPictureBox);
                 TrafficLightDrawing.getTrafficLightDrawing().COORDINATS.Clear();
                 Road.getRoad().TRAFFICLIGHTS.Clear();
                 foreach (StripeDrawing sd in RoadDrawing.getRoadDrawing().STRIPEDRAWINGS)
                 {
                     foreach (CarDrawing cd in sd.carsDrawings)
                     {
                         if (cd.car.stayByTrafficLight)
                         {
                             cd.car.stayByTrafficLight = false;
                             cd.car.speed = cd.car.initialSpeed;
                         }
                     }
                 }
                 trafficLightTimer.Stop();
                 trafficLightPictureBox.Enabled         = true;
                 trafficLightPictureBox.Image           = Image.FromFile("..\\..\\images\\traffic_light_icon.jpg");
                 draggedTrafficLightPictureBoxIsClicked = false;
             }
         }
     }
 }