if brick.spin=1 then
case brick.op of
0:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+3].sost) then //J
begin
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+1,brick.y+1].sost:=true;
pole[brick.x+1,brick.y+1].color:=brick.col;
newbrick;
end;
1:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+4].sost) then //L
begin
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+1,brick.y+3].sost:=true;
pole[brick.x+1,brick.y+3].color:=brick.col;
newbrick;
end;
2:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+3,brick.y+4].sost) then //S
begin
pole[brick.x+2,brick.y+1].sost:=true;
pole[brick.x+2,brick.y+1].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+3,brick.y+3].sost:=true;
pole[brick.x+3,brick.y+3].color:=brick.col;
newbrick;
end;
3:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+3,brick.y+3].sost) then //S
begin
pole[brick.x+3,brick.y+1].sost:=true;
pole[brick.x+3,brick.y+1].color:=brick.col;
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
newbrick;
end;
4:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+3,brick.y+3].sost) then //T
begin
pole[brick.x+2,brick.y+1].sost:=true;
pole[brick.x+2,brick.y+1].color:=brick.col;
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
newbrick;
end;
5:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x,brick.y+3].sost) then //I
begin
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x,brick.y+2].sost:=true;
pole[brick.x,brick.y+2].color:=brick.col;
newbrick;
end;
6:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+4].sost) or (pole[brick.x+2,brick.y+4].sost) then //cube
begin
pole[brick.x+1,brick.y+3].sost:=true;
pole[brick.x+1,brick.y+3].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
newbrick;
end;
end;
if brick.spin=2 then
case brick.op of
0:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+2].sost) or (pole[brick.x+2,brick.y+4].sost) then //J
begin
pole[brick.x+3,brick.y+1].sost:=true;
pole[brick.x+3,brick.y+1].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+1].sost:=true;
pole[brick.x+2,brick.y+1].color:=brick.col;
newbrick;
end;
1:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+2].sost) or (pole[brick.x+2,brick.y+4].sost) then //L
begin
pole[brick.x+1,brick.y+1].sost:=true;
pole[brick.x+1,brick.y+1].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+1].sost:=true;
pole[brick.x+2,brick.y+1].color:=brick.col;
newbrick;
end;
2: if (brick.y>=h-4) or (pole[brick.x+1,brick.y+4].sost) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+3,brick.y+3].sost) then //S
begin
pole[brick.x+1,brick.y+3].sost:=true;
pole[brick.x+1,brick.y+3].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
newbrick;
end;
3:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+4].sost) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+1,brick.y+3].sost) then //Z
begin
pole[brick.x+3,brick.y+3].sost:=true;
pole[brick.x+3,brick.y+3].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
newbrick;
end;
4:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+1,brick.y+3].sost) then //T
begin
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
newbrick;
end;
5:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+4].sost) then //I
begin
pole[brick.x+2,brick.y].sost:=true;
pole[brick.x+2,brick.y].color:=brick.col;
pole[brick.x+2,brick.y+1].sost:=true;
pole[brick.x+2,brick.y+1].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
newbrick;
end;
6:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+2].sost) or (pole[brick.x+2,brick.y+2].sost) then //cube
begin
pole[brick.x+1,brick.y+1].sost:=true;
pole[brick.x+1,brick.y+1].color:=brick.col;
pole[brick.x+2,brick.y+1].sost:=true;
pole[brick.x+2,brick.y+1].color:=brick.col;
pole[brick.x+1,brick.y+1].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
newbrick;
end;
end;
if brick.spin=3 then
case brick.op of
0:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+4].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+3].sost) then //J
begin
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+3,brick.y+3].sost:=true;
pole[brick.x+3,brick.y+3].color:=brick.col;
newbrick;
end;
1:if (brick.y>=h-4) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+1,brick.y+3].sost) then //L
begin
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+3,brick.y+1].sost:=true;
pole[brick.x+3,brick.y+1].color:=brick.col;
newbrick;
end;
2:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+3].sost) or (pole[brick.x+2,brick.y+4].sost) then //S
begin
pole[brick.x+1,brick.y+1].sost:=true;
pole[brick.x+1,brick.y+1].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
newbrick;
end;
3:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+4].sost) or (pole[brick.x+2,brick.y+3].sost) then //S
begin
pole[brick.x+2,brick.y+1].sost:=true;
pole[brick.x+2,brick.y+1].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+1,brick.y+3].sost:=true;
pole[brick.x+1,brick.y+3].color:=brick.col;
newbrick;
end;
4:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+4].sost) or (pole[brick.x+1,brick.y+3].sost) then //T
begin
pole[brick.x+2,brick.y+1].sost:=true;
pole[brick.x+2,brick.y+1].color:=brick.col;
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+3].sost:=true;
pole[brick.x+2,brick.y+3].color:=brick.col;
newbrick;
end;
5:if (brick.y>=h-4) or (pole[brick.x+1,brick.y+3].sost) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+3,brick.y+3].sost) or (pole[brick.x+4,brick.y+3].sost) then //I
begin
pole[brick.x+1,brick.y+2].sost:=true;
pole[brick.x+1,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+4,brick.y+2].sost:=true;
pole[brick.x+4,brick.y+2].color:=brick.col;
newbrick;
end;
6:if (brick.y>=h-4) or (pole[brick.x+2,brick.y+3].sost) or (pole[brick.x+3,brick.y+3].sost) then //cube
begin
pole[brick.x+3,brick.y+1].sost:=true;
pole[brick.x+3,brick.y+1].color:=brick.col;
pole[brick.x+2,brick.y+1].sost:=true;
pole[brick.x+2,brick.y+1].color:=brick.col;
pole[brick.x+3,brick.y+2].sost:=true;
pole[brick.x+3,brick.y+2].color:=brick.col;
pole[brick.x+2,brick.y+2].sost:=true;
pole[brick.x+2,brick.y+2].color:=brick.col;
newbrick;
end;
end;
end;
procedure flipbrick; //поворот
var temp:boolean;
begin
brick.spin:= brick.spin+1;
brick.spin:= brick.spin mod 4;
temp:=brick.amount[1,1];
brick.amount[1,1]:=brick.amount[1,5];
brick.amount[1,5]:=brick.amount[5,5];
brick.amount[5,5]:=brick.amount[5,1];
brick.amount[5,1]:=temp;
temp:=brick.amount[1,2];
brick.amount[1,2]:=brick.amount[2,5];
brick.amount[2,5]:=brick.amount[5,4];
brick.amount[5,4]:=brick.amount[4,1];
brick.amount[4,1]:=temp;
temp:=brick.amount[1,3];
brick.amount[1,3]:=brick.amount[3,5];
brick.amount[3,5]:=brick.amount[5,3];
brick.amount[5,3]:=brick.amount[3,1];
brick.amount[3,1]:=temp;
temp:=brick.amount[1,4];
brick.amount[1,4]:=brick.amount[4,5];
brick.amount[4,5]:=brick.amount[5,2];
brick.amount[5,2]:=brick.amount[2,1];
brick.amount[2,1]:=temp;
temp:=brick.amount[2,2];
brick.amount[2,2]:=brick.amount[2,4];
brick.amount[2,4]:=brick.amount[4,4];
brick.amount[4,4]:=brick.amount[4,2];
brick.amount[4,2]:=temp;
temp:=brick.amount[2,3];
brick.amount[2,3]:=brick.amount[3,4];
brick.amount[3,4]:=brick.amount[4,3];
brick.amount[4,3]:=brick.amount[3,2];
brick.amount[3,2]:=temp
end;
procedure printfield; //вывод поля
begin
chekline;
fallbrick;
for i:=1 to w do
for j:=1 to h do
begin
GameField[i,j]:=TImage.Create(MainForm);
GameField[i,j].Parent:=MainForm;
GameField[i,j].Height:=a;
GameField[i,j].Width:=a;
GameField[i,j].Top:=j*a+30;
GameField[i,j].left:=i*a+15
end;
for i:=1 to w do
for j:=1 to h do
if pole[i,j].sost then
GameField[i,j].Picture.LoadFromFile('.\img\'+IntToStr(pole[i,j].color)+'.png')
else
GameField[i,j].Picture.LoadFromFile('.\img\0.png');
for i:=1 to 5 do
for j:=1 to 5 do
if brick.amount[i,j] then
GameField[brick.x+i,brick.y+j].Picture.LoadFromFile('.\img\'+IntToStr(brick.col)+'.png');
for i:=1 to 5 do
for j:=1 to 5 do
begin
Next[i,j]:=TImage.Create(MainForm);
Next[i,j].Parent:=MainForm;
Next[i,j].Height:=a;
Next[i,j].Width:=a;
Next[i,j].Top:=j*a+60;
Next[i,j].left:=i*a+283
end;
for i:=1 to 5 do
for j:=1 to 5 do
if nextbrick.amount[i,j] then
Next[i,j].Picture.LoadFromFile('.\img\'+IntToStr(brick.col)+'.png')
else
Next[i,j].Picture.LoadFromFile('.\img\0.png');
end;
procedure TMainForm.StartBtnClick(Sender: TObject);
begin
counter := 0;
newbrick;
newbrick;
for i:=1 to w do
for j:=1 to h do
pole[i,j].sost:=false;
end;
procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if(not FrameTick.Enabled) then
begin
exit;
end;
if (Key = 37) then
begin
brick.x:=brick.x-1;
printfield;
end
else if (Key = 39) then
begin
brick.x := brick.x+1;
printfield;
end
else if (Key = 40) then
Frametick.Interval:=fast_tick
else if (Key = 38) then
begin
flipbrick;
printfield;
end
end;
procedure TMainForm.FrameTickTimer(Sender: TObject);
begin
brick.y:=brick.y+1;
printfield
end;
end.