Esempio n. 1
0
        public void CreateGridColumnsAndRowsAndTurnOnCenterCheckLightsOn(int columns, int rows, int x, int y, int expected)
        {
            var grid = new LightGrid(columns, rows);

            grid.ToggleLight(x, y);

            var lightsOn = grid.GetLights(LightState.On);

            Assert.Equal(expected, lightsOn.Count);
        }
Esempio n. 2
0
        public void CreateGridColumnsAndRowsAndTurnOnCenter()
        {
            int x    = 2;
            int y    = 2;
            var grid = new LightGrid(5, 5);

            var centerLight = grid.GetLight(x, y);

            grid.ToggleLight(x, y);

            Assert.Equal(LightState.On, centerLight.State);
        }
Esempio n. 3
0
        public MainWindow()
        {
            _LightGrid = new LightGrid(Columns, Rows);
            _Buttons   = new Button[Rows, Columns];

            InitializeComponent();

            // Set the grid size so the lights rendering in the correct order
            grid.Columns = Columns;
            grid.Rows    = Rows;

            // Loops the lights and attach click handlers
            foreach (var light in _LightGrid.Lights)
            {
                var button = new Button()
                {
                    Background = Brushes.Gray
                };
                // Apply the event handler and add the light to the grid
                button.Click += new RoutedEventHandler((object sender, RoutedEventArgs e) =>
                {
                    if (_LightGrid.Complete)
                    {
                        return;
                    }

                    _LightGrid.ToggleLight(light.X, light.Y);
                    RedrawGrid();

                    if (_LightGrid.Complete)
                    {
                        MessageBox.Show("You win");
                    }
                });
                _Buttons[light.Y, light.X] = button;
                grid.Children.Add(button);
            }

            // Reset and randomize the grid
            _LightGrid.ResetAndRandomizeStates();
            RedrawGrid();
        }