コード例 #1
0
        private void CrossingType(Crossing crossing)
        {
            string sPattern = @"[0-9]+";

            foreach (PictureBox pic in ControlList)
            {
                Match m      = Regex.Match(pic.Name, sPattern);
                int   number = Convert.ToInt32(m.Value);
                if (crossing.CrossingId == number)
                {
                    if (crossing.GetType() == typeof(Crossing_A))
                    {
                        pic.Image = ProCP.Properties.Resources.Crossing_a;
                    }
                    else if (crossing.GetType() == typeof(Crossing_B))
                    {
                        pic.Image = ProCP.Properties.Resources.Crossing_b;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the properties of the individual crossing
        /// </summary>
        /// <param name="id"></param>
        /// <param name="nCars"></param>
        /// <param name="time"></param>
        /// <param name="style"></param>
        public void getProperties(int id, ref int nCars, ref int time, ref string style)
        {
            Crossing cr = Crossings.Find(x => x.CrossingId == (id));

            nCars = cr.NumCars;
            time  = cr.Time.Seconds;

            if (cr.GetType() == typeof(Crossing_B))
            {
                Crossing_B cr1 = (Crossing_B)cr;
                //nPed = cr1.NumPeds;
                style = cr1.style;
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
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
            }
        }
コード例 #5
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
            }
        }
コード例 #6
0
        private void CrossingType(Crossing crossing)
        {
            string sPattern = @"[0-9]+";

            foreach (PictureBox pic in ControlList)
            {
                Match m = Regex.Match(pic.Name, sPattern);
                int number = Convert.ToInt32(m.Value);
                if (crossing.CrossingId == number)
                {
                    if (crossing.GetType() == typeof(Crossing_A))
                    {
                        pic.Image = ProCP.Properties.Resources.Crossing_a;
                    }
                    else if (crossing.GetType() == typeof(Crossing_B))
                    {
                        pic.Image = ProCP.Properties.Resources.Crossing_b;
                    }
                }

            }

        }