Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

having top 3 scores.......

Status
Not open for further replies.

kuja

Programmer
Jan 12, 2003
7
GB
ok,i got a file which records the top score in a snake game i'm making and everytime the top score is beaten the file is updated and saved.but instead of having 1 top score i wanna have 3 top scores.so if top score 1 is beaten then top score 1 becomes top score 2 and top score 2 will become top score 3 and top score 1 will be the new top score.basically a systme that records the top 3 scores.
any suggestions?
cheers
 
Read the scores (and name if applicable) into arrays.
Sort the scores array (and name array if applicable) and save them back to the file.

There's plenty of sort routine examples out there. my favorite is QuikSort because it's probably the fastest.
 
To show you some code from Buff1's idea:

DIM scores(3)
OPEN highsc.cfg FOR RANDOM AS #1 LEN = 4
FOR t = 1 TO 3
GET #1, T, scores(t) 'gets the scores
NEXT
IF score(1) < score(2) THEN SWAP score(1), score(2)
IF score(2) < score(3) THEN SWAP score(2), score(3)
IF score(1) < score(2) THEN SWAP score(1), score(2)
FOR t = 3 TO 1 STEP -1
PRINT score(t)
NEXT


in this demo the score(3) is the highest and score(1) is the lowest

the scores also must be less that 4,294,967,296
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top