public bool UpdateHighscore(string gameTitle, int score, bool time) { bool isNewScore = true; if (!HasHighscore(gameTitle)) { string type = time ? "TIME" : "SCORE"; Database.AddNewHighscore(baseUser.Id, gameTitle, score, type); HighscoreTableEntry newHighscore = new HighscoreTableEntry(); newHighscore.UserId = baseUser.Id; newHighscore.GameName = gameTitle; newHighscore.Wins = 0; newHighscore.Looses = 0; newHighscore.TimesPlayed = 1; newHighscore.Score = score; newHighscore.Type = type; highScoreList.Add(newHighscore); return(isNewScore); } else { int currentScore = GetHighscore(gameTitle).Score; if (score < currentScore) { score = currentScore; isNewScore = false; } Database.UpdateHighscore(baseUser.Id, gameTitle, score); for (int i = 0; i < highScoreList.Count; i++) { if (highScoreList[i].GameName == gameTitle) { highScoreList[i].TimesPlayed += 1; highScoreList[i].Score = score; } } return(isNewScore); } }
public bool Loose(string gameTitle) { bool isNewScore = true; if (!HasHighscore(gameTitle)) { Database.AddNewWinner(baseUser.Id, gameTitle, 0, 1); HighscoreTableEntry newHighscore = new HighscoreTableEntry(); newHighscore.UserId = baseUser.Id; newHighscore.GameName = gameTitle; newHighscore.Wins = 0; newHighscore.Looses = 0; newHighscore.TimesPlayed = 1; newHighscore.Wins = 0; newHighscore.Looses = 1; newHighscore.Type = "WINLOSS"; highScoreList.Add(newHighscore); return(isNewScore); } else { Database.UpdateHighscoreLooseGame(baseUser.Id, gameTitle); for (int i = 0; i < highScoreList.Count; i++) { if (highScoreList[i].GameName == gameTitle) { highScoreList[i].TimesPlayed += 1; highScoreList[i].Looses++; } } return(isNewScore); } }