unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;
type
TBlock =
class;
THaupt =
class;
TForm2 =
class(TForm)
Spielfeld: TImage;
Timer1: TTimer;
Button1: TSpeedButton;
Edit1: TEdit;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
Haupt : THaupt;
end;
THaupt =
class(TObject)
Block :
array of TBlock;
Anzahl : integer;
kannbewegen : boolean;
IDs : Integer;
procedure Neu();
procedure Neufallen();
procedure verschiebenlinks();
procedure verschiebenrechts();
procedure findelinie();
procedure arraykurzen();
procedure Drehen();
function CanMoveLast(
const deltaX, deltaY: integer): boolean;
function findemax(): integer;
// procedure Prufen();
// procedure Entfernen();
private
public
zufall: integer;
gedreht : integer;
temp :
array[1..16]
of Integer;
end;
TBlock =
class(TObject)
private
fFarbe : TColor;
fPosition : TPoint;
fID : Integer;
public
procedure zeichen;
property Farbe : TColor
read fFarbe
write fFarbe;
property Position : Tpoint
read fPosition
write fPosition;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
//Code Block
procedure TBlock.zeichen;
begin
form2.Spielfeld.Canvas.Brush.Color := fFarbe;
form2.Spielfeld.Canvas.Brush.Style := bssolid;
form2.Spielfeld.Canvas.Rectangle(fPosition.X*24, fPosition.Y*24, fPosition.X*24+24, fPosition.Y*24+24 );
end;
//Code Haupt
procedure THaupt.Neu;
begin
gedreht := 0;
form2.Timer1.Enabled := false;
if (form2.Edit1.text = '
')
then
begin
repeat
zufall := random(5) +1;
until (zufall <> 0) ;
end
else
begin
try
zufall := strtoint(form2.Edit1.Text);
except
showmessage('
keine Zahl');
repeat
zufall := random(5) +1;
until (zufall <> 0) ;
end;
end;
findelinie();
case zufall
of
1:
begin // Quadrat
IDs := IDs +4;
setlength(Block, Length(Block)+4);
Block[high(Block)-3] := TBlock.Create;
Block[high(Block)-3].Farbe := clred ;
Block[high(Block)-3].fPosition.X:= 4 ;
Block[high(Block)-3].fPosition.Y:= -2 ;
Block[high(Block)-3].fID := IDS-3;
Block[high(Block)-2] := TBlock.Create;
Block[high(Block)-2].Farbe := clred ;
Block[high(Block)-2].fPosition.X:= 5 ;
Block[high(Block)-2].fPosition.Y:= -2 ;
Block[high(Block)-2].fID := IDs-2;
Block[high(Block)-1] := TBlock.Create;
Block[high(Block)-1].Farbe := clred ;
Block[high(Block)-1].fPosition.X:= 4 ;
Block[high(Block)-1].fPosition.Y:= -1 ;
Block[high(Block)-1].fID := IDs-1;
Block[high(Block)] := TBlock.Create;
Block[high(Block)].Farbe := clred ;
Block[high(Block)].fPosition.X:= 5 ;
Block[high(Block)].fPosition.Y:= -1 ;
Block[high(Block)].fID := IDs;
//showmessage('Quadrat');
form2.Timer1.Enabled := true;
end;
2:
begin // Winkellinks
IDs := IDs +4 ;
setlength(Block, Length(Block)+4);
Block[high(Block)-3] := TBlock.Create;
Block[high(Block)-3].Farbe := clyellow ;
Block[high(Block)-3].fPosition.X:= 4 ;
Block[high(Block)-3].fPosition.Y:= -2 ;
Block[high(Block)-3].fID := IDs-3;
Block[high(Block)-2] := TBlock.Create;
Block[high(Block)-2].Farbe := clyellow ;
Block[high(Block)-2].fPosition.X:= 4 ;
Block[high(Block)-2].fPosition.Y:= -1 ;
Block[high(Block)-2].fID := IDs-2;
Block[high(Block)-1] := TBlock.Create;
Block[high(Block)-1].Farbe := clyellow ;
Block[high(Block)-1].fPosition.X:= 5 ;
Block[high(Block)-1].fPosition.Y:= -1 ;
Block[high(Block)-1].fID := IDs-1;
Block[high(Block)] := TBlock.Create;
Block[high(Block)].Farbe := clyellow ;
Block[high(Block)].fPosition.X:= 6 ;
Block[high(Block)].fPosition.Y:= -1 ;
Block[high(Block)].fID := IDs;
//showmessage('Winkel');
form2.Timer1.Enabled := true;
end;
3:
begin //Winkelrechts
IDS := IDs +4;
setlength(Block, Length(Block)+4);
Block[high(Block)-3] := TBlock.Create;
Block[high(Block)-3].Farbe := clblue ;
Block[high(Block)-3].fPosition.X:= 6 ;
Block[high(Block)-3].fPosition.Y:= -2 ;
Block[high(Block)-3].fID := IDs-3;
Block[high(Block)-2] := TBlock.Create;
Block[high(Block)-2].Farbe := clblue ;
Block[high(Block)-2].fPosition.X:= 4 ;
Block[high(Block)-2].fPosition.Y:= -1 ;
Block[high(Block)-2].fID := IDs-2;
Block[high(Block)-1] := TBlock.Create;
Block[high(Block)-1].Farbe := clblue ;
Block[high(Block)-1].fPosition.X:= 5 ;
Block[high(Block)-1].fPosition.Y:= -1 ;
Block[high(Block)-1].fID := IDs-1;
Block[high(Block)] := TBlock.Create;
Block[high(Block)].Farbe := clblue ;
Block[high(Block)].fPosition.X:= 6 ;
Block[high(Block)].fPosition.Y:= -1 ;
Block[high(Block)].fID := IDs;
//showmessage('Winkel');
form2.Timer1.Enabled := true;
end;
4:
begin //T
IDS := IDs +4;
setlength(Block, Length(Block)+4);
Block[high(Block)-3] := TBlock.Create;
Block[high(Block)-3].Farbe := cllime ;
Block[high(Block)-3].fPosition.X:= 5 ;
Block[high(Block)-3].fPosition.Y:= -2 ;
Block[high(Block)-3].fID := IDs-3;
Block[high(Block)-2] := TBlock.Create;
Block[high(Block)-2].Farbe := cllime ;
Block[high(Block)-2].fPosition.X:= 4 ;
Block[high(Block)-2].fPosition.Y:= -1 ;
Block[high(Block)-2].fID := IDs-2;
Block[high(Block)-1] := TBlock.Create;
Block[high(Block)-1].Farbe := cllime ;
Block[high(Block)-1].fPosition.X:= 5 ;
Block[high(Block)-1].fPosition.Y:= -1 ;
Block[high(Block)-1].fID := IDs-1;
Block[high(Block)] := TBlock.Create;
Block[high(Block)].Farbe := cllime ;
Block[high(Block)].fPosition.X:= 6 ;
Block[high(Block)].fPosition.Y:= -1 ;
//showmessage('T');
form2.Timer1.Enabled := true;
end;
5:
begin // Rechteck
IDs := IDs +4;
setlength(Block, Length(Block)+4);
Block[high(Block)-3] := TBlock.Create;
Block[high(Block)-3].Farbe := clpurple ;
Block[high(Block)-3].fPosition.X:= 5 ;
Block[high(Block)-3].fPosition.Y:= -4 ;
Block[high(Block)-3].fID := IDs-3;
Block[high(Block)-2] := TBlock.Create;
Block[high(Block)-2].Farbe := clpurple ;
Block[high(Block)-2].fPosition.X:= 5 ;
Block[high(Block)-2].fPosition.Y:= -3 ;
Block[high(Block)-2].fID := IDs-2;
Block[high(Block)-1] := TBlock.Create;
Block[high(Block)-1].Farbe := clpurple ;
Block[high(Block)-1].fPosition.X:= 5 ;
Block[high(Block)-1].fPosition.Y:= -2 ;
Block[high(Block)-1].fID := IDs-1;
Block[high(Block)] := TBlock.Create;
Block[high(Block)].Farbe := clpurple ;
Block[high(Block)].fPosition.X:= 5 ;
Block[high(Block)].fPosition.Y:= -1 ;
Block[high(Block)].fID := IDs;
//showmessage('REchteck');
form2.Timer1.Enabled := true;
end;
end;
end;
procedure THaupt.Neufallen;
var
i :integer;
begin
Form2.Spielfeld.Canvas.Brush.Color := clwhite;
Form2.Spielfeld.Canvas.Brush.Style := bssolid;
Form2.Spielfeld.Canvas.Rectangle(0,0,form2.Spielfeld.Width, form2.Spielfeld.Height);
kannbewegen :=false;
if CanMoveLast(0,1)
then kannbewegen:= true;
if kannbewegen
then
begin
Block[high(Block)-3].fPosition.Y := Block[high(Block)-3].fPosition.Y +1 ;
Block[high(Block)-2].fPosition.Y := Block[high(Block)-2].fPosition.Y +1 ;
Block[high(Block)-1].fPosition.Y := Block[high(Block)-1].fPosition.Y +1 ;
Block[high(Block)].fPosition.Y := Block[high(Block)].fPosition.Y +1 ;
end;
if (Block[high(Block)-3].fPosition.y = 27)
or (Block[high(Block)-2].fposition.y = 27)
or (Block[high(Block)-1].fposition.y = 27)
or (Block[high(Block)-0].fposition.y = 27)
then kannbewegen:= false;
for i := 0
to high(Block)
do
begin
Block[i].zeichen;
end;
if not kannbewegen
then neu();
end;
procedure THaupt.Drehen;
begin
kannbewegen := false;
case Zufall
of
1:
begin
//passiert nichts
end;
2:
begin
case gedreht
of
0:
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x +0;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y +2;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x+1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y+1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0 ;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y - 0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x-1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y -1;
gedreht := 1;
end;
1:
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x +2;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y +0;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x +1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y -1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y - 0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x - 1 ;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y +1;
gedreht := 2;
end;
2 :
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x -0;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y -2;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x -1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y -1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y -0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x +1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y +1;
gedreht := 3;
end;
3 :
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x -2 ;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y +0;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x -1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y +1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x +0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y +0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x +1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y -1;
gedreht := 0;
end;
end;
end;
3:
begin
case gedreht
of
0:
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x -2;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y -0;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x+1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y +1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0 ;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y - 0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x-1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y -1;
gedreht := 1;
end;
1:
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x -0;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y +2;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x +1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y -1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y - 0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x - 1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y + 1;
gedreht := 2;
end;
2 :
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x +2;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y +0;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x -1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y -1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y - 0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x + 1 ;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y + 1;
gedreht := 3;
end;
3 :
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x -0 ;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y -2;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x -1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y +1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y +0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x +1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y -1;
gedreht := 0;
end;
end;
end;
4:
begin
case gedreht
of
0:
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x -1;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y +1;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x+1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y +1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y - 0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x-1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y -1;
gedreht := 1;
end;
1:
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x +1;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y +1;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x +1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y -1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y - 0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x - 1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y + 1;
gedreht := 2;
end;
2 :
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x +1;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y -1;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x -1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y -1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y - 0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x + 1 ;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y + 1;
gedreht := 3;
end;
3 :
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x -1;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y -1;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x -1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y +1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y +0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x +1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y -1;
gedreht := 0;
end;
end;
end;
5:
begin
case gedreht
of
0:
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x -2;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y +2;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x-1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y +1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y - 0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x+1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y -1;
gedreht := 1;
end;
1:
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.x +2;
Block[high(Block)-3].fPosition.Y:= Block[high(Block)-3].fPosition.Y -2;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.x +1;
Block[high(Block)-2].fPosition.Y:= Block[high(Block)-2].fPosition.Y -1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.x -0;
Block[high(Block)-1].fPosition.Y:= Block[high(Block)-1].fPosition.Y -0;
Block[high(Block)].fPosition.X:= Block[high(Block)].fPosition.x - 1;
Block[high(Block)].fPosition.Y:= Block[high(Block)].fPosition.Y + 1;
gedreht := 0;
end;
end;
end;
end;
end;
procedure THaupt.verschiebenlinks;
var
i : Integer;
begin
if (Block[high(Block)-3].fPosition.x = 0)
or (Block[high(Block)-2].fPosition.x = 0)
or (Block[high(Block)-1].fPosition.x = 0)
or (Block[high(Block)-0].fPosition.x = 0)
then
begin
end
else
begin
if canmovelast(-1,0)
then
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.X -1;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.X -1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.X -1;
Block[high(Block)-0].fPosition.X:= Block[high(Block)-0].fPosition.X -1;
Form2.Spielfeld.Canvas.Brush.Color := clwhite;
Form2.Spielfeld.Canvas.Brush.Style := bssolid;
Form2.Spielfeld.Canvas.Rectangle(0,0,form2.Spielfeld.Width, form2.Spielfeld.Height);
for i := 0
to high(Block)
do
begin
Block[i].zeichen;
end;
end;
end;
end;
procedure Thaupt.verschiebenrechts;
var
i : Integer;
begin
if (Block[high(Block)-3].fPosition.x = 15)
or (Block[high(Block)-2].fPosition.x = 15)
or (Block[high(Block)-10].fPosition.x = 15)
or (Block[high(Block)-0].fPosition.x = 15)
then
begin
end
else
begin
if canmovelast(1,0)
then
begin
Block[high(Block)-3].fPosition.X:= Block[high(Block)-3].fPosition.X +1;
Block[high(Block)-2].fPosition.X:= Block[high(Block)-2].fPosition.X +1;
Block[high(Block)-1].fPosition.X:= Block[high(Block)-1].fPosition.X +1;
Block[high(Block)-0].fPosition.X:= Block[high(Block)-0].fPosition.X +1;
Form2.Spielfeld.Canvas.Brush.Color := clwhite;
Form2.Spielfeld.Canvas.Brush.Style := bssolid;
Form2.Spielfeld.Canvas.Rectangle(0,0,form2.Spielfeld.Width, form2.Spielfeld.Height);
for i := 0
to high(Block)
do
begin
Block[i].zeichen;
end;
end;
end;
end;
function THaupt.CanMoveLast(
const deltaX, deltaY: integer): boolean;
var
N, I, J: integer;
begin
Result := true;
N := High(Block);
for I := 0
to N - 4
do
for J := 0
to 3
do
if (Block[N - J].fPosition.X + deltaX = Block[I].fPosition.X)
and (Block[N - J].fPosition.y + deltaY = Block[I].fPosition.Y)
then
Result := false;
end;
function THaupt.findemax;
var
i,max :integer;
begin
max := 0;
for i := 1
to high(Block)
do
begin
if 27-Block[i].fPosition.Y > max
then max := 27-Block[i].fPosition.Y;
end;
result :=max;
end;
procedure THaupt.findelinie;
var
i,j: integer;
begin
Anzahl := 0;
showmessage(inttostr(findemax+1));
for j := 0
to findemax
do
begin
anzahl:=0;
for i := 1
to high(Block)
do
begin
if Block[i].fPosition.Y = 27-J
then
begin
Anzahl := Anzahl+1;
temp[Anzahl] := Block[i].fID ;
form2.Label1.Caption := inttostr(Anzahl)+'
,'+inttostr(j);
if Anzahl = 16
then
begin
showmessage('
endlich');
arraykurzen;
end;
end
else
begin
end;
end;
end;
end;
procedure THaupt.arraykurzen;
var
i,j,x : integer;
begin
x:= 0;
for j := 1
to 16
do
begin
for i := 1
to high(Block)
do
begin
if block[i].fID = temp[j]
then
begin
x := i+1;
repeat
try
showmessage(inttostr(X)+'
, '+ inttostr(high(Block )));
Block[x-1].fPosition.X := Block[x].fPosition.x;
Block[x-1].fPosition.X := Block[x].fPosition.y;
Block[x-1].fFarbe := Block[x].fFarbe;
Block[x-1].fID := Block[x].fID;
x := x+1;
setlength(Block, length(Block)-1);
except
showmessage('
hier')
end;
until (x+1 > length(Block)) ;
end;
end;
end;
// findelinie;
end;
//Fenster
procedure TForm2.Button1Click(Sender: TObject);
begin
Haupt.Neu();
end;
procedure TForm2.FormClose(Sender: TObject;
var Action: TCloseAction);
var
i : integer;
begin
for i := 1
to high(Haupt.Block)
do
begin
Haupt.Block[i].Free;
end;
Haupt.Free;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
Haupt := THaupt.Create;
setlength(Haupt.Block, 0);
Haupt.IDs := 0;
end;
procedure TForm2.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if key = VK_UP
then Haupt.Drehen;
if key = VK_left
then Haupt.verschiebenlinks;
if key = Vk_right
then Haupt.verschiebenrechts;
if key = vk_down
then Haupt.Neufallen;
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
Haupt.Neufallen();
end;
end.