예제 #1
0
        private void StopButton_Click(object sender, EventArgs e)
        {
            lblCountDown.Visible = true;

            //Add the phases to a Queue with the time duration
            var phase = new TrafficPhase(PhaseType.Attention, 3);

            phase.Done    += Phase_Done;
            phase.Elapsed += Phase_Elapsed;
            phaseQueue.Enqueue(phase);

            phase          = new TrafficPhase(PhaseType.Stop, 7);
            phase.Done    += Phase_Done;
            phase.Elapsed += Phase_Elapsed;
            phaseQueue.Enqueue(phase);

            phase          = new TrafficPhase(PhaseType.Prepare, 2);
            phase.Done    += Phase_Done;
            phase.Elapsed += Phase_Elapsed;
            phaseQueue.Enqueue(phase);

            // Aktuelle Phase Go ist am Ende wieder Ausgangszustand
            phaseQueue.Enqueue(CurrentPhase);

            // Ablauf der aktuellen Phase auslösen
            CurrentPhase.Run();
        }
예제 #2
0
        public void GoToTime(int time)
        {
            //Zeitpunkt bestimmt CurrentPhase und verbleibende Phasen
            var sum   = 0;
            var found = false;

            foreach (var phase in PhaseQueue)
            {
                sum += phase.Duration;
                if (sum >= time)
                {
                    if (found)
                    {
                        WorkingQueue.Enqueue(phase);
                    }
                    else
                    {
                        found        = true;
                        CurrentPhase = phase;
                        CurrentPhase.RemainingTime = (sum - time);
                        WorkingQueue.Clear();
                    }
                }
            }

            //PhaseEventArgs als Informationspaket instanzieren
            PhaseChanged?.Invoke(this, new PhaseEventArgs(CurrentPhase, MessageType.Move, time));
            //SubController benachrichtigen
        }
예제 #3
0
        private void LightTimer_Tick(object sender, EventArgs e)
        {
            //Attention phase
            if (CurrentPhase == TrafficPhase.Go)
            {
                CurrentPhase        = TrafficPhase.Attention;
                LightTimer.Interval = 3000;
            }
            //Stop phase
            else if (CurrentPhase == TrafficPhase.Attention)
            {
                CurrentPhase        = TrafficPhase.Stop;
                LightTimer.Interval = 6000;
            }

            //Prepare Phase
            else if (CurrentPhase == TrafficPhase.Stop)
            {
                CurrentPhase        = TrafficPhase.Prepare;
                LightTimer.Interval = 2000;
            }
            //return to Go Phase
            else if (CurrentPhase == TrafficPhase.Prepare)
            {
                CurrentPhase = TrafficPhase.Go;
                LightTimer.Stop();
            }
        }
예제 #4
0
 public TrafficLight()
 {
     InitializeComponent();
     CurrentPhase          = new TrafficPhase(PhaseType.Go, 8);
     CurrentPhase.Done    += Phase_Done;
     CurrentPhase.Elapsed += Phase_Elapsed;
 }
예제 #5
0
 private void Phase_Done(object sender, EventArgs e)
 {
     if (phaseQueue.Count != 0)
     {
         CurrentPhase = phaseQueue.Dequeue();
         CurrentPhase.Run();
     }
 }
예제 #6
0
        public TrafficLight()
        {
            InitializeComponent();
            CurrentPhase = TrafficPhase.Go;

            GreenLight.Image  = Properties.Resources.LightGreen;
            YellowLight.Image = Properties.Resources.DarkYellow;
            RedLight.Image    = Properties.Resources.DarkRed;
        }
예제 #7
0
 private void Phase_Done(object sender, EventArgs e)
 {
     //execute the next phase in the Queue
     if (phaseQueue.Count != 0)
     {
         CurrentPhase = phaseQueue.Dequeue();
         CurrentPhase.Run();
     }
 }
예제 #8
0
 public PhaseController(string name, Queue <TrafficPhase> phaseQueue, PhaseController parent = null, TrafficPhase initialPhase = null)
 {
     Name           = name;
     Parent         = parent;
     CurrentPhase   = initialPhase;
     PhaseQueue     = phaseQueue;
     Timer.Interval = 1000;
     Timer.Tick    += new EventHandler(Timer_Tick);
 }
예제 #9
0
        public TrafficLight()
        {
            InitializeComponent();
            CurrentPhase = TrafficPhase.Go;

            RedLight.SetState(LampState.Off);
            YellowLight.SetState(LampState.Off);
            GreenLight.SetState(LampState.On);
        }
예제 #10
0
 private void Phase_Done(object sender, EventArgs e)
 {
     //execute the next phase in the Queue and inform the Events
     if (PhaseQueue.Count != 0)
     {
         CurrentPhase          = PhaseQueue.Dequeue();
         CurrentPhase.Done    += Phase_Done;
         CurrentPhase.Elapsed += Phase_Elapsed;
         CurrentPhase.Run();
     }
     OnPhaseChanged();
 }
