Player1,10
Player2,20
Player3,5
I am thinking of splitting this list at the comma into one list containing all the player names and one list containing the scores. I will then use bubble sort procedure described in some tutorials to sort the scores in descending order. However, I am stuck on how to reassign the corresponding player name to each score after the score list has been sorted. Any ideas?
see the High Score example by ABG
alternatively you could think about storing your list as list of lists, each item of the main list is a sublist with the two items player name and score
btw. you do not need to sort your highscores if you add a new score at the correct position in the list...
I tried ABGs method but for some reason it wasn't working for me so I modified it a little. It is working now but it inserts the score into the list twice.
Can anyone look at my blocks and check what I am doing wrong? (The variable 'runcounter' is the score to be inserted in the highscore list.)
From what I can see of your code fragment,
it should insert only one score at a time,
and like my example, it does not rule
out inserting a score if it duplicates one
already on the list.
Maybe you are calling this fragment twice?
I am also unsure why you are skipping the 1st element
of the list.
You were right. The code was being run twice. Also I was skipping the first element because I just put some text in it to be displayed as a title. Problem solved :)
댓글 없음:
댓글 쓰기