Пример #1
0
        public bool IsSolved()
        {
            if (ContinueGame)
            {
                if (SudokuMatrix.IsSolved())
                {
                    if (SudokuMatrix.Stopwatch.IsRunning)
                    {
                        SudokuMatrix.Stopwatch.Stop();
                    }

                    foreach (var sudokuCell in SudokuMatrix.SudokuCells)
                    {
                        if (sudokuCell.DisplayedValue > 0)
                        {
                            sudokuCell.Value = sudokuCell.DisplayedValue;
                        }
                    }

                    if (KeepScore)
                    {
                        TimeToSolve = SudokuMatrix.Stopwatch.Elapsed;

                        if (SudokuMatrix.Difficulty.DifficultyLevel == DifficultyLevel.EASY)
                        {
                            Score = Convert.ToInt32((TimeToSolve.Ticks * .80) / 1000000000);
                        }
                        else if (SudokuMatrix.Difficulty.DifficultyLevel == DifficultyLevel.MEDIUM)
                        {
                            Score = Convert.ToInt32((TimeToSolve.Ticks * .60) / 1000000000);
                        }
                        else if (SudokuMatrix.Difficulty.DifficultyLevel == DifficultyLevel.HARD)
                        {
                            Score = Convert.ToInt32((TimeToSolve.Ticks * .40) / 1000000000);
                        }
                        else if (SudokuMatrix.Difficulty.DifficultyLevel == DifficultyLevel.EVIL)
                        {
                            Score = Convert.ToInt32((TimeToSolve.Ticks * 20) / 1000000000);
                        }
                        else
                        {
                            Score = int.MaxValue;
                        }
                    }

                    var solvedDate = DateTime.UtcNow;

                    ContinueGame  = false;
                    DateUpdated   = solvedDate;
                    DateCompleted = solvedDate;
                    SudokuSolution.SolutionList = SudokuMatrix.ToIntList();
                    SudokuSolution.DateSolved   = solvedDate;
                }
            }

            return(!ContinueGame);
        }
Пример #2
0
        public Game(Difficulty difficulty, List <int> intList = null) : this()
        {
            if (intList != null)
            {
                SudokuMatrix = new SudokuMatrix(difficulty, intList);
            }
            else
            {
                SudokuMatrix.Difficulty = difficulty;
            }

            SudokuMatrix.SetDifficulty();
        }
Пример #3
0
        public Game(
            User user,
            SudokuMatrix matrix,
            Difficulty difficulty,
            int appId = 0) : this()
        {
            User                    = user;
            SudokuMatrix            = matrix;
            SudokuMatrix.Difficulty = difficulty;
            SudokuMatrix.SetDifficulty(SudokuMatrix.Difficulty);
            AppId = appId;

            User.Games.Add(this);
        }
Пример #4
0
 public Game()
 {
     Id             = 0;
     DateCreated    = DateTime.UtcNow;
     DateUpdated    = DateTime.MinValue;
     DateCompleted  = DateTime.MinValue;
     ContinueGame   = true;
     Score          = 0;
     KeepScore      = false;
     SudokuMatrix   = new SudokuMatrix();
     SudokuSolution = new SudokuSolution();
     AppId          = 0;
     TimeToSolve    = new TimeSpan();
 }