p> buf: TUserInfo;
begin
i: = 0;
assign (f, 'peaks.dat');
{$ I-}
FileMode : = 2;
reset (f);
{$ I +}
if IOResult <> 0 then
begin
rewrite (f);
write (f, UInfo),
close (f);
exit;
end;
repeat
read (f, buf);
inc (i);
until (I = filesize (f)) or (UInfo.UserName = buf.UserName);
if (UInfo.UserName = buf.UserName) then {Якщо користувач вже є}
begin
buf.wcnt: = buf.wcnt + UInfo.wcnt;
buf.dcnt : = Buf.dcnt + UInfo.dcnt;
buf.allscore: = buf.allscore + UInfo.allscore;
seek (f, filepos (f) -1);
write (f, buf);
close (f);
exit;
end;
seek (f, filesize (f));
write (f, UInfo);
close (f);
end;
Procedure DisplayStat;
var
i: longint;
f: file of TUserInfo;
buf: TUserInfo;
begin
assign (f, 'peaks.dat');
{$ I-}
reset (f);
{$ I +}
if IOResult <> 0 then exit;
for i: = 1 to filesize (f) do
begin
read (f, buf);
with buf do
writeln ('Name:', UserName, 'Wins:', wcnt, 'Defeats:', dcnt,
' Score: ', AllScore);
if (I mod 23) = 0 then
begin
writeln;
writeln ('Press any key to continue ... ");
readkey;
ClrScr;
end;
end;
close (f);
writeln;
writeln ('Press any key to exit ... ');
readkey;
end;
var
ch: char;
UserInfo: TUserInfo; {Інформація про що відіграє}
begin
ChDir (workdir); {Переходимо в каталог звідки запущена програма}
randomize;
with UserInfo do
begin
UserName: = GetUserName;
wcnt : = 0;
dcnt : = 0;
end;
Init;
repeat {Робочий цикл програми}
if keypressed then ch: = readkey; {Скануємо натискання клавіш}
ScanMouse; {Скануємо мишу}
CalcTime; {Вважаємо час}
until (Ch = # 27) or DefeatOrWin (UserInfo);
CloseGr;
if (UserInfo.wcnt> 0) or (UserInfo.dcnt> 0) then
SaveToFile (UserInfo);
DisplayStat;
ClrScr;
writeln ('3 Peaks ');
writeln ('ver. 1.0 ');
Writeln ('(c) 2004 by Denis Kireev ')
end. {Кінець програми}