Example #1
0
        public virtual void NewGame()
        {
            Sudoku = Generator.Generate();

            if (Sudoku.GetLength(0) == Sudoku.GetLength(1))
            {
                Status = SudokuGameStatus.InProgress;
                return;
            }

            Status = SudokuGameStatus.NotActive;

            var exception = new AbstractSudokuGameException("incorrect sudoku size");

            exception.Data["rows"]    = Sudoku.GetLength(0);
            exception.Data["columns"] = Sudoku.GetLength(1);
            throw exception;
        }
Example #2
0
        public virtual bool AddNumber(int row, int column, int value, Guid userGuid)
        {
            if (Status != SudokuGameStatus.InProgress)
            {
                throw new AbstractSudokuGameException("sudoku is not in progress");
            }

            if (value < 1 || value > Sudoku.GetLength(0))
            {
                var exception = new AbstractSudokuGameException("incorrect value");
                exception.Data["sudoku size"] = Sudoku.GetLength(0);
                exception.Data["value"]       = value;
                throw exception;
            }

            if (Sudoku[row, column] != 0)
            {
                return(false);
            }

            Sudoku[row, column] = value;

            if (!IsDone())
            {
                return(true);
            }

            if (!Solve())
            {
                Status = SudokuGameStatus.GameOver;
                return(true);
            }

            Status = SudokuGameStatus.Solved;
            Winner = userGuid;
            return(true);
        }