コード例 #1
0
        public void Add(string Name, int Points)
        {
            HighscoreEntity newEntry = new HighscoreEntity();

            newEntry.Name   = Name;
            newEntry.Points = Points;

            //neuer eintrag ist besser als letzter eintrag
            if (_scoresList[_scoresList.Length - 1].Points < newEntry.Points)
            {
                _scoresList[_scoresList.Length - 1] = newEntry;
            }

            //liste sortieren
            for (int i = _scoresList.Length - 2; i >= 0; i--)
            {
                if (_scoresList[i].Points < _scoresList[i + 1].Points)
                {
                    HighscoreEntity tempEntity = _scoresList[i + 1];
                    _scoresList[i + 1] = _scoresList[i];
                    _scoresList[i]     = tempEntity;
                }
            }
            SaveFile();
        }
コード例 #2
0
        //laden der XML und schreiben in scoresList
        public void LoadFile()
        {
            XmlDocument highScoreDoc = new XmlDocument();

            highScoreDoc.Load(_filePath);

            _scoresList = new HighscoreEntity[highScoreDoc.ChildNodes[0].ChildNodes.Count];
            int             i = 0;
            HighscoreEntity currentEntry;

            foreach (XmlNode entry in highScoreDoc.ChildNodes[0].ChildNodes)
            {
                if (!string.IsNullOrEmpty(entry.ChildNodes[0].InnerText))
                {
                    currentEntry        = new HighscoreEntity();
                    currentEntry.Name   = entry.ChildNodes[0].InnerText;
                    currentEntry.Points = int.Parse(entry.ChildNodes[1].InnerText);
                    _scoresList[i]      = currentEntry;
                    i++;
                }
            }
        }