class ScoreBoard { // Constructor that takes points and number of records, this constructor will be called if the user doesnt insert the name, and will assing the name to unknown public ScoreBoard(int points, int numberOfRecords) { playerName = "unknown"; playerPoints = points; numberOfSaves = numberOfRecords + 1; } // Constructor that takes all the arguments, this constructor will set the name, points and number of records public ScoreBoard(string name, int points, int numberOfRecords) { playerName = name; playerPoints = points; numberOfSaves = numberOfRecords +1; } //Create a read and set variable called player name that will save the player name public string playerName { get; set; } //Create a read and set variable called Player points that will save the player points public int playerPoints { get; set; } //Create a read only variable called number of saves public int numberOfSaves { get; } } //this will save all the player scores List<ScoreBoard> allPlayerScores = new List<ScoreBoard>(); void sortListScoreboard() { //do a sorting loop for (int i = 0; i < allPlayerScores.Count - 1; i++) { //this loop will check every item with the items from the other for for (int x = 0; x < allPlayerScores.Count - 1; x++) { //check if the item is bigger then this item, if it is just move it up if(allPlayerScores[i].playerPoints>allPlayerScores[x].playerPoints) { int temp = allPlayerScores[x].playerPoints; string tempName = allPlayerScores[x].playerName; allPlayerScores[x].playerPoints = allPlayerScores[i].playerPoints; allPlayerScores[i].playerPoints = temp; allPlayerScores[x].playerName = allPlayerScores[i].playerName; allPlayerScores[i].playerName = tempName; } } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter