コード例 #1
0
        public bool SendPoints(string input, string nickName)
        {
            Achievement achievement = new Achievement();
            List<Achievement> achs = new List<Achievement>();
            
            // Read from xml file current user 
            User user = new User(nickName);
            user = User.CurrentUser;
           
            // Get the Achievements for user in order not to match the sames 
            Achievement[] userAchievements = GetUserAchievements(nickName);

            // Get the current points and check if user has same achievement 
            int points = int.Parse(input);
            Tuple<string, int> tupleRes = achievement.Result(points, userAchievements.ToList());

            if(tupleRes.Item1 != string.Empty && tupleRes.Item2 != 0)
                achs.Add(new Achievement(tupleRes.Item2, tupleRes.Item1, true, PathToAppData("Achievements",
                                         "Achiv" + tupleRes.Item2 + ".png")));

            // If user get achievement we increment the level of user
            if (achs.Count != 0)
                user.Level += 5;

            // Set to user list - current user achivements 
            user.Achievements = achs;
            // Save the game (level)
            user.SaveGame();
            // Save achievements to xml file 
            user.SaveAchievements();
            // Return the value. True - user get achievement, false - vice versa
            return (achs.Count != 0) ? true : false;
        }
コード例 #2
0
        /// <summary>
        /// Get the result from service about achive
        /// True: the user get achive 
        /// False: the user is not get achive
        /// </summary>
        /// <returns>True/False</returns>
        public List<Achievement> GetAchieve(string nickName)
        {
            try
            {
                wcfResponse = client.GetAsync("http://localhost:20236/GameService.svc/UserAchievement/" + nickName + "").Result;
                stream = wcfResponse.Content;
                Task<string> data = stream.ReadAsStringAsync();

                Achievement ach = new Achievement();
                List<Achievement> listAchieves = new List<Achievement>();
                
                dynamic jsArray = (JArray)JsonConvert.DeserializeObject(data.Result.ToString());

                foreach (var item in jsArray)
                {
                    string pathToImage = item.ImagePath;
                    listAchieves.Add(new Achievement()
                        {
                            ImagePath = item.ImagePath,
                            IsDone = item.IsDone,
                            SmallDescription = item.SmallDescription,
                            ImageBytes = Achievement.ConvertPathToImage(pathToImage)
                        });
                }
                return listAchieves;
            }
            catch (AggregateException ex)
            {
                throw new AggregateException(ex.Message);
                // Write to logger;
            }
        }