static void Main(string[] args) { ITrafficLightFactory factory = new TrafficLightFactory(); ITrafficLightController[] controllers = { new AdditionalTrafficLightController(), new StandartTrafficLightController(), new PedestrianTrafficLightController() }; var trafficLights = controllers.Select(tl => factory.Create(tl)); foreach (var trafficLight in trafficLights) { trafficLight.Start(); } Console.ReadKey(); }
static void Main(string[] args) { TrafficLightFactory factory = new TrafficLightFactory(); string[] inputLights = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); List <TrafficLight> trafficLights = new List <TrafficLight>(); for (int index = 0; index < inputLights.Length; index++) { var currentTrafficLight = factory.CreateTrafficLight(inputLights[index]); trafficLights.Add(currentTrafficLight); } int numberOfUpdates = int.Parse(Console.ReadLine()); for (int index = 0; index < numberOfUpdates; index++) { trafficLights.ForEach(t => t.Update()); Console.WriteLine(string.Join(" ", trafficLights)); } }
public void Run() { TrafficLightFactory trafficLightFactory = new TrafficLightFactory(); List <IChangeable> trafficLights = new List <IChangeable>(); string[] trafficStates = Console.ReadLine().Split(); int changesCount = int.Parse(Console.ReadLine()); for (int index = 0; index < trafficStates.Length; index++) { LightColor state = (LightColor)Enum.Parse(typeof(LightColor), trafficStates[index]); IChangeable trafficLight = trafficLightFactory.CreateTrafficLight(state); trafficLights.Add(trafficLight); } for (int counter = 0; counter < changesCount; counter++) { trafficLights.ForEach(tl => tl.ChangeState()); string result = string.Join(" ", trafficLights); Console.WriteLine(result); } }