Пример #1
0
        /// <summary>
        /// This method updates the traffic lights state if needed.
        /// </summary>
        public void Update()
        {
            TrafficLight light = TrafficControl.FindLight(lightId); //search for this light

            if (light != null)
            {
                TimeSpan timePassed = Master.SimulationManager.CurTickTime - timeStamp;
                if (light.State == LightStates.RED)             //current state = red
                {
                    if (timePassed.TotalSeconds >= redDuration) //time for update
                    {
                        light.State = LightStates.GREEN;
                        timeStamp   = Master.SimulationManager.CurTickTime; //update the timestamp too
                        //Console.WriteLine("light " + light.Id + " updated to " + light.State + " after " + timePassed.TotalSeconds + " seconds");
                    }
                }
                else if (light.State == LightStates.GREEN)  //current state = green
                {
                    if (timePassed.TotalSeconds >= greenDuration)
                    {
                        light.State = LightStates.RED;
                        timeStamp   = Master.SimulationManager.CurTickTime;
                        //Console.WriteLine("light " + light.Id + " updated to " + light.State + " after " + timePassed.TotalSeconds + " seconds");
                    }
                }
            }
        }
        /// <summary>
        /// This method gets called by the system when a new incident (accident or natural disaster) has been simulated.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="connector"></param>
        /// <param name="involvedObjects"></param>
        /// <param name="roadDamage"></param>
        public static void IncidentHappened(IncidentType type, List <StreetConnector> connectors)
        {
            Incident incident = new Incident(type, connectors);

            TrafficControl.IncidentDetected(incident);
        }
Пример #3
0
 /// <summary>
 /// Creates the core instances of SS1.
 /// </summary>
 public static void Init()
 {
     control      = TrafficControl.GetInstance;
     lightManager = TrafficLightManager.GetInstance;
     detector     = TrafficDetection.GetInstance;
 }