void CompareCards(List <HighScoreCard> newAllCards) // this is the function that compares the score cards among themselves. { List <HighScoreCard> UltimateCardListInOrder = new List <HighScoreCard>(); // this is the list where all the cards will go in order. int listLenght = newAllCards.Count; while (listLenght > 0) { HighScoreCard bestCard = defaultCard; foreach (var card in newAllCards) { if (card.score > bestCard.score) { bestCard = card; } } UltimateCardListInOrder.Add(bestCard); newAllCards.Remove(bestCard); listLenght = newAllCards.Count; } int ultimateListLenght = UltimateCardListInOrder.Count; for (int i = 0; i < ultimateListLenght; i++)// this 2 will go through all the cards in order of score. { highScoreNamesText[i].text = UltimateCardListInOrder[i].playerName; } for (int i = 0; i < ultimateListLenght; i++) { string scoreString = UltimateCardListInOrder[i].score.ToString(); string someString = scoreString.PadLeft(10, '0');// this is what adds the 00 to the left of the score text. highScorePointsText[i].text = someString; } }
public void savePlayerScore()// this is suppose to be called when the player clicks to save their score and name. { playerNameString = inputField.text; if (playerScore < PlayerHighScore.pointsSystem.currentScore) { PlayerPrefs.SetString("playerName", playerNameString); PlayerPrefs.SetInt("playerscore", PlayerHighScore.pointsSystem.currentScore); PlayerPrefs.Save(); } playerScore = PlayerPrefs.GetInt("playerscore"); playerName = PlayerPrefs.GetString("playerName"); HighScoreCard player = new HighScoreCard(playerName, playerScore); allCards.Add(player); foreach (var card in allCards) { newAllCards.Add(card); } CompareCards(newAllCards); Debug.Log(allCards.Count); }