Пример #1
0
        /// <summary>
        /// Removes fields from the full solution.
        /// </summary>
        /// <param name="level"></param>
        private void SetupBoard(SudokuLevels level)
        {
            for (int i = 0; i < 9; i++)
            {
                board[i] = new int?[9];
                for (int j = 0; j < 9; j++)
                {
                    board[i][j] = solution[i][j];
                }
            }

            int remainingItems = ((int)level + 1) * 15;

            while (remainingItems > 0)
            {
                int posX = random.Next(9);
                int posY = random.Next(9);
                if (board[posX][posY] == null)
                {
                    continue;
                }
                board[posX][posY] = null;
                remainingItems--;
            }
        }
Пример #2
0
        private void StartGane(SudokuLevels level)
        {
            var game = new GameCode();

            game.GenerateGame(level);
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    sudokuBlocks[i, j].SetBinding(TextBlock.TextProperty, new Binding($"Board[{i}][{j}]"));
                }

                DataContext = game;
            }
        }
Пример #3
0
 public NewGameWindow(SudokuLevels level)
 {
     InitializeComponent();
     GenerateSudokuGrid();
     StartGane(level);
 }
Пример #4
0
        public void GenerateGame(SudokuLevels level)
        {
            GenerateSolution();

            SetupBoard(level);
        }