feat/TD-002-simple-interface
This commit is contained in:
parent
b27cbed0bb
commit
c900189c59
@ -1,5 +1,110 @@
|
||||
program go_hamster;
|
||||
|
||||
uses crt;
|
||||
|
||||
const
|
||||
FieldSize = 82;
|
||||
InterfaceHeight = 14;
|
||||
MinScreenH = FieldSize;
|
||||
WidthCoefficient = 2;
|
||||
MinScreenW = FieldSize * WidthCoefficient;
|
||||
FieldBorder = '#';
|
||||
BorderWidth = 2;
|
||||
DelaySizeMs = 50;
|
||||
EscCode = 27;
|
||||
CtrlCCode = 3;
|
||||
|
||||
function IsScreenValid: boolean;
|
||||
begin
|
||||
writeln('Repo init')
|
||||
IsScreenValid :=
|
||||
(ScreenWidth >= MinScreenW) and (ScreenHeight >= MinScreenH)
|
||||
end;
|
||||
|
||||
procedure PrintScreenHelp;
|
||||
begin
|
||||
writeln('Increase your screen size and try again.');
|
||||
if ScreenWidth < MinScreenW then
|
||||
begin
|
||||
writeln('Your screen width: ', ScreenWidth,
|
||||
'. Required: ', MinScreenW, '.')
|
||||
end;
|
||||
if ScreenHeight < MinScreenH then
|
||||
begin
|
||||
writeln('Your screen height: ', ScreenHeight,
|
||||
'. Required: ', MinScreenH, '.')
|
||||
end
|
||||
end;
|
||||
|
||||
procedure GetKey(var code: integer);
|
||||
var
|
||||
c: char;
|
||||
begin
|
||||
c := ReadKey;
|
||||
if c = #0 then
|
||||
begin
|
||||
c := ReadKey;
|
||||
code := -ord(c)
|
||||
end
|
||||
else
|
||||
begin
|
||||
code := ord(c)
|
||||
end
|
||||
end;
|
||||
|
||||
procedure DrawLine(x, y, len: integer);
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
for i := 1 to len do
|
||||
write(FieldBorder);
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawInterface;
|
||||
begin
|
||||
DrawLine(1, InterfaceHeight, FieldSize * WidthCoefficient)
|
||||
end;
|
||||
|
||||
procedure DrawField(x0, y0, size: integer);
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
clrscr;
|
||||
DrawLine(x0, y0, size * WidthCoefficient);
|
||||
for i := 1 to size - 2 do
|
||||
begin
|
||||
GotoXY(x0, y0 + i);
|
||||
write(FieldBorder);
|
||||
GotoXY(x0 + size * WidthCoefficient - 1, y0 + i);
|
||||
write(FieldBorder)
|
||||
end;
|
||||
DrawLine(x0, y0 + size - 1, size * WidthCoefficient);
|
||||
GotoXY(1, 1);
|
||||
DrawInterface
|
||||
end;
|
||||
|
||||
|
||||
var
|
||||
code: integer;
|
||||
begin
|
||||
|
||||
if not IsScreenValid then
|
||||
begin
|
||||
PrintScreenHelp;
|
||||
exit
|
||||
end;
|
||||
DrawField(1, 1, FieldSize);
|
||||
while true do
|
||||
begin
|
||||
delay(DelaySizeMs);
|
||||
if keypressed then
|
||||
begin
|
||||
GetKey(code);
|
||||
writeln(code);
|
||||
if (code = EscCode) or (code = CtrlCCode) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user