This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHISCORE.PAS
243 lines (205 loc) · 4.98 KB
/
HISCORE.PAS
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
(*
** High score functions
*)
unit HiScore;
(**********************************************************)
(**) (**)
(**) INTERFACE (**)
(**) (**)
(**********************************************************)
uses Dos, Crt,
Global, Display;
const
HSnameLen = 10;
HSentryLen = HSnameLen + 11 + 2 + 10;
HSnum = 10;
HSfname = 'ASCSCRAM.HIS';
HStitleY = 2;
HSlistY = 6;
HSlistStep = 1;
type
HSentryRec = record
name : string[HSnameLen];
score: LongInt;
day : word;
month: word;
year : word;
end;
var
HSentry: array[1..LevelNum, 1..HSnum] of HSentryRec;
procedure HighScoreScreen;
function CheckHiScore(newscore: LongInt): byte;
procedure EnterHiScore(pos: byte);
procedure ReadHiScores;
procedure WriteHiScores;
procedure WriteHSentry(i,j: byte);
(**********************************************************)
(**) (**)
(**) IMPLEMENTATION (**)
(**) (**)
(**********************************************************)
var
HSfile : file of HSentryRec;
procedure GetToday( var year, month, day: word );
var
dow: word;
begin
GetDate( year, month, day, dow );
end;
(*
** HSy
*)
function HSy(i: byte): byte;
begin
HSy := HSlistY+(i-1)*HSlistStep;
end;
(*
** WriteHSentry
*)
procedure WriteHSentry(i,j: byte);
const
dateStr: array[1..12] of string =
( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );
begin
with HSentry[i,j] do begin
GotoXY( HSnameLen + (sx-HSentryLen) div 2, HSy(j) );
Write( Score: 11 );
Write( day:4, '-' );
if month <= 12 then
Write( dateStr[month] )
else
Write( 'SUX' );
Write('-', year );
GotoXY( (sx-HSentryLen) div 2, HSy(j) );
Write( name );
end;
end;
(*
** ReadHiScores
*)
procedure ReadHiScores;
var
i,j: byte; (* loop vars *)
y,m,d: word; (* store date *)
begin
GetToday(y,m,d); (* init hiscores *)
for i := 1 to LevelNum do
for j := 1 to HSnum do
with HSentry[i,j] do begin
name := 'none';
score := 0;
year := y; month := m; day := d;
end;
Assign( HSfile, HSfname ); (* read hiscores *)
(*$I-*)
Reset( HSfile );
(*$I+*)
if IOResult <> 0 then begin
WriteMessage('Creating hiscore table');
WriteHiScores;
end
else begin
for i := 1 to LevelNum do
for j := 1 to HSnum do begin
Read( HSfile, HSentry[i,j] );
end;
Close( HSfile );
end;
end;
(*
** WriteHiScores
*)
procedure WriteHiScores;
var
i,j: byte;
begin
Assign( HSfile, HSfname );
Rewrite( HSfile );
if IOResult = 0 then begin
for i := 1 to LevelNum do
for j := 1 to HSnum do
Write( HSfile, HSentry[i,j] );
Close( HSfile );
end
else
WriteMessage('Error writing hiscores');
end;
(*
** HighScoreScreen
*)
procedure HighScoreScreen;
var
i: byte;
begin
ClrScr;
WriteCtr( HStitleY, '^H** high scores **^S' );
for i := 1 to HSnum do begin
WriteHSentry( Difficulty, i );
end;
end;
(*
** CheckHiScore
*)
function CheckHiScore(newscore: LongInt): byte;
var
pos: byte;
i : byte; (* loop var *)
begin
pos := HSnum;
while (newscore > HSentry[Difficulty,pos].score) and (pos>0) do
dec( pos );
inc(pos);
for i := HSnum-1 downto pos do
HSentry[Difficulty, i+1] := HSentry[Difficulty, i];
if pos > HSnum then
pos := 0
else with HSentry[Difficulty, pos] do begin
name := '';
score := newscore;
GetToday( year, month, day );
end;
CheckHiScore := pos;
end;
(*
** EnterHiScore
*)
procedure EnterHiScore(pos: byte);
var
PlName: string;
enter : boolean;
key : char;
begin
HighScoreScreen;
enter := false;
while not enter do begin
TextAttr := ColorLit;
WriteHSentry( Difficulty, pos );
TextAttr := ColorStd;
key := ReadKey;
with HSentry[Difficulty, pos] do
case key of
#8 : if length(name) >= 1 then begin
name := Copy(name,1,length(name)-1);
GotoXY(1,WhereY);
ClrEol;
end;
#13: enter := true;
#27: begin
enter := true;
name := 'anonymous'
end;
else
if (key>=' ') and (key<=#127) then
if length(name) < HSnameLen then
name := name + key;
end;
end;
WriteHiScores;
end;
(*
** Initialisation
*)
begin
end.