コード例 #1
0
ファイル: MainForm.cs プロジェクト: ERASERASERAS/ARDS
        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;
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: ERASERASERAS/ARDS
 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();
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: ERASERASERAS/ARDS
 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;
             }
         }
     }
 }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: ERASERASERAS/ARDS
        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();
            }
        }