示例#1
0
        /// <summary>
        /// Change state of traffic light on red
        /// </summary>
        /// <param name="trafficLight"> Object of traffic light for changing its state </param>
        /// <exception cref="ArgumentNullException"> If trafficLight is null </exception>
        public void Change(TrafficLightState trafficLight)
        {
            if (trafficLight == null)
            {
                throw new ArgumentNullException($"The patametr {nameof(trafficLight)} can't be null!");
            }

            trafficLight.State = new RedState();
        }
        /// <summary>
        /// Run cycle of change states for traffic light
        /// </summary>
        /// <param name="initState"> Initial state </param>
        /// <param name="shiftsNumber"> Number of changes states </param>
        /// <returns> Collection of colours </returns>
        /// <exception cref="ArgumentNullException"> If initState is null </exception>
        public static IEnumerable <ColourOption> Start(ILightState initState, int shiftsNumber)
        {
            var trafficLight = new TrafficLightState(initState);

            for (int i = 0; i < shiftsNumber; i++)
            {
                yield return(trafficLight.Colour);

                trafficLight.Change();
            }
        }