Esempio n. 1
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            XmlNodeList _names = null, _scores = null;
            bool        fileExists = true;

            try
            {
                StorageFile st = await ApplicationData.Current.LocalFolder.GetFileAsync("score.xml");

                dom = await XmlDocument.LoadFromFileAsync(st);

                _names  = dom.GetElementsByTagName("name");
                _scores = dom.GetElementsByTagName("highscore");
            }
            catch (Exception)
            {
                fileExists = false;
            }

            playerTable = new ObservableCollection <Player>();

            if (fileExists)
            {
                for (int i = 0; i < _names.Count; i++)
                {
                    string name  = _names.ElementAt(i).InnerText;
                    int    score = Int32.Parse(_scores.ElementAt(i).InnerText);
                    playerTable.Add(new Player(name, score));
                }
            }

            playerTable = new ObservableCollection <Player>(playerTable.OrderByDescending(player => player.Score));
            playerTable = new ObservableCollection <Player>(playerTable.Take(10));

            foreach (var elem in playerTable)
            {
                LeaderBoardControl control = new LeaderBoardControl(elem.Name, elem.Score);
                leaderBoardList.Items.Add(control);
            }
        }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            XmlNodeList _names = null, _scores = null;
            bool fileExists = true;
            try
            {
                StorageFile st = await ApplicationData.Current.LocalFolder.GetFileAsync("score.xml");
                dom = await XmlDocument.LoadFromFileAsync(st);

                _names = dom.GetElementsByTagName("name");
                _scores = dom.GetElementsByTagName("highscore");
            }
            catch (Exception)
            {
                fileExists = false;
            }

            playerTable = new ObservableCollection<Player>();

            if (fileExists)
            {                
                for (int i = 0; i < _names.Count; i++)
                {
                    string name = _names.ElementAt(i).InnerText;
                    int score = Int32.Parse(_scores.ElementAt(i).InnerText);
                    playerTable.Add(new Player(name, score));
                }
            }

            playerTable = new ObservableCollection<Player>(playerTable.OrderByDescending(player => player.Score));
            playerTable = new ObservableCollection<Player>(playerTable.Take(10));

            foreach (var elem in playerTable)
            {
                LeaderBoardControl control = new LeaderBoardControl(elem.Name, elem.Score);
                leaderBoardList.Items.Add(control);
            }

        }