-
Notifications
You must be signed in to change notification settings - Fork 2
/
mktetsct.pas
109 lines (104 loc) · 2.64 KB
/
mktetsct.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
{
-----------------------------------------------------------
Project: MKTRIS
Tetris-like game / Tetris clone.
File: mktetsct.pas
Purpose: Routines to handle hi-score.
Author: Copyright (C) by Marek Karcz 2016-2020.
All rights reserved.
-----------------------------------------------------------
}
{
-----------------------------------------------------------
Write hi-score table with hihest score player on top.
This file is updated with a new value every time the new
score is grater than the one currently on file when game
ends.
-----------------------------------------------------------
}
procedure WriteHiScore;
var
i: Integer;
begin
Assign(HiScoreFile, HiScFname);
Rewrite(HiScoreFile);
for i := 1 to 5 do
begin
Write(HiScoreFile, HiScTbl[i]);
end;
Close(HiScoreFile);
end;
{
-----------------------------------------------------------
Read scores from a hi-score file.
-----------------------------------------------------------
}
procedure ReadHiScore;
var
iook : Boolean;
i : Integer;
begin
Assign(HiScoreFile, HiScFName);
{$I-} Reset(HiScoreFile) {$I+} ;
iook := (IOresult = 0);
if not iook then { hi-score file doesn't exist, write one }
begin
WriteHiScore;
Assign(HiScoreFile, HiScFName);
Reset(HiScoreFile);
end;
for i := 1 to 5 do
begin
Read(HiScoreFile, HiScTbl[i]);
end;
Close(HiScoreFile);
end;
{
---------------------------------------------------------
Refresh score on the screen.
---------------------------------------------------------
}
procedure RefreshScore;
begin
GotoXY(InfoCol, 1);
write(PlayerName, ' Score: ', Score);
with HiScoreRec do
write(' Hi-Score: ', PlrName, ' ', Score);
end;
{
------------------------------------------------------------------
Insert score into table below equal or higher score entry.
Shift entries below down. Save table to file.
------------------------------------------------------------------
}
procedure InsertScore(pn: PlName; scre: Integer);
var
i, j: Integer;
keepGoing: Boolean;
begin
i := 1;
keepGoing := True;
while keepGoing and (i < 6) do
begin
with HiScTbl[i] do
begin
if (scre > Score) then
begin
for j := 5 downto i do
begin
HiScTbl[j] := HiScTbl[j-1];
end;
PlrName := pn;
Score := scre;
keepGoing := False;
end;
end;
i := i + 1;
end;
if (keepGoing = False) then
begin
WriteHiScore;
end;
end;
{ * * * EOF * * * }