Exemple #1
0
    private void SetHighScoresList()
    {
        string text = "";
        SortedList <int, HighScore> highScores = HighScoreUtils.GetHighScores();
        int         count = highScores.Count;
        IList <int> keys  = highScores.Keys;

        for (int i = 0; i < count && i < HighScoreUtils.MAX_HIGH_SCORES; i++)
        {
            int       nextEntryNum = (i + 1);
            HighScore current      = highScores[keys[i]];
            text += string.Format(HIGH_SCORE_FORMAT, nextEntryNum, current.Initials, current.Score);
        }

        GetComponent <Text>().text = (text != null) ? text : DEFAULT;
    }
    public void OnEnterNewHighScore()
    {
        string initials = GetComponent <InputField>().text;

        if (initials == null || initials.Length == 0)
        {
            AccessDeniedSound.Play();
            return;
        }

        HUDInventoryAndScoreController scoreController = (HUDInventoryAndScoreController)Object.FindObjectOfType(typeof(HUDInventoryAndScoreController));
        int score = scoreController.GetCurrentScore();

        HighScoreUtils.AddHighScore(initials, score);

        SceneManager.LoadScene("HighScoreScene");
    }
    private bool IsNewHighScore()
    {
        HUDInventoryAndScoreController scoreController = (HUDInventoryAndScoreController)Object.FindObjectOfType(typeof(HUDInventoryAndScoreController));
        int score = scoreController.GetCurrentScore();
        SortedList <int, HighScore> highScores = HighScoreUtils.GetHighScores();

        if (highScores.Count < 10)
        {
            return(true);
        }

        foreach (HighScore highScore in highScores.Values)
        {
            if (score >= highScore.Score)
            {
                return(true);
            }
        }

        return(false);
    }