Creating a high score table
Blitz3D Forums/Blitz3D Programming/Creating a high score table
| ||
Wotcha, folks. I swear blind that I've read in a book somewhere the technique used in sorting an array of numbers into order for use on a high score table. Does anyone know the book or, failing that, how to code one? My brain shuts down when I consider what to do when you have 2 scores the same. Many thanks. Tobo |
| ||
Here's some ancient code that should give you the general idea...Const MAX_HISCORES = 10 Dim hi_scores(MAX_HISCORES) Graphics 400, 300, 0, 2 SeedRnd MilliSecs() Repeat Cls For s=1 To MAX_HISCORES Text 10, s * 12, "No" + RSet$("0" + s, 2) + " - " + RSet$("000" + hi_scores(s - 1), 4) Next Text 10, 160, "Any key to add new score" Text 10, 200, "Last entry " + RSet$("000" + r, 4) If in Text 140, 200, "was a hiscore (No:" + in + ")" Else Text 140, 200, "wasn't a hiscore" EndIf WaitKey() r = Rand(1000) in = insert_hi_score(r) Flip Until KeyHit(1) End Function insert_hi_score(score) Local s, t, p = MAX_HISCORES hi_scores(MAX_HISCORES) = score For s=0 To MAX_HISCORES - 1 If hi_scores(MAX_HISCORES) > hi_scores(s) t = hi_scores(s) hi_scores(s) = hi_scores(MAX_HISCORES) hi_scores(MAX_HISCORES) = t If s < p Then p = s EndIf Next If p < MAX_HISCORES Then Return (p + 1) End Function |