Код
program tetris;
uses crt,graph;
const esc=#27; up=#72;
down=#80; left=#75;
right=#77; null=#0;
var dv,mv,a,b:integer;
ch:char;
Procedure Sync; assembler;{Procedura Zaderjki lucha}
asm
mov dx, 3DAh
@@Wait:
in al, dx
test al, 08h
jz @@Wait
end;
procedure moveL;
begin
if (getpixel(a-1,B)=15) or (getpixel(a-1,b-3)=15)
then
begin
a:=a+20;b:=b+1;
end;
if (getpixel(a-1,B)=0) and (getpixel(a-1,b-3)=0)
then
begin
a:=a-20;b:=b+1;
end;
end;
procedure moveR;
begin
if (getpixel(a+41,B)<>0) or (getpixel(a+41,b-3)<>0) then
begin
a:=a-20; b:=b+1;
end;
if (getpixel(a+41,B)=0) and (getpixel(a+41,b-3)=0) then
begin
a:=a+20; b:=b+1;
end;
end;
procedure kvd;
begin
setfillstyle(1,15);
bar(a,b,a+40,b-40);
sync;
end;
procedure stakan;
begin
{setlinestyle(solidln,0,thickwidth);}
line(98,0,98,400);
line(98,400,542,400);
line(542,400,542,0);
setfillstyle(0,15);
end;
procedure zakrash;
begin
setfillstyle(0,15);
bar(a,b,a+40,b-40);
end;
procedure proverkaV;
begin
if a>502 then a:=501;
if a<98 then a:=99;
end;
procedure proverkaG;
begin
if b>397 then
begin
b:=397;
ch:=null;
end;
end;
begin
dv:=detect;
initgraph(dv,mv,'c:tpbgi');
a:=320;
b:=40;
kvd;
stakan;
repeat
a:=320;
b:=40;
while getpixel(a+20,b+3)=0
do begin
if keypressed=true then
begin
ch:=readkey;
zakrash;
case ch of
esc:halt(1);
left:moveL;
right:moveR;
end;
proverkaG;
proverkaV;
kvd;
end;
if keypressed=false then
begin
zakrash;
a:=a;
b:=b+1;
proverkaG;
proverkaV;
kvd;
end;
end;
until getpixel(320,40)=15;
end.
uses crt,graph;
const esc=#27; up=#72;
down=#80; left=#75;
right=#77; null=#0;
var dv,mv,a,b:integer;
ch:char;
Procedure Sync; assembler;{Procedura Zaderjki lucha}
asm
mov dx, 3DAh
@@Wait:
in al, dx
test al, 08h
jz @@Wait
end;
procedure moveL;
begin
if (getpixel(a-1,B)=15) or (getpixel(a-1,b-3)=15)
then
begin
a:=a+20;b:=b+1;
end;
if (getpixel(a-1,B)=0) and (getpixel(a-1,b-3)=0)
then
begin
a:=a-20;b:=b+1;
end;
end;
procedure moveR;
begin
if (getpixel(a+41,B)<>0) or (getpixel(a+41,b-3)<>0) then
begin
a:=a-20; b:=b+1;
end;
if (getpixel(a+41,B)=0) and (getpixel(a+41,b-3)=0) then
begin
a:=a+20; b:=b+1;
end;
end;
procedure kvd;
begin
setfillstyle(1,15);
bar(a,b,a+40,b-40);
sync;
end;
procedure stakan;
begin
{setlinestyle(solidln,0,thickwidth);}
line(98,0,98,400);
line(98,400,542,400);
line(542,400,542,0);
setfillstyle(0,15);
end;
procedure zakrash;
begin
setfillstyle(0,15);
bar(a,b,a+40,b-40);
end;
procedure proverkaV;
begin
if a>502 then a:=501;
if a<98 then a:=99;
end;
procedure proverkaG;
begin
if b>397 then
begin
b:=397;
ch:=null;
end;
end;
begin
dv:=detect;
initgraph(dv,mv,'c:tpbgi');
a:=320;
b:=40;
kvd;
stakan;
repeat
a:=320;
b:=40;
while getpixel(a+20,b+3)=0
do begin
if keypressed=true then
begin
ch:=readkey;
zakrash;
case ch of
esc:halt(1);
left:moveL;
right:moveR;
end;
proverkaG;
proverkaV;
kvd;
end;
if keypressed=false then
begin
zakrash;
a:=a;
b:=b+1;
proverkaG;
proverkaV;
kvd;
end;
end;
until getpixel(320,40)=15;
end.