// Fills the list view component with the leaderboard data for the passed game mode private async void FillListView(Gamemode currentGameMode) { // Creates the leaderboard manager for the passed gamemode this.leaderboardManager = new LeaderboardController(currentGameMode); // Clear the leaderboard view of any items this.leaderboardListView.Items.Clear(); // Get the leaderboard data from the database List <LeaderboardData> leaderboardData = await this.leaderboardManager.GetLeaderboard(); // Goes through each record of the database ordered by score in descending order int counter = 1; foreach (var record in leaderboardData.OrderByDescending(l => l.Score)) { // Form the rank of each score - if it's below 10 add a zero ifront of the digit string rank = counter < 10 ? "0" + counter : counter.ToString(); // Form the rank row string result = $@" {rank}. {record.Username} - {record.Score} pt."; // Create list view item with the formated result ListViewItem listViewItem = new ListViewItem(result); listViewItem.IndentCount = 4; // Add the list view item inside the listview this.leaderboardListView.Items.Add(listViewItem); // Increase the counter counter++; } }
public LeaderboardPrompt(int playerScore, LeaderboardController leaderboardManager) { // Set the current player's score this.playerScore = playerScore; this.leaderboardManager = leaderboardManager; InitializeComponent(); // Hide the error message errorMessage.Visible = false; }