Esempio n. 1
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;
            }
        }
Esempio n. 2
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();
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
 private void initTopDraggedTrafficLightPictureBox()
 {
     startPoint = trafficLightPictureBox.Location;
     trafficLightPictureBoxIsCLicked             = true;
     topDraggedTrafficLightPictureBox.Image      = trafficLightPictureBox.Image;
     topDraggedTrafficLightPictureBox.Size       = trafficLightPictureBox.Size;
     topDraggedTrafficLightPictureBox.SizeMode   = PictureBoxSizeMode.StretchImage;
     topDraggedTrafficLightPictureBox.Location   = trafficLightPictureBox.Location;
     topDraggedTrafficLightPictureBox.MouseMove += (s, arg) =>
     {
         if (trafficLightPictureBoxIsCLicked)
         {
             topDraggedTrafficLightPictureBox.Left += trafficLightPictureBox.Location.X - startPoint.X;
             topDraggedTrafficLightPictureBox.Top  += trafficLightPictureBox.Location.Y - startPoint.Y;
         }
     };
     topDraggedTrafficLightPictureBox.MouseClick += (s, arg) =>
     {
         if (trafficLightPictureBoxIsCLicked)
         {
             //if чтобы положить его сожно только в mainPB
             if (Road.getRoad().COUNTOFWAYS == 2)
             {
                 bottomTrafficLightPictureBox.Image    = TrafficLightDrawing.getTrafficLightDrawing().DEFAULTSTATEBOTTOM;
                 bottomTrafficLightPictureBox.Size     = new Size(topDraggedTrafficLightPictureBox.Width * 2, mainPictureBox.Height / 14);
                 bottomTrafficLightPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
                 bottomTrafficLightPictureBox.Location = new Point(topDraggedTrafficLightPictureBox.Location.X, mainPictureBox.Height - topDraggedTrafficLightPictureBox.Location.Y + bottomTrafficLightPictureBox.Height);
                 this.Controls.Add(bottomTrafficLightPictureBox);
                 bottomTrafficLightPictureBox.BringToFront();
             }
             trafficLightPictureBoxIsCLicked         = false;
             trafficLightPictureBox.Enabled          = false;
             trafficLightPictureBox.Image            = Image.FromFile("..\\..\\images\\not_enabled_traffic_light_icon.jpeg");
             topDraggedTrafficLightPictureBox.Height = mainPictureBox.Height / 14;
             topDraggedTrafficLightPictureBox.Width *= 2;
             topDraggedTrafficLightPictureBox.Image  = TrafficLightDrawing.getTrafficLightDrawing().DEFAULTSTATETOP;
             SetTrafficLightForm setTrafficLightForm = new SetTrafficLightForm(true);
             setTrafficLightForm.Visible = true;
             LinkedList <TrafficLight> t = Road.getRoad().TRAFFICLIGHTS;
             TrafficLightDrawing.getTrafficLightDrawing().COORDINATS.AddLast(new Point[] { topDraggedTrafficLightPictureBox.Location
                                                                                           , bottomTrafficLightPictureBox.Location });
         }
         else
         {
             if (draggedTrafficLightPictureBoxIsClicked)
             {
                 draggedTrafficLightPictureBoxIsClicked = false;
                 TrafficLightDrawing.getTrafficLightDrawing().COORDINATS.RemoveLast();
                 TrafficLightDrawing.getTrafficLightDrawing().COORDINATS.AddLast(new Point[] { topDraggedTrafficLightPictureBox.Location
                                                                                               , bottomTrafficLightPictureBox.Location });
             }
             else
             {
                 draggedTrafficLightPictureBoxIsClicked = true;
             }
         }
     };
     topDraggedTrafficLightPictureBox.DoubleClick += (s, arg) =>
     {
         draggedTrafficLightPictureBoxIsClicked = false;
         SetTrafficLightForm ssf = new SetTrafficLightForm(false);
         ssf.ShowDialog();
     };
     this.Controls.Add(topDraggedTrafficLightPictureBox);
     topDraggedTrafficLightPictureBox.BringToFront();
 }
Esempio n. 5
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;
             }
         }
     }
 }
