Code: Select all
type HighScore
as string playername
as string score
as string dateof
declare sub Set ( pn as string, inscore as string, indateof as string )
end type
sub HighScore.Set ( pn as string, inscore as string, indateof as string )
this.playername = pn
this.score = inscore
this.dateof = indateof
end sub
#DEFINE MAX_SCORES 20
type HighScoreTable
dim as HighScore Record(MAX_SCORES)
dim as string filename
declare sub Load ( fn as string = "highscores.txt")
declare sub Insert ( in_score as HighScore )
declare sub Save ()
declare sub PrintHST ()
declare sub Display()
end type
sub HighScoreTable.Insert ( in_score as HighScore )
for i as integer = 1 to MAX_SCORES
if val(in_score.score) > val(Record(i).score) then
for ii as integer = MAX_SCORES to i step -1
Record(ii).score = Record(ii-1).score
Record(ii).playername = Record(ii-1).playername
Record(ii).dateof = Record(ii-1).dateof
next
Record(i).score = in_score.score
Record(i).playername = in_score.playername
Record(i).dateof = in_score.dateof
exit for
endif
next
end sub
sub HighScoreTable.Save ()
if filename = "" then filename = "highscores.txt"
open filename for output as #1
for i as integer = 1 to MAX_SCORES
print #1, Record(i).playername
print #1, Record(i).Score
print #1, Record(i).Dateof
next
close #1
end sub
sub HighScoreTable.Load ( fn as string = "highscores.txt" )
open fn for input as #1
for i as integer = 1 to MAX_SCORES
line input #1, Record(i).playername
line input #1, Record(i).Score
line input #1, Record(i).dateof
next
this.filename = fn
close #1
end sub
sub HighScoreTable.PrintHST()
for i as integer = 1 to MAX_SCORES
? i,Record(i).playername, Record(i).Score,Record(i).DateOf
next
end sub
sub HighScoreTable.Display()
for i as integer = 75 to 550 step 25
line ( 800-700,i) - (800-100, i-25),&hfff*RND*1000000,b
next
Draw String (150, 31), "Player", &hff
Draw String (350, 31), "Score", &hff
Draw String (490, 31), "Date", &hff
for i as integer = 1 to MAX_SCORES
Draw String ( 150, 31 + (i*25) ), Record(i).Playername
Draw String ( 350, 31 + (i*25) ), Record(i).Score
Draw String ( 490, 31 + (i*25) ), Record(i).Dateof
next
end sub
'///////////////////////////////////////////////////////////////////////////////
dim as HighScoreTable hst
dim as HighScore hs(20)
for i as integer = 1 to 20
'Generates Random Values
hs(i).score = str(int(rnd*300))
hs(i).playername = str(i)
hs(i).dateof = date
hst.Insert ( hs(i) )
next
screen 19,32
'hst.Load("temp.txt") 'Also sets the filename to save
'st.Save()
hst.Load ("highscores.txt")
hst.Display
sleep