コード例 #1
0
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            TrafficLightStates state = (TrafficLightStates)value;

            switch (state)
            {
            case TrafficLightStates.GREEN: return(new SolidColorBrush(Colors.Green));

            case TrafficLightStates.YELLOW: return(new SolidColorBrush(Colors.Yellow));

            case TrafficLightStates.RED: return(new SolidColorBrush(Colors.Red));
            }

            return(new SolidColorBrush(Colors.LightGray));
        }
コード例 #2
0
 void ChangeTrafficLite()
 {
     if (currentState == TrafficLightStates.GreenLeftLightBlinking)
     {
         expectationTicksCount = gangerRedLightCycles * changeTicksCount;
     }
     if (currentState == TrafficLightStates.YellowRedLightEnabled)
     {
         expectationTicksCount = gangerGreenLightCycles * changeTicksCount;
     }
     if (currentState == TrafficLightStates.YellowLightEnabled)
     {
         currentState = TrafficLightStates.RedLightEnabled;
     }
     else
     {
         currentState = (TrafficLightStates)((int)currentState + 1);
     }
     IsGreenLeftSegmentEnabled   = greenLeftSegmentStates[(int)currentState];
     IsGreenRightSegmentEnabled  = greenRightSegmentStates[(int)currentState];
     IsYellowSegmentEnabled      = yellowSegmentStates[(int)currentState];
     IsRedSegmentEnabled         = redSegmentStates[(int)currentState];
     IsGangerGreenSegmentEnabled = gangerGreenSegmentStates[(int)currentState];
     IsGangerRedSegmentEnabled   = gangerRedSegmentStates[(int)currentState];
     IsTimerGreen               = !IsGangerRedSegmentEnabled;
     isGreenLeftLightBlinking   = greenLeftBlinkingStates[(int)currentState];
     isGreenRightLightBlinking  = greenRightBlinkingStates[(int)currentState];
     isGangerGreenLightBlinking = gangerGreenBlinkingStates[(int)currentState];
     if (blinkingStates[(int)currentState])
     {
         blinkingTimer.Start();
     }
     else
     {
         blinkingTimer.Stop();
     }
 }
コード例 #3
0
ファイル: TrafficLight.cs プロジェクト: Gnork/proTRonDrive
 public void Reset()
 {
     // Set the traffic light to red state and start over
     _lightTimer.Stop();
     _lightTimer.MaxTime = _redTime;
     _timeDisplay.font.material = _redMaterial;
     _phase = TrafficLightStates.Red;
     _lightTimer.Start();
 }
コード例 #4
0
ファイル: TrafficLight.cs プロジェクト: Gnork/proTRonDrive
    private void SwitchPhase()
    {
        // Switches to the next traffic light phase
        // ( Red -> Yellow -> Green -> Yellow -> Red -> ... )
        switch (_phase)
        {
        case TrafficLightStates.Red:
            _lightTimer.Stop();
            _lightTimer.MaxTime = _yellowTime;
            _lightTimer.Start();

            _phase = TrafficLightStates.ToGreen;
            break;

        case TrafficLightStates.ToGreen:
            _lightTimer.Stop();
            _lightTimer.MaxTime = _greenTime;
            _timeDisplayRenderer.material = _greenMaterial;
            _lightTimer.Start();

            _phase = TrafficLightStates.Green;
            break;

        case TrafficLightStates.Green:
            _lightTimer.Stop();
            _lightTimer.MaxTime = _yellowTime;
            _lightTimer.Start();

            _phase = TrafficLightStates.ToRed;
            break;

        case TrafficLightStates.ToRed:
            _lightTimer.Stop();
            _lightTimer.MaxTime = _redTime;
            _timeDisplayRenderer.material = _redMaterial;
            _lightTimer.Start();

            _phase = TrafficLightStates.Red;
            break;

        }

        UpdateLight();
    }