 |
 |

11-14-2011, 12:40 AM
|
|
Newcomer
|
|
Join Date: Nov 2011
Posts: 2
|
|
Game Leaderboard Logic
|
I'm covering a class where one student is building a game in VisualBasic. The game operates fine, but he is having issues with the Leaderboard. Together we've worked out how to compare and log high scores and then print them to screen in the correct order, but we can't seem to implement this when the new score is THE SAME as a previous score. We can't seem to figure out the code for JOINT high scores.
Has anybody got any idea's for how we can fix this please? I'm sure this is just a logic issue with how we've gone about this, but I'm out of my depth.
Thank you.
|
|

11-14-2011, 03:38 AM
|
 |
Junior Contributor
|
|
Join Date: Nov 2008
Location: Glasgow, UK
Posts: 328
|
|
|
Hi Josh and welcome to XVBT.
Perhaps a snippet of the code you have came up with might help shed some light on what the problem might be? It would also make people more willing to help - no one can help when they don't really know the problem!
|
__________________
Artificial Intelligence is no match for natural stupidity
|

11-14-2011, 07:53 AM
|
|
Newcomer
|
|
Join Date: Nov 2011
Posts: 2
|
|
|
Thanks TheRealTinTin!
Basically we've constructed the Leaderboard Logic around a series of If loops. I'm sure there will be a smarter way of doing this, but I felt more comfortable with this approach whilst we were getting out heads around the problem. It's been a few years since I've done any programming and it's not really my field.
intstore0 = the new score from the game
The code compares the new score to see if it's greater than the previous score stored in each respective 1st, 2nd, 3rd, etc position from the Leaderboard (a series of If loops for each comparison). If the new score fits the criteria for one of the If loops then it will action the code within the loop. So it will put the newscore in the correct place and re-shuffle the previous scores (which have been kept in a "store" buffer) to their new correct position. Once this has happened the positions on the Leaderboard are backed up in the "store" ready for the next game.
Please find a snippet of code below:
If intstore0 > intstore1 Then
int1st = intstore0
int2nd = intstore1
int3rd = intstore2
int4th = intstore3
int 5th = intstore4
Lbl1st = textName.Text
Lbl2nd = onename
Lbl3rd = twoname
Lbl4th = threename
Lbl5th = fourname
Any help would be greatly appreciated- thank you.
|
|

11-14-2011, 02:31 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|
For a tie, the general rule is the second person to reach that score goes under the first person to reach that score.
So, for simplicity, you should simply start at the end of the list, not the top.
If the new score is not higher than the bottom score it won't make the list (doesn't matter if you tie the bottom high scorer).
If the new score is higher than the bottom score, you know it belongs somewhere on the list, so now you just work your way up the list i.e.
If the new score is higher than next highest, move the next highest down, and check then next.
If the new score is not higher than the next highest, then write it in the slot you are currently at.
If you reach the top of the list, and the new score is higher, then you will move the top down and write the new score there.
That logic will automatically write a new tied score beneath the previous scorer with the same value, shift the needed players down, and be done with it in one pass.
If would help if you used an array to store the scores and names, rather than uniquely named variables, that way you could handle any desired number of high scorers using the same code, in a loop, rather than several lines of code for each place.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Last edited by passel; 11-15-2011 at 07:48 AM.
Reason: Changed "down" to "done"
|

11-15-2011, 02:22 AM
|
 |
Junior Contributor
|
|
Join Date: Nov 2008
Location: Glasgow, UK
Posts: 328
|
|
Quote:
Originally Posted by passel
If would help if you used an array to store the scores and names
|
As Passel suggests, an array would be your best option. This would shorten your code and make it easier to manage/amend if you wanted to change from say Top 10 to Top 100, not to mention easier to read also 
|
__________________
Artificial Intelligence is no match for natural stupidity
Last edited by passel; 11-15-2011 at 07:49 AM.
Reason: Changed "ready" to "read"
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|