private void OnNewHighScore(NewHighScoreArgs args)
    {
        EventHandler <NewHighScoreArgs> handler = NewHighScore;

        if (handler != null)
        {
            handler(this, args);
        }
    }
Exemple #2
0
    private static void OnNewHighScore(NewHighScoreArgs args)
    {
        SaveHighScores();

        EventHandler <NewHighScoreArgs> handler = NewHighScore;

        if (handler != null)
        {
            handler(typeof(HighScoreManager), args);
        }
    }
Exemple #3
0
    /********************************************************************************************/
    /**************************************** BEHAVIOURS ****************************************/
    /********************************************************************************************/

    /// <summary>
    /// Adds a high score to the list. Will not add if it is not higher than the lowest high score.
    /// </summary>
    /// <param name="highScore">The score to add to the list.</param>
    public static void AddHighScore(HighScore highScore)
    {
        if (highScores.Count == 0) //Any score can be added if no high scores exist.
        {
            highScores.Insert(0, highScore);
            NewHighScoreArgs args = new NewHighScoreArgs()
            {
                newScore = highScore.score
            };
            OnNewHighScore(args);
        }
        else
        {
            for (int i = 0; i < highScores.Count; i++) //Find the appropriate ordered position for the new score.
            {
                if (highScore.score > highScores[i].score)
                {
                    highScores.Insert(i, highScore);
                    if (highScores.Count > _maxNumOfHighScores) //cull high scores that exist beyond the limit.
                    {
                        for (int c = highScores.Count - 1; c >= _maxNumOfHighScores; c--)
                        {
                            highScores.RemoveAt(c);
                        }
                    }
                    NewHighScoreArgs args = new NewHighScoreArgs()
                    {
                        newScore = highScore.score
                    };
                    OnNewHighScore(args);
                    return;
                }
            }
            if (highScores.Count < _maxNumOfHighScores)//Any high score can be added if the list is not full.
            {
                highScores.Add(highScore);
                NewHighScoreArgs args = new NewHighScoreArgs()
                {
                    newScore = highScore.score
                };
                OnNewHighScore(args);
            }
        }
    }