Code: Select all
;DeleteFile("scores.bin")
; Gestion des Scores
Dim HS[10], HS1[10]
Dimstr N$[10], N1$[10]
score = 1235462
b$="Gagnant"
;
; Création du fichier Highscores
;
Function fn_Creation()
For i=1 To 10
HS[i]=20000*(11-i)
N$[i]=AddStr("Tarzin",i)
Next
tablescores = {HS[1], HS[2], HS[3], HS[4], HS[5], HS[6], HS[7], HS[8], HS[9], HS[10], N$[1], N$[2], N$[3], N$[4], N$[5], N$[6], N$[7], N$[8], N$[9], N$[10]}
OpenFile(1, "scores.bin", #MODE_WRITE)
WriteTable(1, tablescores)
CloseFile(1)
EndFunction
;
; Lecture du fichier Highscores
;
Function fn_Lecture()
OpenFile(1, "scores.bin", #MODE_READ)
tablescores = ReadTable(1)
CloseFile(1)
For Local lect=0 To 9
HS[lect+1]=tablescores[lect]
N$[lect+1]=tablescores[lect+10]
Next
EndFunction
;
; Sauvegarde du fichier Highscores
;
Function fn_Sauvegarde()
;For Local i=1 To 10 scores={HS[i]} noms={N$[i]} Next
; tablescores = {scores, noms}
tablescores = {HS[1], HS[2], HS[3], HS[4], HS[5], HS[6], HS[7], HS[8], HS[9], HS[10], N$[1], N$[2], N$[3], N$[4], N$[5], N$[6], N$[7], N$[8], N$[9], N$[10]}
OpenFile(1, "scores.bin", #MODE_WRITE)
WriteTable(1, tablescores)
CloseFile(1)
EndFunction
;
; Tri des Scores
;
Function fn_Tri()
For i=1 To 10
If score > HS[i] And flag=False
HS1[i]=score
N1$[i]=b$
flag=True
For c=i To 10
HS1[c+1]=HS[c]
N1$[c+1]=N$[c]
Next
For x=1 To 10
HS[x]=HS1[x]
N$[x]=N1$[x]
Next
Else
HS1[i]=HS[i]
N1$[i]=N$[i]
EndIf
Next
flag=False
fn_sauvegarde()
fn_Affichage()
EndFunction
;
; Affichage des Scores
;
Function fn_Affichage()
For Local a=1 To 10
NPrint (a, hs[a], "", n$[a])
Next
WaitLeftMouse()
End
EndFunction
;
; Test de l'existence du fichier
;
If Exists("scores.bin")<>1
fn_Creation()
Else
fn_Lecture()
EndIf
;
; Execution en fonction des cas
;
If score < HS[10] ; Pas de tri/Score inférieur
fn_Affichage()
EndIf
If score > HS[10] ; Pas de tri/Score identique
For Local i=1 To 10
If score = HS[i]
fn_affichage()
EndIf
Next
fn_Tri() ; Tri a effectuer
EndIf
Code: Select all
tablescores = {HS[1], HS[2], HS[3], HS[4], HS[5], HS[6], HS[7], HS[8], HS[9], HS[10], N$[1], N$[2], N$[3], N$[4], N$[5], N$[6], N$[7], N$[8], N$[9], N$[10]}
Code: Select all
;
; Sauvegarde du fichier Highscores
;
Function fn_Sauvegarde()
tablescores = {HS[1], HS[2], HS[3], HS[4], HS[5], HS[6], HS[7], HS[8], HS[9], HS[10], N$[1], N$[2], N$[3], N$[4], N$[5], N$[6], N$[7], N$[8], N$[9], N$[10]}
OpenFile(1, "scores.bin", #MODE_WRITE)
WriteTable(1, tablescores)
CloseFile(1)
EndFunction
For Local i=1 To 10 scores={HS} noms={N$} Next
tablescores = {scores, noms}
ou For Local i=1 To 10 scores={HS} noms={N$} Next
tablescores = scores + nom (enfin pas les additionner mais joindre les tables à la suite)
Une idée?