List <ScoreModel.HighScoreInformation> highScoresList; //list of high score from score model ///<description>Set Final score on game finish and update high score list (in View)</description> void EvaluateScore() { ScoreModel.HighScoreInformation currentScoreInfo = new ScoreModel.HighScoreInformation("Enter Name To Save Score...", score); highScoresList = scoreModel.GetHighScoreList(); int rank = 1; scoreRank = highScoresList.Count + 1; scoreView.OnHighScoreBeat(false); for (; rank <= highScoresList.Count; rank++) { if (highScoresList[rank - 1].score < score) { scoreRank = rank; break; } } if (scoreRank <= highScoresList.Count) { rank = highScoresList.Count; for (; rank > scoreRank; rank--) { highScoresList[rank - 1] = highScoresList[rank - 2]; } highScoresList[scoreRank - 1] = currentScoreInfo; scoreView.OnHighScoreBeat(true); } scoreView.SetHighScoreUIForList(highScoresList); }
///<description>Called by UI to save name of player with high score</description> public void UpdateHighScoreHolderName(string name) { if (scoreRank < 1 || scoreRank > highScoresList.Count) { return; } scoreView.SetHighScoreUIForRank(scoreRank, name, score); highScoresList[scoreRank - 1] = new ScoreModel.HighScoreInformation(name, score); scoreModel.SaveHighScoreList(highScoresList); }