예제 #1
0
 public TrafficLight(int rDuration, int yDuration, int gDuration, TrafficLightColor color): this()
 {
     this.rDuration = RDuration;
     this.yDuration = YDuration;
     this.gDuration = GDuration;
     this.color = Color;
 }
        public void Update()
        {
            int lastColor   = (int)this.color;
            int enumsLength = Enum.GetNames(typeof(TrafficLightColor)).Length;

            this.color = (TrafficLightColor)(++lastColor % enumsLength);
        }
        public void MayIGo_given_color_returns_expected(TrafficLightColor color, bool expected)
        {
            var ctrl = new TrafficLightController();

            var actual = ctrl.MayIGo(color);

            Assert.Equal(actual, expected);
        }
        public void CanIGo_given_color_returns_expected(TrafficLightColor color, bool expected)
        {
            var controller = new TrafficLightController();

            var go = controller.MayIGo(color);

            Assert.Equal(expected, go);
        }
        public void CanIGo_theory(TrafficLightColor color, bool result)
        {
            ITrafficLightController controller = new TrafficLightController();

            var go = controller.MayIGo(color);

            Assert.Equal(result, go);
        }
 public void SwitchLight(TrafficLightColor color)
 {
     if(color != TrafficColor)
     {
         TrafficColor = color;
         // Restart the counter everytime the color changes.....
         // So the next change happens for the current color.
         counter = 0;
     }
 }
예제 #7
0
        // A method to change the light to a random value
        public void change()
        {
            //TODO: Set the Auto-implemented property CurrentColor to
            // a random color, either Red, Yellow, or Green
            // None should not be included

            Array colors = Enum.GetValues(typeof(TrafficLightColor));

            CurrentColor = (TrafficLightColor)colors.GetValue(random.Next(1, colors.Length));
        }
예제 #8
0
        public bool MayIGo(TrafficLightColor color)
        {
            switch (color)
            {
            default:
                return(false);

            case Green:
                return(true);
            }
        }
예제 #9
0
        public bool MayIGo(TrafficLightColor color)
        {
            switch (color)
            {
            case Green:
                return(true);

            case Yellow:
            case Red:
                return(false);

            default:
                throw new ArgumentException("Invalid color", nameof(color));
            }
        }
예제 #10
0
        public bool MayIGo(TrafficLightColor color)
        {
            switch (color)
            {
            case TrafficLightColor.Red:
            case TrafficLightColor.Yellow:
                return(false);

            case TrafficLightColor.Green:
                return(true);

            default:
                throw new ArgumentException("Wrong color", nameof(color));
            }
        }
예제 #11
0
 private void DrawDownTrafficLight(TrafficLightColor colors)
 {
     switch (colors)
     {
         case TrafficLightColor.Red:
             Console.ForegroundColor = ConsoleColor.Red;
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 5), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.ForegroundColor = ConsoleColor.White;
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 3), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 1), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.ForegroundColor = ConsoleColor.White;
             break;
         case TrafficLightColor.Green:
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 5), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 3), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.ForegroundColor = ConsoleColor.Green;
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 1), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.ForegroundColor = ConsoleColor.White;
             break;
         case TrafficLightColor.Yellow:
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 5), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.ForegroundColor = ConsoleColor.Yellow;
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 3), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.ForegroundColor = ConsoleColor.White;
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 1), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             break;
         default:
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 5), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.ForegroundColor = ConsoleColor.Yellow;
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 3), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             Console.ForegroundColor = ConsoleColor.White;
             Console.SetCursorPosition(((Console.WindowWidth / 2) - 1), ((Console.WindowHeight / 2) + 3));
             Console.Write("@");
             break;
     }
 }
        public void ChangeColor()
        {
            switch (CurrentColor)
            {
            case TrafficLightColor.Red:
                CurrentColor = TrafficLightColor.Green;
                break;

            case TrafficLightColor.Yellow:
                CurrentColor = TrafficLightColor.Red;
                break;

            default:
                CurrentColor = TrafficLightColor.Yellow;
                break;
            }
        }
예제 #13
0
    private void changeColor()
    {
        _timer = Time.time;

        int indexColor = Colors.IndexOf(_currentColor);

        if (Colors.Count <= indexColor + 1)
        {
            _currentColor = Colors[0];
        }
        else
        {
            _currentColor = Colors[indexColor + 1];
        }
        TrafficLight.material.color = _currentColor.Color;
        _collider.enabled           = !_currentColor.AllowTraffic;
        OnColorChange?.Invoke(_currentColor);
    }
