Пример #1
0
        public void IsAllSwitchesOff()
        {
            // Define a test input and output value:
            var matrix = new int[4, 4];

            //fill the matrix
            matrix[0, 0] = 0;
            matrix[0, 1] = 0;
            matrix[0, 2] = 0;
            matrix[0, 3] = 0;
            matrix[1, 0] = 0;
            matrix[1, 1] = 0;
            matrix[1, 2] = 0;
            matrix[1, 3] = 0;
            matrix[2, 0] = 0;
            matrix[2, 1] = 0;
            matrix[2, 2] = 0;
            matrix[2, 3] = 0;
            matrix[3, 0] = 0;
            matrix[3, 1] = 0;
            matrix[3, 2] = 0;
            matrix[3, 3] = 0;
            // Run the method under test:
            OperationsHelper.AllLightsOff(matrix);
            //Verify the result:
            Assert.AreEqual(true, OperationsHelper.AllLightsOff(matrix));
        }
Пример #2
0
        /// <summary>
        /// Print the switch buttons
        /// </summary>
        private void PrintMatrix()
        {
            gridPanel.Children.Clear(); //clear children objects
            gridPanel.ColumnDefinitions.Clear();
            gridPanel.RowDefinitions.Clear();

            //add columns dynamically
            for (int i = 0; i < MatrixColumns; i++)
            {
                var newColumn = new ColumnDefinition();
                newColumn.Name  = "column" + i.ToString();
                newColumn.Width = GridLength.Auto;
                this.gridPanel.ColumnDefinitions.Add(newColumn);
            }

            //add rows dynamically
            for (int row = 0; row < MatrixRows; row++)
            {
                var newRows = new RowDefinition();
                newRows.Name   = "row" + row.ToString();
                newRows.Height = GridLength.Auto;


                this.gridPanel.RowDefinitions.Add(newRows);
                for (int col = 0; col < MatrixColumns; col++)
                {
                    UserControl switchBox = new IMAGE_off();

                    if (LightsMatrix[row, col] == 1)
                    {
                        switchBox = new IMAGE_on();
                    }

                    Button btn = new Button();
                    btn.Content          = switchBox;
                    btn.RenderSize       = new Size(20, 20);
                    btn.CommandParameter = Tuple.Create(row, col);
                    btn.Click           += SwitchHandler;
                    btn.Background       = Brushes.DarkRed;

                    btn.HorizontalAlignment = HorizontalAlignment.Center;
                    btn.VerticalAlignment   = VerticalAlignment.Bottom;

                    btn.SetValue(Grid.RowProperty, row);
                    btn.SetValue(Grid.ColumnProperty, col);

                    gridPanel.Children.Add(btn);
                }
            }

            lblCounter.Content = ClickCounter;
            lblTrophy.Content  = WinsCounter;

            //Check if all the switches are in OFF
            if (OperationsHelper.AllLightsOff(LightsMatrix))
            {
                lblYouWin.Visibility = Visibility.Visible;
                WinsCounter++;
                lblTrophy.Content         = WinsCounter;
                gridPanel.IsEnabled       = false;
                btnLevelChange.Visibility = Visibility.Visible;
                lblLevel.Visibility       = Visibility.Hidden;
            }
        }