public void AddEntry(ScoreboardEntryData scoreboardEntryData) { ScoreboardSaveData savedScores = GetSavedScores(); ScoreboardEntryData hashedScoreboardEntryData = CreateIntegrityHash(scoreboardEntryData); Debug.Log("Adding new score entry..."); bool scoreAdded = false; for (int i = 0; i < savedScores.highscores.Count; i++) { if (hashedScoreboardEntryData.entryScore > savedScores.highscores[i].entryScore) { savedScores.highscores.Insert(i, hashedScoreboardEntryData); scoreAdded = true; break; } } if (!scoreAdded && savedScores.highscores.Count < maxScoreboardEntries) { savedScores.highscores.Add(hashedScoreboardEntryData); } if (savedScores.highscores.Count > maxScoreboardEntries) { savedScores.highscores.RemoveRange(maxScoreboardEntries, savedScores.highscores.Count - maxScoreboardEntries); } UpdateUI(savedScores); SaveScores(savedScores); Debug.Log("New entry added succesfully"); }
private ScoreboardEntryData CreateIntegrityHash(ScoreboardEntryData scoreboardEntryData) { string combinedValues = scoreboardEntryData.entryName + scoreboardEntryData.entryScore.ToString(); scoreboardEntryData.entryHash = HashString(combinedValues); return(scoreboardEntryData); }
private ScoreboardEntryData CheckHighScore(ScoreboardEntryData highscore) { string combinedValues = highscore.entryName + highscore.entryScore.ToString(); string hashedString = HashString(combinedValues); if (highscore.entryHash != hashedString) { highscore.entryName = "1337Haxx0r"; highscore.entryScore = 0; highscore.entryHash = HashString(highscore.entryName + highscore.entryScore.ToString()); } return(highscore); }
public void Initialise(ScoreboardEntryData scoreboardEntryData) { entryNameText.text = scoreboardEntryData.entryName; entryScoreText.text = scoreboardEntryData.entryScore.ToString(); }