Try my new website:
www.urcho.com
- the new SIMPLE social network
Sign up
|
284
members |
114
snippets
Search for:
ALL
POPULAR
File Controls
Multiplayer Code
2D Effects
3D Effects
Oldskool demos
Basic Functions
Maths/Physics
Sound
Tutorials
Misc
Username:
Password:
Sign up
High Score Type by ninjarat
[
back
]
Author:
Archive
| Viewed:
596
times | Language:
BlitzMax
| Category:
File Controls
Type scorelist Field list:scoreitem[100] Global listfile:TStream Method init() For j=0 To 99 list[j]=New scoreitem Next open() End Method Method open() ' Print "openning score file" listfile=OpenFile("diamonds.highscores") If Not listfile Then createhiscoresfile() listfile=OpenFile("diamonds.highscores") End If close() End Method Method load() ' Print "loading score data from file stream" listfile=OpenFile("diamonds.highscores") Rem This is not neccecary If Not listfile Then init() save() End If End Rem Local strlen:Byte For j=0 To 99 If Not Eof(listfile) Then list[j].score=listfile.ReadInt() strlen=listfile.ReadByte() list[j].name=listfile.ReadString(strlen) End If Next close() End Method Method save() ' Print "saving score data to file stream" listfile=OpenFile("diamonds.highscores") For j=0 To 99 listfile.WriteInt list[j].score listfile.WriteByte Len(list[j].name) listfile.WriteString list[j].name Next close() End Method Method createhiscoresfile() ' Print "no high scores file found; making new one" CreateFile("diamonds.highscores") listfile=OpenFile("diamonds.highscores") Local examplescores$[]=["BILL","FRANK","JOE","ANN","ROBBIE"] For j=0 To 4 listfile.WriteInt (5-j)*1000 listfile.WriteByte Len(examplescores[j]) listfile.WriteString examplescores[j] Next For j=5 To 99 listfile.WriteInt list[j].score listfile.WriteByte Len(list[j].name) listfile.WriteString list[j].name Next close() End Method Method close() listfile.Close End Method Method sort() End Method End Type
Author Comments:
Simple high scores file handler, and an unfinished method for sorting them.
Login or
create an account
to comment on this snippet