예제 #14
0
        public TrafficLight()
        {
            toNextDuration = rDuration;

            timer.Interval = 10;
            timer.Tick += (object sender, EventArgs e) => {
                toNextDuration -= timer.Interval;
                if (toNextDuration <= 0)
                {
                    color = GetNextColor(color);
                    toNextDuration =
                        color == TrafficLightColor.Red ? rDuration :
                            color == TrafficLightColor.Yellow ? yDuration : gDuration;
                    OnChangeColor(EventArgs.Empty);
                }
            };
            timer.Enabled = true;
        }
예제 #15
0
        public bool MayIGo(TrafficLightColor color)
        {
            bool go;

            switch (color)
            {
            case TrafficLightColor.Green:
                go = true;
                break;

            case TrafficLightColor.Red:
            case TrafficLightColor.Yellow:
                go = false;
                break;

            default:
                throw new ArgumentException("Unknown color, dummy", nameof(color));
            }

            return(go);
        }
예제 #16
0
        private void ProcessTimer()
        {
            bool isChanged = false;

            if (downTopColor == TrafficLightColor.Green &&
                rightLeftColor == TrafficLightColor.Red &&
                !isChanged)
            {
                downTopColor = TrafficLightColor.Yellow;
                rightLeftColor = TrafficLightColor.Yellow;
                isChanged = true;
            }

            if (downTopColor == TrafficLightColor.Red &&
                rightLeftColor == TrafficLightColor.Green &&
                !isChanged)
            {
                downTopColor = TrafficLightColor.Yellow;
                rightLeftColor = TrafficLightColor.Yellow;
                isChanged = true;
            }

            if (downTopColor == TrafficLightColor.Yellow &&
                rightLeftColor == TrafficLightColor.Yellow &&
                !isGreenTopDown &&
                !isChanged)
            {
                downTopColor = TrafficLightColor.Green;
                rightLeftColor = TrafficLightColor.Red;
                isGreenTopDown = true;
                isChanged = true;
            }

            if (downTopColor == TrafficLightColor.Yellow &&
                rightLeftColor == TrafficLightColor.Yellow &&
                isGreenTopDown &&
                !isChanged)
            {
                downTopColor = TrafficLightColor.Red;
                rightLeftColor = TrafficLightColor.Green;
                isGreenTopDown = false;
                isChanged = true;
            }

            int seconds = 0;
            int timer = 0;

            switch (downTopColor)
            {
                case TrafficLightColor.Red:
                    timer = TIME_RED_LIGHT;
                    break;
                case TrafficLightColor.Green:
                    timer = TIME_GREEN_LIGHT;
                    break;
                case TrafficLightColor.Yellow:
                    timer = TIME_YELLOW_LIGHT;
                    break;
                default:
                    timer = TIME_YELLOW_LIGHT;
                    break;
            }

            int showTimer = timer;

            while (seconds < timer)
            {
                seconds++;
                showTimer--;

                Console.SetCursorPosition(9, 2);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(showTimer);
                Console.ForegroundColor = ConsoleColor.White;

                if (seconds == timer)
                {
                    DrawDownTrafficLight(downTopColor);
                    DrawLeftTrafficLight(rightLeftColor);
                    DrawRightTrafficLight(rightLeftColor);
                    DrawTopTrafficLight(downTopColor);
                }
            }

            Console.Beep();
        }
예제 #17
0
 public TrafficLight(string name, Dictionary <TrafficLightColor, int> colors, TrafficLightColor color, int countdown)
 {
 }
예제 #18
0
 public static TrafficLightColor GetNextColor(TrafficLightColor color) {
     return (TrafficLightColor) ((((int)color) + 1) % 3);
 }
 public TrafficLight()
 {
     CurrentColor = TrafficLightColor.Red;
 }
예제 #20
0
 private void TrafficController_OnColorChange(TrafficLightColor color)
 {
     text.text  = color.Description;
     text.color = new Color(color.Color.r, color.Color.g, color.Color.b);
 }
 public TrafficLight(string color)
 {
     this.color = Enum.Parse <TrafficLightColor>(color);
 }
예제 #22
0
 // Default Constructor
 public TrafficLight()
 {
     //TODO: Set the Auto-implemented property CurrentColor to None
     CurrentColor = TrafficLightColor.None;
     random       = new Random();
 }
예제 #23
0
 // Initial Value Constructor
 public TrafficLight(TrafficLightColor lightColor)
 {
     //TODO: Set the Auto-implemented property CurrentColor to this function's parameter
     CurrentColor = lightColor;
     random       = new Random();
 }