Ejemplo n.º 1
0
        /// <summary>
        /// Edits the properties of the crossing
        /// eg. number of cars for that crossing, time the light is green, etc.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="numCars"></param>
        /// <param name="time"></param>
        /// <param name="style"></param>
        public void EditCrossing(int id, int numCars, int time, string style)
        {
            Crossing cr = Crossings.Find(x => x.CrossingId == (id));

            if (cr.GetType() == typeof(Crossing_A))
            {
                cr.NumCars = numCars;
                cr.Time    = new TimeSpan(0, 0, time);
            }
            else
            {
                Crossing_B cr1 = (Crossing_B)cr;
                cr1.NumCars = numCars;
                cr1.Time    = new TimeSpan(0, 0, time);
                cr1.style   = style;
                cr1.CreatePedestrians();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// changes the lights to the next iteration
        /// </summary>
        /// <param name="c"></param>
        public void SwitchAll(Crossing c)
        {
            TotalNumberofSwitches++;

            if (c.GetType() == typeof(Crossing_A))
            {
                /*
                 #region A Crossing
                 *
                 * foreach (TrafficLane l in c.Lanes)
                 * {
                 *  if (l.TrafficLight != null)
                 *  {
                 *      if (l.Direction == (Direction)(c.Turn - 1))
                 *      {
                 *          l.TrafficLight.State = true;
                 *      }
                 *      else
                 *      {
                 *          l.TrafficLight.State = false;
                 *      }
                 *  }
                 *  c.Turn = ((c.Turn + 1) % 4);
                 *
                 *  if (c.Turn == 0)
                 *      c.Turn = 1;
                 * }
                 *
                 #endregion
                 */

                #region A Crossing
                switch (c.Turn)
                {
                case 1:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.NORTH)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn++;
                    break;

                case 2:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.EAST)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn++;
                    break;

                case 3:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.SOUTH)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn++;
                    break;

                case 4:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.WEST)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn = 1;
                    break;
                }
                #endregion
            }
            else
            {
                #region B Crossing


                Crossing_B cb = (Crossing_B)c;
                switch (c.Turn)
                {
                case 1:
                    cb.ATimer.Interval = 1000 * cb.Time.Seconds;
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.NORTH || l.Direction == Direction.SOUTH)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    foreach (PedestrianLane pl in cb.pLanes)
                    {
                        if (pl.PLight != null)
                        {
                            pl.PLight.State = false;
                        }
                    }
                    c.Turn++;
                    break;

                case 2:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.EAST)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn++;
                    break;

                case 3:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.WEST)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    bool sensor = false;
                    cb.CreatePedestrians();
                    foreach (PedestrianLane pl in cb.pLanes)
                    {
                        if (pl.PLight.Sensor)
                        {
                            sensor = true;
                        }
                    }
                    if (sensor)
                    {
                        c.Turn++;
                    }
                    else
                    {
                        c.Turn = 1;
                    }
                    break;

                case 4:
                    if (cb.style == "Quiet")
                    {
                        cb.ATimer.Interval = (int)(1000 * (double)cb.Time.Seconds * 0.25);
                    }
                    else
                    {
                        cb.ATimer.Interval = (int)(1000 * (double)cb.Time.Seconds * 0.75);
                    }
                    foreach (PedestrianLane pl in cb.pLanes)
                    {
                        if (pl.PLight != null)
                        {
                            pl.PLight.State = true;
                        }
                    }
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            l.TrafficLight.State = false;
                        }
                    }
                    c.Turn = 1;
                    break;
                }
                #endregion
            }
        }