Example #1
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();
        }
Example #2
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();
            }
        }