Esempio n. 6
0
        private void startButton_Click(object sender, EventArgs e)
        {
            if (checkTimeParamsForException() && checkSpeedParamsForExceptions())
            {
                labelForCarAppereanceTime.Visible  = true;
                labelForCarAppereanceValue.Visible = true;

                stopButton.Enabled = true;
                stopButton.Visible = true;
                switch (chooseTimeTypeComboBox.SelectedItem.ToString())
                {
                case ("Детерминированный"):
                    GeneratorsHolder.getGeneratorsHolder().TIMESGENERATOR = new DeterministicTimeGenerator(Double.Parse(timeTextBox.Text));
                    break;

                case ("Случайный"):
                    if (chooseTimeDistributionLawComboBox.SelectedItem.ToString().Equals("Показательный"))
                    {
                        GeneratorsHolder.getGeneratorsHolder().TIMESGENERATOR = new RandomTimeGenerator(new ExponentialDistribution(Double.Parse(timesFirstParTextBox.Text)));
                    }
                    else if (chooseTimeDistributionLawComboBox.SelectedItem.ToString().Equals("Равномерный"))
                    {
                        GeneratorsHolder.getGeneratorsHolder().TIMESGENERATOR = new RandomTimeGenerator(new UniformDistribution(Double.Parse(timesFirstParTextBox.Text), Double.Parse(timesSecondParTextBox.Text)));
                    }
                    else if (chooseTimeDistributionLawComboBox.SelectedItem.ToString().Equals("Нормальный"))
                    {
                        GeneratorsHolder.getGeneratorsHolder().TIMESGENERATOR = new RandomTimeGenerator(new NormalDistribution(Double.Parse(timesFirstParTextBox.Text), Double.Parse(timesSecondParTextBox.Text)));
                    }
                    break;

                default:
                    break;
                }

                switch (chooseSpeedTypeComboBox.SelectedItem.ToString())
                {
                case ("Детерминированный"):
                    GeneratorsHolder.getGeneratorsHolder().SPEEDSGENERATOR = new DeterministicSpeedGenerator(Double.Parse(speedTextBox.Text));
                    break;

                case ("Случайный"):
                    if (chooseSpeedDistributionLawComboBox.SelectedItem.ToString().Equals("Показательный"))
                    {
                        GeneratorsHolder.getGeneratorsHolder().SPEEDSGENERATOR = new RandomSpeedGenerator(new ExponentialDistribution(Double.Parse(speedsFirstParTextBox.Text)));
                    }
                    else if (chooseSpeedDistributionLawComboBox.SelectedItem.ToString().Equals("Равномерный"))
                    {
                        GeneratorsHolder.getGeneratorsHolder().SPEEDSGENERATOR = new RandomSpeedGenerator(new UniformDistribution(Double.Parse(speedsFirstParTextBox.Text), Double.Parse(speedsSecondParTextBox.Text)));
                    }
                    else if (chooseSpeedDistributionLawComboBox.SelectedItem.ToString().Equals("Нормальный"))
                    {
                        GeneratorsHolder.getGeneratorsHolder().SPEEDSGENERATOR = new RandomSpeedGenerator(new NormalDistribution(Double.Parse(speedsFirstParTextBox.Text), Double.Parse(speedsSecondParTextBox.Text)));
                    }
                    break;

                default:
                    break;
                }
                if (Road.getRoad().TRAFFICLIGHTS.Count > 0)
                {
                    TrafficLight tl = Road.getRoad().TRAFFICLIGHTS.First.Value;
                    trafficLightTimer.Interval             = tl.REDLIGHTTIME * 1000;
                    topDraggedTrafficLightPictureBox.Image = TrafficLightDrawing.getTrafficLightDrawing().REDSTATETOP;
                    if (Road.getRoad().COUNTOFWAYS == 2)
                    {
                        bottomTrafficLightPictureBox.Image = TrafficLightDrawing.getTrafficLightDrawing().REDSTATEBOTTOM;
                    }
                    tl.REDLIGHT = false;
                    trafficLightTimer.Start();
                    labelForTrafficLightTime.Visible  = true;
                    labelForTrafficLightValue.Visible = true;
                    labelForTrafficLightValue.Text    = (trafficLightTimer.Interval / 1000).ToString();
                }
                generateCarTimer.Interval       = (int)(GeneratorsHolder.getGeneratorsHolder().TIMESGENERATOR.getTime() * 1000);
                labelForCarAppereanceValue.Text = (generateCarTimer.Interval / 1000).ToString();
                generateCarTimer.Start();
                animationTimer.Start();
                timerForVisibility.Start();
            }
        }