void Update_Scores() { for (int i = 0; i < num_of_scores; i++) { scores score_to_add = new scores(); score_to_add.gold = PlayerPrefs.GetInt(i.ToString(), 0); score_to_add.name = PlayerPrefs.GetString((i + 5).ToString(), "---"); highscore[i] = score_to_add; score_text[i].text = score_to_add.name + ": " + score_to_add.gold; } }
public static async Task <Leaderboard> GetLeaderboard(string order_by, string order, int limit) { scores scores = await ScoreoidClient.GetBestScoresAsync(order_by, order, limit); int rank = 1; return(new Leaderboard(from _ in scores.items select new LeaderboardItem { Rank = rank++, Player = _.username, Score = _.scores.First().value })); }
public int CompareScores(scores s1, scores s2) { if (s1.score < s2.score) { return(-1); } else if (s1.score == s2.score) { return(0); } else if (s1.score > s2.score) { return(1); } return(0); }
public void SendHighScore() { if (_namePlayer != null) { Load(); scores newScore = new scores(); newScore.score = _score; newScore.name = string.Copy(_namePlayer); _highScoreList.Insert(0, newScore); _highScoreList.Sort(CompareScores); if (_highScoreList.Count > 14) { _highScoreList.RemoveAt(0); } Save(); SceneManager.LoadScene("ScoreBoard"); } }
// Use this for initialization void Start() { ds = GameObject.FindGameObjectWithTag("Data").GetComponent <Data_Script>(); player_score_text.text = "Your score: " + ds.gold_amount.ToString(); submit_button.onClick.AddListener(() => Add_Highscore()); menu_button.onClick.AddListener(() => Return_To_Menu()); for (int i = 0; i < num_of_scores; i++) { scores score_to_add = new scores(); score_to_add.name = "---"; score_to_add.gold = 0; highscore.Add(score_to_add); } Update_Scores(); }
void Add_Highscore() // Adds a highscore to the score board (after checking if it is highest than the lowest score on there) { if (!is_submitted) { int counter = 0; bool is_new_highscore = false; foreach (var score in highscore) { if (ds.gold_amount > score.gold) { scores score_to_add = new scores(); score_to_add.name = input_name.text; score_to_add.gold = ds.gold_amount; highscore.Insert(counter, score_to_add); is_new_highscore = true; break; } counter++; } if (is_new_highscore) { highscore.RemoveRange(5, 1); } for (int i = 0; i < num_of_scores; i++) { scores score_to_add = new scores(); score_to_add = highscore[i]; PlayerPrefs.SetInt(i.ToString(), score_to_add.gold); PlayerPrefs.SetString((i + 5).ToString(), score_to_add.name); } Update_Scores(); is_submitted = true; } }