#include "fbgfx.bi"
Using FB

const num_of_entries = 10 ' Flags the number of entries in the 
                          ' high score file.

DECLARE SUB ReadHighScore (highscore_file AS STRING)
    
DIM SHARED workpage AS INTEGER
DIM SHARED hname(num_of_entries) AS STRING ' Flags high score table names.
DIM SHARED hscore(num_of_entries) AS INTEGER ' Flags high score table scores.

SCREENRES 640, 480, 32, 2, GFX_ALPHA_PRIMITIVES+GFX_WINDOWED
SCREENSET 1, 0

' We need to call our subroutine with the appropriate file
' and then end program.
ReadHighScore "high_scores.dat"
END

SUB ReadHighScore (highscore_file AS STRING)

' Dimension the variable that will hold
' the information about the free
' file handle.
DIM free_filehandle AS INTEGER

' Pass the free file handle to the free_filehandle
' variable.
free_filehandle = FreeFile

' Open our high score file with the free file
' handle for reading (FOR INPUT).
OPEN highscore_file FOR INPUT AS #free_filehandle

' Loop through the high score entries and place
' them in appropriate variables (hname and hscore).
' hscore(1) will hold the highest score, while
' hscore(num_of_entries) the lowest score.
FOR count_entry AS INTEGER = 1 TO num_of_entries
INPUT #free_filehandle, hname(count_entry)
INPUT #free_filehandle, hscore(count_entry)
' If the end of file is reached, exit the FOR loop.
IF EOF(free_filehandle) THEN EXIT FOR
NEXT count_entry

' Close the file we just open.
CLOSE #free_filehandle

' Start a DO...LOOP to display our high score table.
DO

screenlock
screenset workpage, workpage xor 1

' Clear the screen.
LINE (0,0)-(639,479), RGBA(0, 0, 0, 255), BF

' Print TOP SCORES title with WHITE color.
Draw String (285, 120), "TOP SCORES", RGBA(255,255, 255, 255)

' Loop through high score entries, print names and
' scores on appropriate positions, with each new score
' using more translucency. Change * 12 to a higher number
' to get more space between scores.
FOR count_entry AS INTEGER = 1 TO num_of_entries
Draw String (270, 140 + count_entry * 12), hname(count_entry), RGBA(255,255, 255, 250-count_entry*10)
Draw String (340, 140 + (count_entry) * 12), STR$(hscore(count_entry)), RGBA(255,255, 255, 250-count_entry*10)
NEXT count_entry

Draw String (245, 400), "Press ESCAPE to exit", RGBA(255,255, 255, 220)

workpage xor = 1
screenunlock

SLEEP 10

LOOP UNTIL MULTIKEY(SC_ESCAPE) ' Loop until ESCAPE is pressed.

END SUB