Exemplo n.º 1
0
        /// <summary>
        /// Updates also level status (finished, unlocked, etc.)
        /// </summary>
        /// <param name="puzzle"></param>
        public AfterSolvedInfo UpdateSolved(Puzzle puzzle, int moves)
        {
            var lastPuzzleState = GetSolvedState(puzzle);
            var lastLevelState  = GetLevelState(puzzle.LevelRef);
            var lastTypeStats   = GetTypeStats(puzzle.level.type);

            var newState = EstimateSolvedState(puzzle, moves);

            if (newState <= lastPuzzleState)
            {
                return(AfterSolvedInfo.NoChanges);
            }

            var newStars = GetNewStars(lastPuzzleState, newState);

            db.SetPuzzleState(puzzle, newState);

            if (puzzle.level.IsTutorial)
            {
                Settings.Instance.TutorialDone = true;
            }
            var ass        = new AfterSolvedState(AfterSolvedState.PUZZLE_SOLVED);
            var levelState = GetLevelState(puzzle.LevelRef);

            if (levelState != lastLevelState)
            {
                ass.LevelMastered = (levelState == SolvedState.Mastered);
                ass.LevelFinished = (levelState == SolvedState.Finished) || ((levelState == SolvedState.Mastered) && lastLevelState == SolvedState.Unsolved);
            }
            ass.LevelUnlocked = AnyLevelUnlocked(stars, stars + newStars);

            var typeStats = GetTypeStats(puzzle.level.type);

            if (typeStats.State != lastTypeStats.State)
            {
                ass.TypeMastered = (typeStats.State == SolvedState.Mastered);
                ass.TypeFinished = (typeStats.State == SolvedState.Finished) || ((typeStats.State == SolvedState.Mastered) && (lastTypeStats.State == SolvedState.Unsolved));
            }

            var levelStats  = db.GetLevelStats(AllLevels.Select(l => l.Ref));
            var numMastered = levelStats.Values.Where(s => s.State == SolvedState.Mastered).Count();
            var numFinished = levelStats.Values.Where(s => s.State == SolvedState.Finished).Count();

            ass.AllLevelsMastered = (numMastered == NUM_LEVELS);
            ass.AllLevelsFinished = (numFinished == NUM_LEVELS);

            return(new AfterSolvedInfo(newStars, ass));
        }
Exemplo n.º 2
0
 public AfterSolvedInfo(int newStars, AfterSolvedState state)
 {
     this.state    = state;
     this.newStars = newStars;
 }