예제 #1
0
        public static void Add(Score s)
        {
            highscore.Add(s);

            highscore.Sort(CompareScore);

            SaveInFile();
        }
예제 #2
0
        // ***********************************************************************
        private void UpdateScore()
        {
            // Text eingabe verwalten
            if (Keyboard.GetState().IsKeyUp(lastKey))
            {
                lastKey = Keys.None;
            }
            if (Keyboard.GetState().GetPressedKeys().Length > 0 && lastKey == Keys.None)
            {
                lastKey = Keyboard.GetState().GetPressedKeys()[0];
                if (lastKey == Keys.Back)
                {
                    if (_inputText.Length != 0)
                        _inputText = _inputText.Substring(0, _inputText.Length - 1);
                }
                else if (_inputText.Length < 16)
                {
                    char input = (char)lastKey.GetHashCode();
                    if (char.IsLetterOrDigit(input) || input == ' ')
                        _inputText += (char)lastKey.GetHashCode();
                }

                if (lastKey == Keys.Enter)
                {
                    // Highscore eintragen
                    Score newScore = new Score();
                    newScore.Name = _inputText;
                    newScore.Points = _gameState.GameStatistic.Highscore;
                    newScore.Round = _gameState.GameStatistic.Round;

                    HighscoreHelper.Add(newScore);

                    // Zu Highscore wechseln
                    _updateDelegate = UpdateHighscore;
                    _drawDelegate = DrawHighscore;
                }
            }
        }
예제 #3
0
 // **************************************************************************
 // Vergleicht zwei Scores
 private static int CompareScore(Score x, Score y)
 {
     // ansonsten vergleichen
     if (x.Points > y.Points)
     {
         return 1;
     }
     else if (x.Points < y.Points)
     {
         return -1;
     }
     else
     {
         return 0;
     }
 }