예제 #11
0
        private void LightTimer_Tick(object sender, EventArgs e)
        {
            // Wenn keine Zeit übrig ist: Phasenwechsel
            if (remainingTime == 0)
            {
                CurrentPhase = GoToNextPhase();
            }

            // Anzeige aktualisieren
            lblCountDown.Text = remainingTime.ToString("00");
            lblCountDown.Refresh();

            // Verbleibende Zeit reduzieren
            remainingTime--;
        }
예제 #12
0
        public void CreateMainQueue(object sender, EventArgs e)
        {
            //Add phases to the Queue and set the Current phase for the Controller

            var phase = new TrafficPhase(PhaseType.Attention, 2);//Yelllow

            MainPhaseQueue.Enqueue(phase);

            phase = new TrafficPhase(PhaseType.Stop, 15);//Red
            MainPhaseQueue.Enqueue(phase);

            phase = new TrafficPhase(PhaseType.Prepare, 2);//Red, Yellow
            MainPhaseQueue.Enqueue(phase);

            phase = new TrafficPhase(PhaseType.Go, 0);//Green
            MainPhaseQueue.Enqueue(phase);
        }
예제 #13
0
        public void CreateSubQueue(object sender, EventArgs e)
        {
            //Add phases to the Queue and set the Current phase for the Controller
            SubController.CurrentPhase = new TrafficPhase(PhaseType.Stop, 10); //Red

            var phase = new TrafficPhase(PhaseType.Prepare, 2);                //Red, Yellow

            SubPhaseQueue.Enqueue(phase);

            phase = new TrafficPhase(PhaseType.Go, 9);//Green
            SubPhaseQueue.Enqueue(phase);

            phase = new TrafficPhase(PhaseType.Attention, 2);//Yellow
            SubPhaseQueue.Enqueue(phase);

            phase = new TrafficPhase(PhaseType.Stop, 0);//Red
            SubPhaseQueue.Enqueue(phase);
        }
예제 #14
0
 private void PerformClockTick()
 {
     if (CurrentPhase?.RemainingTime >= 1)
     {
         CurrentPhase.RemainingTime--;
         OnPhaseChanged();
     }
     else
     {
         if (WorkingQueue.Count != 0)
         {
             CurrentPhase = WorkingQueue.Dequeue();
             OnPhaseChanged();
         }
         else
         {
             Timer.Stop();
         }
     }
 }
예제 #15
0
        private void StopButton_Click(object sender, EventArgs e)
        {
            //Add the phases to a Queue with the time duration
            var phaseQueue = new Queue <TrafficPhase>();

            phaseQueue.Enqueue(new TrafficPhase(PhaseType.Attention, 3));
            phaseQueue.Enqueue(new TrafficPhase(PhaseType.Stop, 7));
            phaseQueue.Enqueue(new TrafficPhase(PhaseType.Prepare, 2));

            CurrentPhase.Run();

            //execute the Queue elements statrs from the first phase
            while (phaseQueue.Count > 0)
            {
                CurrentPhase = phaseQueue.Dequeue();
                CurrentPhase.Run();
            }

            //set the Go phase as the last phase
            CurrentPhase = new TrafficPhase(PhaseType.Go, 7);
        }
예제 #16
0
        private void LightTimer_Tick(object sender, EventArgs e)
        {
            //Attention phase
            if (CurrentPhase == TrafficPhase.Go)
            {
                CurrentPhase = TrafficPhase.Attention;
                RedLight.SetState(LampState.Off);
                YellowLight.SetState(LampState.On);
                GreenLight.SetState(LampState.Off);
                LightTimer.Interval = 3000;
            }
            //Stop phase
            else if (CurrentPhase == TrafficPhase.Attention)
            {
                CurrentPhase = TrafficPhase.Stop;
                RedLight.SetState(LampState.On);
                YellowLight.SetState(LampState.Off);//LightStateOff();
                GreenLight.SetState(LampState.Off);
                LightTimer.Interval = 6000;
            }
            //Prepare Phase

            else if (CurrentPhase == TrafficPhase.Stop)
            {
                CurrentPhase = TrafficPhase.Prepare;
                RedLight.SetState(LampState.On);
                YellowLight.SetState(LampState.On);
                GreenLight.SetState(LampState.Off);
                LightTimer.Interval = 2000;
            }
            else if (CurrentPhase == TrafficPhase.Prepare)
            {
                CurrentPhase = TrafficPhase.Go;
                RedLight.SetState(LampState.Off);
                YellowLight.SetState(LampState.Off);
                GreenLight.SetState(LampState.On);
                LightTimer.Stop();
            }
        }
