private IEnumerable<Light> GetLightsForRange(string inputRange)
 {
     var isOn = false;
     var isToggle = false;
     var trimValue = TurnOff;
     var input = inputRange.Trim();
     if (input.StartsWith(TurnOn))
     {
         isOn = true;
         trimValue = TurnOn;
     }else if (input.StartsWith(Toggle))
     {
         trimValue = Toggle;
         isToggle = true;
     }
     var matches =
         _regEx.Matches(inputRange.Replace(trimValue, string.Empty).Replace(Through, string.Empty).Trim());
     var p1 = matches[0].Value.Split(',');
     var p2 = matches[1].Value.Split(',');
     var startPoint = new Point(int.Parse(p1[0].Trim()), int.Parse(p1[1].Trim()));
     var endPoint = new Point(int.Parse(p2[0].Trim()), int.Parse(p2[1].Trim()));
     var x = startPoint.X;
     var y = startPoint.Y;
     while (x <= endPoint.X)
     {
         y = startPoint.Y;
         while (y <= endPoint.Y)
         {
             var l = new Light(new Point(x, y)) {IsOn = isOn, Toggle = isToggle};
             y++;
             yield return l;
         }
         x++;
     }
 }
Esempio n. 2
0
        public void AddLight(Light light)
        {
            if (!_mapDictionary.ContainsKey(light.Coordinate.X))
                _mapDictionary.Add(light.Coordinate.X, new Dictionary<int, Light>());

            var yDirection = _mapDictionary[light.Coordinate.X];
            if (light.Toggle)
            {
               yDirection[light.Coordinate.Y].IsOn = !yDirection[light.Coordinate.Y].IsOn;
            }
            else yDirection[light.Coordinate.Y] = light;
        }
        public void AddLight(Light light)
        {
            if (!_mapDictionary.ContainsKey(light.Coordinate.X))
                _mapDictionary.Add(light.Coordinate.X, new Dictionary<int, Light>());

            var yDirection = _mapDictionary[light.Coordinate.X];
            if (light.Toggle)
            {
                yDirection[light.Coordinate.Y].Brightness = yDirection[light.Coordinate.Y].Brightness + 2;
            }
            else if (light.IsOn)
                yDirection[light.Coordinate.Y].Brightness++;
            else yDirection[light.Coordinate.Y].Brightness--;
        }