Example #1
0
        private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
        {
            StrikeValue.Text = Gameplay.MaxInRow.ToString();
            ScoreValue.Text = Gameplay.Points.ToString();

            if (Gameplay.Status != Gameplay.STATUS_FINISHED)
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));

            IsolatedStorageSettings.ApplicationSettings.TryGetValue("username", out PlayerName);
            IsolatedStorageSettings.ApplicationSettings.TryGetValue("usercountry", out PlayerCountry);

            if (PlayerName != null && PlayerCountry != null)
            {
                LocalScore = new ScoreResult(Gameplay.Points, PlayerName, PlayerCountry);
                LocalScore.SaveLocal();
            }
        }
Example #2
0
        public void ScoreOnlineHandler(object sender, ScoreEventArgs e)
        {
            XDocument resultXML = XDocument.Parse(e.result);
            var scoresRaw = from score in resultXML.Descendants("player")
                select new
                {
                    PlayerName = score.Attribute("username").Value,
                    ScoreChild = score.Descendants("score")
                };

            List<ScoreResult> scoreList = new List<ScoreResult>();
            foreach(var score in scoresRaw)
            {
                foreach (var pointData in score.ScoreChild)
                {
                    ScoreResult scoreObj = new ScoreResult(Convert.ToInt32(pointData.Attribute("score").Value),
                        score.PlayerName.ToString(), null);

                    String countryIso = pointData.Attribute("data").Value;
                    if (countryIso != null)
                    {
                        Country scoreCountry = (from country in Country.CountryList
                                                where country.Iso == countryIso
                                                select country).FirstOrDefault();

                        if (scoreCountry != null)
                            scoreObj.PlayerCountry = scoreCountry;
                    }

                    scoreList.Add(scoreObj);
                }
            }

            // Uruchomienie metody dodającej pozycję rankingowe przez ten sam wątek
            Deployment.Current.Dispatcher.BeginInvoke(()=>
            {
                AddLadderPlayers(HighscoreOnlineList, scoreList);
                OnlineProgressBar.Visibility = Visibility.Collapsed;
            });
        }
Example #3
0
        private void SubmitScoreBtn_Click(object sender, RoutedEventArgs e)
        {
            var PlayerName = PlayerNameText.Text;

            Country PlayerCountry = null;
            if (CountryList.SelectedItem != null)
            {
                var SelectedCountryText = (CountryList.SelectedItem as Grid).Children.OfType<TextBlock>().FirstOrDefault();

                if (SelectedCountryText != null)
                    PlayerCountry = (
                        from country in Country.CountryList
                        where country.Name == SelectedCountryText.Text
                        select country
                    ).FirstOrDefault();
            }

            if (PlayerName == null || PlayerName == "")
            {
                MessageBox.Show("You need to enter your username.");
            }
            else
            {
                ScoreResult LocalScore = new ScoreResult(Gameplay.Points, PlayerName, PlayerCountry);
                LocalScore.SaveLocal();
                if (!submitPending)
                {
                    submitPending = true;

                    if (PlayerName == null || PlayerCountry == null)
                        NavigationService.Navigate(new Uri("/ScoreSubmit.xaml", UriKind.Relative));
                    else
                    {
                        string uri, postData;
                        LocalScore.SaveOnline(out uri, out postData);

                        ScoreRequests scoreOnline = new ScoreRequests();
                        scoreOnline.RequestSuccessful += new ScoreEventHandler(scoreOnlineSuccess);
                        scoreOnline.RequestFailed += new ScoreEventHandler(scoreOnlineFail);
                        scoreOnline.ProcessRequest(uri, postData);
                    }
                }

                IsolatedStorageSettings.ApplicationSettings["username"] = PlayerName;
                IsolatedStorageSettings.ApplicationSettings["usercountry"] = PlayerCountry;
                IsolatedStorageSettings.ApplicationSettings.Save();

                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
        }