예제 #17
0
        private void InitQueue(object sender, EventArgs e)
        {
            //Add the phases to a Queue with the time duration
            var phase = new TrafficPhase(PhaseType.Attention, 3);

            phase.Done    += Phase_Done;
            phase.Elapsed += Phase_Elapsed;
            phaseQueue.Enqueue(phase);

            phase          = new TrafficPhase(PhaseType.Stop, 8);
            phase.Done    += Phase_Done;
            phase.Elapsed += Phase_Elapsed;
            phaseQueue.Enqueue(phase);

            phase          = new TrafficPhase(PhaseType.Prepare, 2);
            phase.Done    += Phase_Done;
            phase.Elapsed += Phase_Elapsed;
            phaseQueue.Enqueue(phase);

            // Aktuelle Phase Go ist am Ende wieder Ausgangszustand
            phaseQueue.Enqueue(CurrentPhase);
        }
예제 #18
0
        private void LightTimer_Tick(object sender, EventArgs e)
        {
            //Attention phase
            if (CurrentPhase == TrafficPhase.Go)
            {
                CurrentPhase        = TrafficPhase.Attention;
                GreenLight.Image    = Properties.Resources.DarkGreen;
                YellowLight.Image   = Properties.Resources.LightYellow;
                RedLight.Image      = Properties.Resources.DarkRed;
                LightTimer.Interval = 3000;
            }
            //Stop phase
            else if (CurrentPhase == TrafficPhase.Attention)
            {
                CurrentPhase        = TrafficPhase.Stop;
                GreenLight.Image    = Properties.Resources.DarkGreen;
                YellowLight.Image   = Properties.Resources.DarkYellow;
                RedLight.Image      = Properties.Resources.LightRed;
                LightTimer.Interval = 6000;
            }
            //Prepare Phase

            else if (CurrentPhase == TrafficPhase.Stop)
            {
                CurrentPhase        = TrafficPhase.Prepare;
                GreenLight.Image    = Properties.Resources.DarkGreen;
                YellowLight.Image   = Properties.Resources.LightYellow;
                RedLight.Image      = Properties.Resources.LightRed;
                LightTimer.Interval = 2000;
            }
            else if (CurrentPhase == TrafficPhase.Prepare)
            {
                CurrentPhase      = TrafficPhase.Go;
                GreenLight.Image  = Properties.Resources.LightGreen;
                YellowLight.Image = Properties.Resources.DarkYellow;
                RedLight.Image    = Properties.Resources.DarkRed;
                LightTimer.Stop();
            }
        }
예제 #19
0
        private void StopButton_Click(object sender, EventArgs e)
        {
            //Add the phases to a Queue with the time duration
            var phase = new TrafficPhase(PhaseType.Attention, 3);

            phase.Done += Phase_Done;
            phaseQueue.Enqueue(phase);

            phase       = new TrafficPhase(PhaseType.Stop, 7);
            phase.Done += Phase_Done;
            phaseQueue.Enqueue(phase);

            phase       = new TrafficPhase(PhaseType.Prepare, 2);
            phase.Done += Phase_Done;
            phaseQueue.Enqueue(phase);

            phase       = new TrafficPhase(PhaseType.Go, 8);
            phase.Done += Phase_Done;
            phaseQueue.Enqueue(phase);

            CurrentPhase.Run();
            phaseQueue.Enqueue(phase);
        }
예제 #20
0
 private void PerformClockTick()
 {
     if (CurrentPhase.RemainingTime >= 1)
     {
         CurrentPhase.RemainingTime--;
         OnPhaseChanged();
     }
     else
     {
         if (Parent == null)
         {
             Timer.Stop();
         }
         if (PhaseQueue.Count != 0)
         {
             CurrentPhase = PhaseQueue.Dequeue();
             if (Parent == null)
             {
                 Timer.Start();
             }
         }
         OnPhaseChanged();
     }
 }
예제 #21
0
 public PhaseController(Queue <TrafficPhase> phaseQueue, PhaseController parent = null, TrafficPhase initialPhase = null)
 {
     Parent       = parent;
     CurrentPhase = initialPhase;
     PhaseQueue   = phaseQueue;
 }
예제 #22
0
 public PhaseController()
 {
     CurrentPhase          = new TrafficPhase(PhaseType.Go, 8);
     CurrentPhase.Done    += Phase_Done;
     CurrentPhase.Elapsed += Phase_Elapsed;
 }
예제 #23
0
 internal PhaseEventArgs(TrafficPhase phase, int remainingTime)
 {
     Phase         = phase;
     RemainingTime = remainingTime;
 }
예제 #24
0
 public PhaseEventArgs(TrafficPhase phase, MessageType messageType = MessageType.Tick, int time = 0)
 {
     Phase       = phase;
     MessageType = messageType;
     Time        = time;
 }
예제 #25
0
 public TrafficLight()
 {
     InitializeComponent();
     CurrentPhase = new TrafficPhase(PhaseType.Go, 7);
 }
예제 #26
0
 internal PhaseEventArgs(TrafficPhase phase)
 {
     Phase = phase;
 }