예제 #1
0
파일: Form1.cs 프로젝트: ilyakom/Sudoku
        private async void Cell_MouseClick(object sender, MouseEventArgs e)
        {
            if (_model.CurrentSudoku == null)
            {
                return;
            }

            var row    = SudokuGrid.GetRow((Label)sender);
            var column = SudokuGrid.GetColumn((Label)sender);

            var curValue     = ((Label)sender).Text == "" ? 0 : int.Parse(((Label)sender).Text);
            var initialValue = curValue;

            for (var i = 0; i < Domain.Sudoku.BigSide; i++)
            {
                _model.CurrentSudoku[row, column] = curValue >= 9 ? 0 : curValue + 1;

                if (await Task.Run(() => Validations.ValidateSudoku(_model.CurrentSudoku)))
                {
                    ((Label)sender).Text = _model.CurrentSudoku[row, column] == 0 ? "" : _model.CurrentSudoku[row, column].ToString();
                    return;
                }

                curValue = curValue >= 9 ? 0 : curValue + 1;
            }

            _model.CurrentSudoku[row, column] = initialValue;
        }