Computer Science Canada Another Highscore Technique |
Author: | GregLP [ Thu Jan 19, 2006 11:15 pm ] | ||||||||
Post subject: | Another Highscore Technique | ||||||||
While I was making my first game with actual highscore, I discovered a very quick way to record the numbers. It starts off with a procedure to get the scores out of the file: The array which has the highscores from the file should be one greater in number of elements than the total number of highscore places you would like. (so, have 1..11 if you want 10 spaces)
This procedure accesses the file High_Score and gets all the values in it into the array (In this tutorial I used 10 values in the file) Then, the 11th element gets the time/score that the user just got:
Now, use a sort procedure to rearrange the array into lowest to highest:
This procedure looks complicated but all it does is sort the array. Now, put to file only the first 10 elements. (This is why the End variable is set to 10)
This of course only puts the first 10 elements and drops the 11th. No fuss. I have found this technique to be rock solid and have had no problems with it. If you have any questions or can think of a much better way to do the same thing then speak up! |
Author: | NikG [ Thu Mar 16, 2006 5:13 pm ] |
Post subject: | |
Pretty good! It seems so logical now that you've shown it. Edit: +5 bits |
Author: | Cervantes [ Thu Mar 16, 2006 7:27 pm ] | ||||
Post subject: | Re: Another Highscore Technique | ||||
Thanks for the concise tutorial. GregLP wrote:
A few things, here.
Edit: Can't spell. |
Author: | [Gandalf] [ Sun Mar 19, 2006 1:51 am ] |
Post subject: | |
This is actually the thread that prompted me to post my High Scores Class. Note that you do not need a sorting algorithm for high scores, as long as the scores are sorted when they are first created. You only need to check if the new score was higher than a previous score, if so replace it and move all the other scores down one slot. Yes, shameless plug. =) |