Example #1
0
        public void ButtonPressed(byte input)
        {
            int row    = int.Parse(selectedButton.Name[3] + "");
            int column = int.Parse(selectedButton.Name[4] + "");

            if (input == 0)
            {
                Stat.Text = "N***a, you cannot put 0 in a sudoku";
                return;
            }

            ISudoku tmpSudo = sudo.Clone();

            tmpSudo.SetNumberAt(column, row, input);

            if (tmpSudo.IsSolvable())
            {
                sudokuArray[column, row] = (int)input;
                selectedButton.Content   = input;
                selectedButton.IsEnabled = false;
                sudo.SetNumberAt(column, row, input);
                Stat.Text = "GJ N***A";
                if (sudo.IsSolved())
                {
                    Stat.Text = "YOU DONE DID N***A, FRIED CHICKEN FOR EVERYONE!";
                }
                return;
            }
            else
            {
                Stat.Text = "N***A YOU STUPID AS HELL";
                return;
            }
        }
        private void LoadSudoku(ISudoku sudokuToLoad, string name = "a Sudoku.")
        {
            sudokuGrid.Children.RemoveRange(0, sudokuGrid.Children.Count);

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    int cell = sudokuToLoad[i, j];

                    Label cellLabel = new Label
                    {
                        Content = cell != 0 ? cell.ToString() : " ",
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment   = VerticalAlignment.Center,
                        FontSize  = 32,
                        MinWidth  = 50,
                        MinHeight = 50,
                        Tag       = Tuple.Create(i, j)
                    };

                    // Alternate 3-cell group coloring.
                    Console.WriteLine(cell);
                    if (ShouldColorCellAt(i, j))
                    {
                        cellLabel.Background = Brushes.LightGray;
                    }

                    // "Click" handler.
                    cellLabel.MouseLeftButtonUp += OnCellLeftClick;

                    Border cellBorder = new Border
                    {
                        BorderBrush     = Brushes.Black,
                        BorderThickness = new Thickness(1),
                        Child           = cellLabel
                    };

                    // Add our border, containing our label (i.e. cell)
                    sudokuGrid.Children.Add(cellBorder);
                }
            }

            sudoku   = sudokuToLoad;
            solution = sudokuToLoad.Clone().Solve();

            statusLeft.Content = "Loaded " + name;

            UpdateStatistics();
        }