Esempio n. 1
0
        public void AddAchievement(IAchievement achievement)
        {
            var completedAchiemevent =
                new CompletedAchievement(DateTime.Now, achievement);

            CompletedAchievements.Add(completedAchiemevent);
        }
Esempio n. 2
0
        public void CheckForAchievement()
        {
            // Count total kills
            var totalKills = CountDefeatedMonsters();
            // Count Easy kills
            var easyKills = CountDefeatedMonsters(Difficulty.Easy);
            // Count Medium kills
            var mediumKills = CountDefeatedMonsters(Difficulty.Medium);
            // Count Hard kills
            var hardKills = CountDefeatedMonsters(Difficulty.Hard);

            // Sort out already completed Achievements
            var sortedBaseAchievements = (from baseAchieve in BaseAchievements
                                          //from completeAchieve in CompletedAchievements
                                          where !CompletedAchievements.Any(p => p.Achievement.AchievementName == baseAchieve.AchievementName)
                                          select baseAchieve).ToList();

            // Apply Achievements accordingly
            foreach (var achievement in sortedBaseAchievements)
            {
                if (achievement.AchievementType == Difficulty.Easy)
                {
                    if (easyKills >= achievement.AchievementKillAmount)
                    {
                        var completedAchievement = new CompletedAchievement(achievement, DateTime.Now);
                        CompletedAchievements.Add(completedAchievement);
                    }
                }
                else if (achievement.AchievementType == Difficulty.Medium)
                {
                    if (mediumKills >= achievement.AchievementKillAmount)
                    {
                        var completedAchievement = new CompletedAchievement(achievement, DateTime.Now);
                        CompletedAchievements.Add(completedAchievement);
                    }
                }
                else if (achievement.AchievementType == Difficulty.Hard)
                {
                    if (hardKills >= achievement.AchievementKillAmount)
                    {
                        var completedAchievement = new CompletedAchievement(achievement, DateTime.Now);
                        CompletedAchievements.Add(completedAchievement);
                    }
                }
                else if (achievement.AchievementType == Difficulty.none)
                {
                    if (totalKills >= achievement.AchievementKillAmount)
                    {
                        var completedAchievement = new CompletedAchievement(achievement, DateTime.Now);
                        CompletedAchievements.Add(completedAchievement);
                    }
                }
            }
        }