コード例 #1
0
ファイル: GameCode.cs プロジェクト: NScylla/Sudoku
        /// <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
ファイル: GameCode.cs プロジェクト: NScylla/Sudoku
        public void GenerateGame(SudokuLevels level)
        {
            GenerateSolution();

            SetupBoard(level);
        }