News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Highscore-table

Started by Sigtrygg, August 25, 2012, 03:28:29 PM

Previous topic - Next topic

Sigtrygg

Hello Community!

Here is the source code of highscore-table, that I used for my game Hell Eagle.

Greetings

Sigtrygg

PlayBASIC Code: [Select]
; PROJECT : Highscore Multi
; AUTHOR : R.D.
; CREATED : 15.08.2012
; EDITED : 25.08.2012
; ---------------------------------------------------------------------

;-----------------------------Highscore-Routine------------------------------------------
#Include "input"
LoadFont "Ariel",3,24,5
LoadFont "Ariel",2,22,0

Global Score=6000; here you change your score for testing

Global screenwidth=1024
Global screenheight=768
Dim player$(15)
Dim highscore(15)
OpenScreen screenwidth,screenheight,16,2


File$=("Highscore.txt")

If FileExist(File$)=true
ReadFile File$,1
For t=1 To 15
player$(t)=ReadString$(1)
highscore(t)=ReadInt(1)
Next t
CloseFile 1
EndIf
Sync


Sync
;-------------------------------- compare new highscore with old highscore -------------
For t=1 To 15
If Score>highscore(1)
SetFont 2
CenterText screenwidth/2,screenheight/3-100, "YOU HAVE A NEW HIGHSCORE !!!"
SetFont 1
EndIf
If Score>highscore(t)
For ul=15 To t Step -1 ;here the scores move one position down until the new score
highscore(ul)=highscore(ul-1)
player$(ul)=player$(ul-1)
Next ul
highscore(t)=Score
CenterText screenwidth/2,screenheight/3+40, "Your Score: "+Str$(score)
LoadFont "Arial",20,40,0

SetCursor screenwidth/2-100,screenheight/3+80
player$(t)=StaticInput("Please input your name: ")
ExitFor
EndIf
Next

WriteFile File$,1
For t=1 To 15
WriteString 1,player$(t)
WriteInt 1,highscore(t)
Next
CloseFile(1)


Cls(0)
BoxC 0,0,screenwidth,screenheight,1,RndRGB()
BoxC 60,60,screenwidth-60,screenheight-60,1,RGB(0,0,0)
Ink RGB(0,255,0)
SetFont 3
Text screenwidth/2-105,screenheight/3-50,"List of best players"
SetFont 2
For t=1 To 15
ur=ur+20
Text screenwidth/2-100,screenheight/3-30+ur,Str$(t)+". "+player$(t)
Text screenwidth/2+20,screenheight/3-30+ur, highscore(t)
Next


Sync
FlushKeys
WaitKey

Cls (0)
end




 Edit: Added some CODE tags around the snippet