1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
unit UScores;
interface
uses USongs;
procedure ReadScore(var Song: TSong);
procedure WriteScore(var Song: TSong);
procedure AddScore(var Song: TSong; Level: integer; Name: string; Score: integer);
implementation
uses IniFiles, SysUtils;
procedure ReadScore(var Song: TSong);
var
F: TIniFile;
S: string;
P: integer;
Lev: integer;
LevS: string;
begin
F := TIniFile.Create(Song.Path + ChangeFileExt(Song.FileName, '.sco'));
for Lev := 0 to 2 do begin
case Lev of
0: LevS := 'Easy';
1: LevS := 'Normal';
2: LevS := 'Hard';
end;
P := 1;
S := F.ReadString(LevS + IntToStr(P), 'Name', '');
while (S <> '') and (P<=5) do begin
SetLength(Song.Score[Lev], P);
Song.Score[Lev, P-1].Name := S;
Song.Score[Lev, P-1].Score := F.ReadInteger(LevS + IntToStr(P), 'Score', 0);
Inc(P);
S := F.ReadString(LevS + IntToStr(P), 'Name', '');
end;
end;
end;
procedure AddScore(var Song: TSong; Level: integer; Name: string; Score: integer);
var
S: integer;
S2: integer;
begin
S := 0;
while (S <= High(Song.Score[Level])) and (Score <= Song.Score[Level, S].Score) do
Inc(S);
// S has the number for new score
// we create new score
SetLength(Song.Score[Level], Length(Song.Score[Level]) + 1);
// we move down old scores
for S2 := High(Song.Score[Level])-1 downto S do
Song.Score[Level, S2+1] := Song.Score[Level, S2];
// we fill new score
Song.Score[Level, S].Name := Name;
Song.Score[Level, S].Score := Score;
if Length(Song.Score[Level]) > 5 then begin
SetLength(Song.Score[Level], 5);
end;
end;
procedure WriteScore(var Song: TSong);
var
F: TIniFile;
S: integer;
Lev: integer;
LevS: string;
FileName: string;
begin
FileName := Song.Path + ChangeFileExt(Song.FileName, '.sco');
if (not FileExists(FileName)) or (FileExists(FileName) and DeleteFile(FileName)) then begin
// file has been deleted -> creating new file
F := TIniFile.Create(FileName);
for Lev := 0 to 2 do begin
case Lev of
0: LevS := 'Easy';
1: LevS := 'Normal';
2: LevS := 'Hard';
end;
for S := 0 to high(Song.Score[Lev]) do begin
F.WriteString(LevS + IntToStr(S+1), 'Name', Song.Score[Lev, S].Name);
F.WriteInteger(LevS + IntToStr(S+1), 'Score', Song.Score[Lev, S].Score);
end; // for S
end; // for Lev
F.Free;
end; // if
end;
end.
|