Example #1
0
        private void NewSudoku()
        {
            myCanvas.Children.Clear();

            GridMaker.AddRandomDigitsToGrid(ref grid, 81 - level);
            gridDrafter = new GridDrafter(grid);

            gridDrafter.CreateGridForSudoku(myCanvas);

            solved = new int[81];
            Array.Copy(grid, solved, 81);

            Solver.TrySolveSudoku(solved);

            gridDrafter.AddInputsForUser(myCanvas, grid);

            TextBox[] tbs = gridDrafter.GetInputs();
            foreach (TextBox tb in tbs)
            {
                if (tb != null)
                {
                    tb.KeyDown += Inputs_KeyDown;
                }
            }

            NextSudoku.IsEnabled  = false;
            CheckInputs.IsEnabled = true;
            SolveButton.IsEnabled = true;
            PointsText.Content    = $"Points: {points}";
        }
Example #2
0
        public void AddRandomDigitsToGrid_TooFewNumbers_Throws(int numberOfDigits)
        {
            int[] grid = new int[81];

            var ex = Assert.Throws <Exception>(() => GridMaker.AddRandomDigitsToGrid(ref grid, numberOfDigits));

            StringAssert.Contains("too few", ex.Message);
        }
Example #3
0
        public void AddRandomDigitsToGrid_WhenCalled_PutRandomDigitsToGrid(int numberOfDigits)
        {
            int[] grid = new int[81];

            GridMaker.AddRandomDigitsToGrid(ref grid, numberOfDigits);
            int result = grid.Count(g => g != 0);

            Assert.AreEqual(numberOfDigits, result);
        }
Example #4
0
 private void MakeEmptySudoku()
 {
     NewEmptySudokuButton.IsEnabled = false;
     SolveButton.IsEnabled          = true;
     ErrorText.Content = "";
     GridMaker.AddRandomDigitsToGrid(ref grid, 0);
     gridDrafter = new GridDrafter(grid);
     gridDrafter.CreateGridForSudoku(myCanvas);
     gridDrafter.AddInputsForUser(myCanvas, grid);
 }