Esempio n. 1
0
        public bool TryGetLevel(LevelConfiguration level, out HighestScorePerLevel output)
        {
            output = null;
            foreach (var completedLevel in CompletedLevels)
            {
                if (completedLevel.Level == level)
                {
                    output = completedLevel;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 2
0
        public HighestScorePerLevel GetLevelOrDefault(LevelConfiguration level)
        {
            foreach (var completedLevel in CompletedLevels)
            {
                if (completedLevel.Level == level)
                {
                    return(completedLevel);
                }
            }

            return(new HighestScorePerLevel
            {
                Level = level,
                HighestScore = new IntCurrency
                {
                    Variable = TotalScore.Variable,
                    Amount = 0
                }
            });
        }
Esempio n. 3
0
        public IntCurrency SetOrAddScore(LevelConfiguration level, IntCurrency newScore)
        {
            if (TryGetLevel(level, out var levelScore))
            {
                int oldAmount = levelScore.HighestScore.Amount;
                int newAmount = newScore.Amount;

                if (newAmount > oldAmount)
                {
                    int diff = newAmount - oldAmount;
                    levelScore.HighestScore.Amount = newAmount;

                    return(new IntCurrency
                    {
                        Amount = diff,
                        Variable = newScore.Variable
                    });
                }
                else
                {
                    return(new IntCurrency
                    {
                        Amount = 0,
                        Variable = newScore.Variable
                    });
                }
            }
            else
            {
                CompletedLevels.Add(
                    new HighestScorePerLevel
                {
                    Level        = level,
                    HighestScore = newScore
                });
            }

            return(newScore);
        }