示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("жизненный цикл светофора\t\t\tнажми f чтоб подойти к светофору; d чтоб отойти от Светофора! ");

            Svetofor   svetofor = new Svetofor(10, 3, 10);
            Person     pers     = new Person("dima");
            Pedestrian isai     = new Pedestrian(pers);

            while (true)// для имитации подхода/отхода от светофора
            {
                ConsoleKeyInfo podoiti = Console.ReadKey();
                if (podoiti.KeyChar == 'f')
                {
                    isai.GoToPedestrianCrossing(svetofor);
                }
                else if (podoiti.KeyChar == 'd')
                {
                    isai.OutToPedestrianCrossing(svetofor);
                }
                else
                {
                    return;
                }
            }
        }
        public void OutToPedestrianCrossing(Svetofor currentSvetofor)
        {
            CurrentSvetofor = currentSvetofor;

            CurrentSvetofor.ChangStateSvetoforEvent -= GoToPedestrianCrossingHandler;

            Dispose();
        }
 public void Dispose()
 {
     this.CurrentSvetofor = null;
 }
        public void GoToPedestrianCrossing(Svetofor currentSvetofor)
        {
            CurrentSvetofor = currentSvetofor;

            currentSvetofor.ChangStateSvetoforEvent += GoToPedestrianCrossingHandler;
        }