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;
        }
        private void Load()
        {
            user = User.CurrentUser;

            dataRoulette = new DataRoulette();
            txtPoints.Text = "Points: " + user.CurrentPoints.ToString();

            txtUser.Text = user.NickName + " Level: " + user.Level;
        }
        private void btnNext_Click(object sender, RoutedEventArgs  e)
        {
            GameServiceClient service = new GameServiceClient();
            Task<bool> isAlive = service.IsAlive();

            if (!isAlive.Result)
            {
                MyMessageBox.Show("Error!", "Can not connect to the server. Start up server", MessageBoxButton.OKCancel, MessageBoxImage.Error);
                return;
            }

            string userName = txtNickName.Text;

            //Thread userLoadThread = new Thread(new ParameterizedThreadStart(delegate
            //    {
            //        us = service.LoadUserInfo(userName);
            //    }));

            //Task myTask = new Task((Action)delegate { us = service.LoadUserInfo(userName); });

            //userLoadThread.Join();



            Thread userLoadThread = new Thread(new ThreadStart(() =>
            {
                // Create our context, and install it:
                SynchronizationContext.SetSynchronizationContext(
                    new DispatcherSynchronizationContext(
                        Dispatcher.CurrentDispatcher));

                Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);

                us = service.LoadUserInfo(userName);

                // Start the Dispatcher Processing
                System.Windows.Threading.Dispatcher.Run();
            }));
            // Setup and start thread as before
            userLoadThread.Start();

            userLoadThread.Join();

            User.CurrentUser = us;

            new MenuWindow().Show();
            this.Close();
        }
Exemple #4
0
 /// <summary>
 /// ---------------NOT USEFUL---------------
 /// Add user ot list online users
 /// Create for testing rest service
 /// </summary>
 /// <param name="user">User</param>
 public void AddUserOnline(User user)
 {
     _usersInGame.Add(user);
 }
Exemple #5
0
        /// <summary>
        /// True: load user info if user is exist 
        /// False: can not load info - user is not exist 
        /// </summary>
        /// <returns>True/Falss</returns>
        private bool LoadUserProfile()
        {
            try
            {
                XmlDocument xml = OpenXmlDoc();
                XmlNodeList xnList = xml.SelectNodes("ArrayOfUser");
                foreach (XmlNode xn in xnList)
                {
                    XmlNodeList user = xn.SelectNodes("User");
                    foreach (XmlNode item in user)
                        if(item["NickName"].InnerText == this.NickName && user != null)
                        {
                            _user = new User()
                            {
                                NickName = item["NickName"].InnerText,
                                CurrentPoints = Convert.ToInt32(item["Points"].InnerText),
                                Debt = Convert.ToInt32(item["Debt"].InnerText),
                                Status = item["Status"].InnerText,
                                Level = Convert.ToInt32(item["Level"].InnerText),
                            };

                            _user.Achievements = GetAchievements();
                            _usersInGame.Add(_user);
                            return true;
                        }        
                }
            return false;
            }
            catch (Exception)
            {
                return false;
            }
        }
Exemple #6
0
        /// <summary>
        /// Create new profile if is not exist
        /// </summary>
        private void CreateNewProfile()
        {
            List<User> users = new List<User>();
            User us = new User(NickName, 500, 0, "Junior", 1, new List<Achievement>()); 
            _user = us;
            users.Add(us);
            _usersInGame.Add(us);

            if (!Directory.Exists(_pathToDirectory + "\\" + _fileName))
                Directory.CreateDirectory(_pathToDirectory);

            XmlSerializer serializer = new XmlSerializer(typeof(List<User>));
            using (TextWriter writer = new StreamWriter(_pathToDirectory + "/" + _fileName))
            {
                serializer.Serialize(writer, users);
            }
        }
 public void SaveGame(string nickName, string points, string debt, string status, string level)
 {
     User user = new User(nickName);
     user.CurrentPoints = int.Parse(points);
     user.Debt = int.Parse(debt);
     user.Status = status;
     user.Level = int.Parse(level);
     user.SaveGame();
 }
 public Achievement[] GetUserAchievements(string nickName)
 {
     User us = new User(nickName);
     us = User.CurrentUser;
     return us.Achievements.ToArray();
 }
 public void AddUserOnline(string userNick)
 {
     User us = new User(userNick);
     us.AddUserOnline(User.CurrentUser);
 }
 public User LoadUserInfo(string nickName)
 {
     User user = new User(nickName);
     return User.CurrentUser;
 }
 /// <summary>
 /// Add user in online list of users
 /// </summary>
 /// <param name="user"></param>
 public void AddUserOnline(User user)
 {
     wcfResponse = client.GetAsync("http://localhost:20236/GameService.svc/AddUserOnline/" + user.NickName + "").Result;
     stream = wcfResponse.Content;
     Task<string> data = stream.ReadAsStringAsync();
 }
        private void btnGetCredit_Click(object sender, RoutedEventArgs e)
        {
            User us = new User();
            User.CurrentUser.GetCredit();

            SlideLoad(myUser);
            myUser.DataContext = us;
            myUser.DataContext = User.CurrentUser;
        }
 private void Load()
 {
     _userCurr = User.CurrentUser;
 }