Exemplo n.º 1
0
 private void play_Click(object sender, RoutedEventArgs e)
 {
     var p = new Parameters();
     p.Level = 1;
     p.Name = playerNameTxt.Text;
     p.Score = 0;
     p.Counter = 5;
     Frame.Navigate(typeof(Level), p);
 }
Exemplo n.º 2
0
        private async void nextButton_Click_1(object sender, RoutedEventArgs e)
        {
            if ("Exit".Equals(nextButton.Content.ToString()))
            {
                StorageFile st = null;
                bool exists = true;
                XmlNodeList _names = null, _scores = null;
                try
                {
                    st = await ApplicationData.Current.LocalFolder.GetFileAsync("score.xml");
                    dom = await XmlDocument.LoadFromFileAsync(st);
                    _names = dom.GetElementsByTagName("name");
                    _scores = dom.GetElementsByTagName("highscore");
                }
                catch (Exception)
                {
                    exists = false;
                }

                if (!exists)
                {
                    st = await ApplicationData.Current.LocalFolder.CreateFileAsync("score.xml");
                }

                ObservableCollection<Player> playerTable = new ObservableCollection<Player>();
                if (_names != null)
                {
                    for (int i = 0; i < _names.Count; i++)
                    {
                        string tempName = _names.ElementAt(i).InnerText;
                        int tempScore = Int32.Parse(_scores.ElementAt(i).InnerText);
                        playerTable.Add(new Player(tempName, tempScore));
                    }
                }

                playerTable.Add(new Player(playerName, score));

                dom = new XmlDocument();
                x = dom.CreateElement("users");
                dom.AppendChild(x);
                foreach (var elem in playerTable)
                {
                    XmlElement x1 = dom.CreateElement("user");
                    XmlElement x11 = dom.CreateElement("name");
                    x11.InnerText = elem.Name;
                    x1.AppendChild(x11);
                    XmlElement x12 = dom.CreateElement("highscore");
                    x12.InnerText = elem.Score.ToString();
                    x1.AppendChild(x12);
                    x.AppendChild(x1);
                }

                await dom.SaveToFileAsync(st);

                Frame.Navigate(typeof(MainPage));
            }
            else
            {
                var param = new Parameters();
                param.Score = this.score + 10 + this.levelCount;
                param.Name = this.playerName;
                param.Level = this.levelCount + 1;
                param.Counter = this.futureCounter;
                Frame.Navigate(typeof(Level), param);
            }
        }