public bool IsScoreHighEnough(int score) { Debug.Log("Checking if score is high enough: " + score); bool retval = false; if (scores != null) { if (scores.Count < numScores) { Debug.Log("Score will be high enough because there aren't enough scores"); retval = true; } else if (scores.Count > 0) { Debug.Log("Need to check for lowest score"); MinigameHighscore lowestScore = FindLowestScore(); Debug.Log("Lowest score was " + lowestScore.score); if (lowestScore != null) { if (score >= lowestScore.score) { retval = true; } } } } return(retval); }
public bool AddScore(string name, int score) { bool retval = false; MinigameHighscore thescore = new MinigameHighscore(); thescore.name = name; thescore.score = score; if (scores != null) { if (scores.Count == 0) { Debug.Log("Adding score as first score"); scores.AddFirst(thescore); retval = true; } else { LinkedListNode <MinigameHighscore> before = FindScoreBefore(score); if (before != null) { Debug.Log("Adding score after " + before); scores.AddAfter(before, thescore); retval = true; } else { //Debug.Log("AddScore Error: Before score was null"); //If before was null, (and scores was ok and count > 0) //then there is no before - we must be the highest score. scores.AddFirst(thescore); } } } else { Debug.Log("AddScore Error: scores was null"); } while (scores.Count > numScores) { scores.RemoveLast(); } //inspectorScores = new MinigameHighscore[numScores]; scores.CopyTo(inspectorScores, 0); return(retval); }
MinigameHighscore FindLowestScore() { MinigameHighscore retval = null; //int lowestScore; if (scores != null && scores.Count > 0) { LinkedListNode <MinigameHighscore> node = scores.First; retval = node.Value; int lowestScore = retval.score; while (node.Next != null) { if (node.Value.score < lowestScore) { retval = node.Value; lowestScore = retval.score; } node = node.Next; } } return(retval); }