unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TBlock =
class;
THaupt =
class;
TForm2 =
class(TForm)
Spielfeld: TImage;
Button1: TButton;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
Haupt : THaupt;
end;
THaupt =
class(TObject)
Block :
array of TBlock;
Anzahl : integer;
procedure Neu();
procedure Neufallen();
// procedure Drehen();
// procedure Prufen();
// procedure Entfernen();
private
public
end;
TBlock =
class(TObject)
private
fFarbe : TColor;
fPosition : TPoint;
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;
var
zufall : integer;
begin
form2.Timer1.Enabled := false;
repeat
zufall := random(5);
until zufall <> 0 ;
case zufall
of
1:
begin // Quadrat
setlength(Block, high(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)-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)-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)] := TBlock.Create;
Block[high(Block)].Farbe := clred ;
Block[high(Block)].fPosition.X:= 5 ;
Block[high(Block)].fPosition.Y:= -1 ;
showmessage('
Quadrat');
form2.Timer1.Enabled := true;
end;
2:
begin // Winkelrechts
setlength(Block, high(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)-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)-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)] := TBlock.Create;
Block[high(Block)].Farbe := clyellow ;
Block[high(Block)].fPosition.X:= 6 ;
Block[high(Block)].fPosition.Y:= -1 ;
showmessage('
Winkel');
form2.Timer1.Enabled := true;
end;
3:
begin //Winkellinks
setlength(Block, high(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)-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)-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)] := TBlock.Create;
Block[high(Block)].Farbe := clblue ;
Block[high(Block)].fPosition.X:= 6 ;
Block[high(Block)].fPosition.Y:= -1 ;
showmessage('
Winkel');
form2.Timer1.Enabled := true;
end;
4:
begin //T
setlength(Block, high(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)-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)-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)] := 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
setlength(Block, high(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)-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)-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)] := TBlock.Create;
Block[high(Block)].Farbe := clpurple ;
Block[high(Block)].fPosition.X:= 5 ;
Block[high(Block)].fPosition.Y:= -1 ;
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);
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 ;
for i := 0
to high(Block)
do
begin
Block[i].zeichen;
end;
if Block[high(Block)].fPosition.Y = 27
then Neu;
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, 1);
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
Haupt.Neufallen();
end;
end.