public void LoadLeaderboard(LeaderboardType type) { SortLeaderboards(); string leaderboard = ""; switch (type) { case LeaderboardType.MostWins: leaderboard = "<b><size=50>Most Wins</size></b>\n"; for (int i = 0; i < 10; i++) { leaderboard += (i + 1) + ". "; if (mostWins.Count > i) { string id = mostWins.ElementAt(i).Key; string displayName = tc.GetDisplayName(id).Result; leaderboard += displayName + " - " + mostWins[id]; } if (i != 10) { leaderboard += "\n"; } } break; case LeaderboardType.MostGuesses: leaderboard = "<b><size=50>Most Guesses</size></b>\n"; for (int i = 0; i < 10; i++) { leaderboard += (i + 1) + ". "; if (mostGuesses.Count > i) { string id = mostGuesses.ElementAt(i).Key; string displayName = tc.GetDisplayName(id).Result; leaderboard += displayName + " - " + mostGuesses[id]; } if (i != 10) { leaderboard += "\n"; } } break; case LeaderboardType.MostAccurate: break; } StartCoroutine(changeLeaderboardInfoText(leaderboard, type)); }
IEnumerator DisplayNextGuess() { displayingGuess = true; KeyValuePair <string, int> nextGuess = queuedGuesses.Dequeue(); guessesUi.Dequeue(); string name = tc.GetDisplayName(nextGuess.Key).Result; infoText.text = $"{name} guessed {nextGuess.Value}!!!"; guessBarText.text = $"{name}'s guess"; guessBar.SendMessage("ChangeValue", nextGuess.Value); UpdateLeaderboard(nextGuess.Key, LeaderboardUpdater.LeaderboardType.MostGuesses); // Update Leaderboard yield return(new WaitForSeconds(1)); yield return(new WaitUntil(() => guessBar.GetComponent <ChangeBarValue>().idle)); yield return(new WaitForSeconds(1)); if (nextGuess.Value == currentNumber) // The number is correct, restart { UpdateLeaderboard(nextGuess.Key, LeaderboardUpdater.LeaderboardType.MostWins); // Update Leaderboard infoText.text = $"And {nextGuess.Value} is correct! {name} has guessed the number and wins!!!"; generatedBarText.text = "The number was " + currentNumber; guessBarText.text = name + " won!"; yield return(new WaitForSeconds(5)); infoText.text = "Restarting..."; yield return(new WaitForSeconds(2)); StopAndRestart(); } else { string highOrLow = nextGuess.Value > currentNumber ? "high" : "small"; infoText.text = $"But {nextGuess.Value} is too {highOrLow}!"; } if (DistanceFromNumber(nextGuess.Value) < DistanceFromNumber(bestGuess.Value) || bestGuess.Key == null) { bestGuess = new KeyValuePair <string, int>(name, nextGuess.Value); } yield return(new WaitForSeconds(3)); if (queuedGuesses.Count > 0) { StartCoroutine(DisplayNextGuess()); } else { displayingGuess = false; DisplayBestGuess(); } }