public void Light() { Timer.Instance.TimerWait(0.5f, () => { if (_previousLight.GetType() == typeof(TrafficLightGreenState)) { _trafficLight.ChangeState(_trafficLight.RedState); } else if (_previousLight.GetType() == typeof(TrafficLightRedState)) { _trafficLight.ChangeState(_trafficLight.GreenState); } }); }
public void Light() { Timer.Instance.TimerWait(5, () => { _trafficLight.ChangeState(_trafficLight.YellowState); }); }
static void Main() { string[] input = Console.ReadLine().Split(' ').ToArray(); int n = int.Parse(Console.ReadLine()); List <TrafficLight> allTrafficLights = new List <TrafficLight>(); foreach (var signal in input) { Signal signalNow = (Signal)Enum.Parse(typeof(Signal), signal); TrafficLight trafficLight = new TrafficLight(signalNow); allTrafficLights.Add(trafficLight); } for (int i = 0; i < n; i++) { foreach (var trafficLight in allTrafficLights) { trafficLight.ChangeState(); } Console.WriteLine(string.Join(" ", allTrafficLights)); } }