예제 #1
0
    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);
        }
    }