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(); }
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 }
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(); } }
public TrafficLight() { InitializeComponent(); CurrentPhase = new TrafficPhase(PhaseType.Go, 8); CurrentPhase.Done += Phase_Done; CurrentPhase.Elapsed += Phase_Elapsed; }
private void Phase_Done(object sender, EventArgs e) { if (phaseQueue.Count != 0) { CurrentPhase = phaseQueue.Dequeue(); CurrentPhase.Run(); } }
public TrafficLight() { InitializeComponent(); CurrentPhase = TrafficPhase.Go; GreenLight.Image = Properties.Resources.LightGreen; YellowLight.Image = Properties.Resources.DarkYellow; RedLight.Image = Properties.Resources.DarkRed; }
private void Phase_Done(object sender, EventArgs e) { //execute the next phase in the Queue if (phaseQueue.Count != 0) { CurrentPhase = phaseQueue.Dequeue(); CurrentPhase.Run(); } }
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); }
public TrafficLight() { InitializeComponent(); CurrentPhase = TrafficPhase.Go; RedLight.SetState(LampState.Off); YellowLight.SetState(LampState.Off); GreenLight.SetState(LampState.On); }
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(); }
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--; }
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); }
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); }
private void PerformClockTick() { if (CurrentPhase?.RemainingTime >= 1) { CurrentPhase.RemainingTime--; OnPhaseChanged(); } else { if (WorkingQueue.Count != 0) { CurrentPhase = WorkingQueue.Dequeue(); OnPhaseChanged(); } else { Timer.Stop(); } } }
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); }
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(); } }
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); }
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(); } }
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); }
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(); } }
public PhaseController(Queue <TrafficPhase> phaseQueue, PhaseController parent = null, TrafficPhase initialPhase = null) { Parent = parent; CurrentPhase = initialPhase; PhaseQueue = phaseQueue; }
public PhaseController() { CurrentPhase = new TrafficPhase(PhaseType.Go, 8); CurrentPhase.Done += Phase_Done; CurrentPhase.Elapsed += Phase_Elapsed; }
internal PhaseEventArgs(TrafficPhase phase, int remainingTime) { Phase = phase; RemainingTime = remainingTime; }
public PhaseEventArgs(TrafficPhase phase, MessageType messageType = MessageType.Tick, int time = 0) { Phase = phase; MessageType = messageType; Time = time; }
public TrafficLight() { InitializeComponent(); CurrentPhase = new TrafficPhase(PhaseType.Go, 7); }
internal PhaseEventArgs(TrafficPhase phase) { Phase = phase; }