static void Main(string[] args) { List <Bulb> firstBulbs = new List <Bulb>() { new GreenBulb(), new OrangeBulb(), new GreenBulb(), }; TrafficLighter firstTrafficLighter = new TrafficLighter(firstBulbs); List <Bulb> secondBulbs = new List <Bulb>() { new GreenBulb(), new OrangeBulb(), new GreenBulb(), }; TrafficLighter secondTrafficLighter = new TrafficLighter(secondBulbs); RoadIntersection roadIntersection = new RoadIntersection(); roadIntersection.Subscribe(firstTrafficLighter, "daily", 0); roadIntersection.Subscribe(secondTrafficLighter, "daily", 1); roadIntersection.Start(30000); roadIntersection.ChangeBehaviour("orangePulse"); roadIntersection.Start(); }
public static void Main(string[] args) { TrafficLighter lighter = new TrafficLighter(new RedState()); // Will be switched every two seconds Timer timer = new Timer { Interval = 2000, }; // this event causes a change of state timer.Elapsed += (sender, eventArgs) => { Console.Clear(); lighter.Switch(); Console.WriteLine(lighter.Color); }; timer.Start(); Console.ReadKey(); // ends when you pressed any key timer.Stop(); }
/// <inheritdoc/> /// <summary> /// Sets the yellow light and switches lighter to the waiting for red state /// </summary> /// <param name="lighter">The lighter.</param> /// <returns> /// The current state of lighter as a <see cref="string" /> /// </returns> public string Switch(TrafficLighter lighter) { lighter.State = new RedState(); return("Yellow"); }
/// <inheritdoc/> /// <summary> /// Sets the green light and switches lighter to the waiting for yellow state /// </summary> /// <param name="lighter">The lighter.</param> /// <returns> /// The current state of lighter as a <see cref="string" /> /// </returns> public string Switch(TrafficLighter lighter) { lighter.State = new YellowState(); return("Green"); }