Exemple #1
0
        /// <summary>
        /// Add a new cars the given crossing
        /// </summary>
        private void addCars(Crossing c)
        {
            ////////////add new cars to street E
            if (c.FlowE > c.EnteredE &&                                                 //if there are still cars to enter a crossing and
                c.StreetE.LaneEnter1[0] == null && c.StreetE.LaneEnter2[0] == null)   //there is an available slot at the entrance of the street
            {
                Car car = new Car();

                car.Street = c.StreetE;
                car.Crossing = c;
                car.Direction = Direction.West;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredE++;
                _listOfCars.Add(car);
                //car.move();
            }

            ////////////add new cars to street W
            if (c.FlowW > c.EnteredW &&                                                 //if there are still cars to enter a crossing and
                c.StreetW.LaneEnter1[0] == null && c.StreetW.LaneEnter2[0] == null)   //there is an available slot at the entrance of the street
            {

                Car car = new Car();

                car.Street = c.StreetW;
                car.Crossing = c;
                car.Direction = Direction.East;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredW++;
                _listOfCars.Add(car);
                //car.move();
            }

            ////////add new cars to street S
            if (c.FlowS > c.EnteredS &&                                                   //if there are still cars to enter a crossing and
                c.StreetS.LaneEnter1[0] == null                                           //there is an available slot at the entrance of lane enter 1
                && (c.GetType() == typeof(Crossing_2) || c.StreetS.LaneEnter2[0] == null))//and, in case its a crossing 1, there is an available slot at the entrance of lane 2
            {

                Car car = new Car();

                car.Street = c.StreetS;
                car.Crossing = c;
                car.Direction = Direction.North;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredS++;
                _listOfCars.Add(car);
                //car.move();
            }

            ////////add new cars to street N
            if (c.FlowN > c.EnteredN &&                                                   //if there are still cars to enter a crossing
                c.StreetN.LaneEnter1[0] == null                                           //and if there is an available slot at the entrance of lane enter 1
                && (c.GetType() == typeof(Crossing_2) || c.StreetN.LaneEnter2[0] == null))//and, unless it's a crossing_2, if there is an available slot at the entrance of lane 2
            {
                Car car = new Car();

                car.Street = c.StreetN;
                car.Crossing = c;
                car.Direction = Direction.South;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredN++;
                _listOfCars.Add(car);
                //car.move();
            }
        }
Exemple #2
0
        /// <summary>
        /// Displays all the info of a crossing on the right pane
        /// </summary>
        /// <param name="c">crossing whose properties will be displayed</param>
        public void displayCrossingSettings(Crossing c)
        {
            if (c != null)
            {
                //if its stopped, enables textboxes, otherwise disables them
                foreach (TextBox tb in _crossingProperties)
                {
                    tb.Enabled = _controller.State == State.Stopped;
                    if(tb.Enabled)
                        tb.BackColor = Color.White;
                    else
                        tb.BackColor = TextBoxBase.DefaultBackColor;
                }

                if (c.GetType() == typeof(Crossing_1))
                {
                    Crossing_1 cr1 = (Crossing_1)c;
                    label5.Text = "N-->SW  and  S-->NE";
                    label6.Text = "N-->E      and  S-->W";

                    textBoxGLT1.Text = cr1.LightNtoWS._greenLightTime.ToString();
                    textBoxGLT2.Text = cr1.LightNtoE._greenLightTime.ToString();
                    textBoxGLT3.Text = cr1.LightWtoN._greenLightTime.ToString();
                    textBoxGLT4.Text = cr1.LightWtoSE._greenLightTime.ToString();
                    textBoxTF1.Text = cr1.FlowN.ToString();
                    textBoxTF2.Text = cr1.FlowE.ToString();
                    textBoxTF3.Text = cr1.FlowS.ToString();
                    textBoxTF4.Text = cr1.FlowW.ToString();
                    textBoxCTNE.Text = cr1.ProbNtoE.ToString();
                    textBoxCTNS.Text = cr1.ProbNtoS.ToString();
                    textBoxCTNW.Text = cr1.ProbNtoW.ToString();
                    textBoxCTEN.Text = cr1.ProbEtoN.ToString();
                    textBoxCTES.Text = cr1.ProbEtoS.ToString();
                    textBoxCTEW.Text = cr1.ProbEtoW.ToString();
                    textBoxCTSN.Text = cr1.ProbStoN.ToString();
                    textBoxCTSE.Text = cr1.ProbStoE.ToString();
                    textBoxCTSW.Text = cr1.ProbStoW.ToString();
                    textBoxCTWN.Text = cr1.ProbWtoN.ToString();
                    textBoxCTWE.Text = cr1.ProbWtoE.ToString();
                    textBoxCTWS.Text = cr1.ProbWtoS.ToString();
                }

                if (c.GetType() == typeof(Crossing_2))
                {
                    Crossing_2 cr2 = (Crossing_2)c;
                    label5.Text = "Pedestrians";
                    label6.Text = "N-->S      and  S-->N";

                    textBoxGLT1.Text = cr2.LightPedestrian._greenLightTime.ToString();
                    textBoxGLT2.Text = cr2.LightNtoS._greenLightTime.ToString();
                    textBoxGLT3.Text = cr2.LightWtoN._greenLightTime.ToString();
                    textBoxGLT4.Text = cr2.LightWtoSE._greenLightTime.ToString();
                    textBoxTF1.Text = cr2.FlowN.ToString();
                    textBoxTF2.Text = cr2.FlowE.ToString();
                    textBoxTF3.Text = cr2.FlowS.ToString();
                    textBoxTF4.Text = cr2.FlowW.ToString();
                    textBoxCTNE.Text = cr2.ProbNtoE.ToString();
                    textBoxCTNS.Text = cr2.ProbNtoS.ToString();
                    textBoxCTNW.Text = cr2.ProbNtoW.ToString();
                    textBoxCTEN.Text = cr2.ProbEtoN.ToString();
                    textBoxCTES.Text = cr2.ProbEtoS.ToString();
                    textBoxCTEW.Text = cr2.ProbEtoW.ToString();
                    textBoxCTSN.Text = cr2.ProbStoN.ToString();
                    textBoxCTSE.Text = cr2.ProbStoE.ToString();
                    textBoxCTSW.Text = cr2.ProbStoW.ToString();
                    textBoxCTWN.Text = cr2.ProbWtoN.ToString();
                    textBoxCTWE.Text = cr2.ProbWtoE.ToString();
                    textBoxCTWS.Text = cr2.ProbWtoS.ToString();
                }
            }
            else//if no crossing is selected
            {
                foreach (TextBox tb in _crossingProperties)
                {
                    if (tb.Focused)
                        buttonShowHideGLT.Focus();
                    tb.Text = "";
                    tb.Enabled = false;
                    tb.BackColor = TextBoxBase.DefaultBackColor;
                }
            }
            foreach (TextBox tb in _crossingProperties)
            {
                tb.Modified = false;
            }
        }