unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls;
type
{ TForm1 }
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Label1: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Rechts: TShape;
Mitte: TShape;
Links: TShape;
StabRechts: TShape;
StabMitte: TShape;
StabLinks: TShape;
ShapeMOVE: TShape;
TA: TShape;
TB: TShape;
TC: TShape;
ShapeMF: TShape;
ShapeMT: TShape;
ShapeT2: TShape;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
z: integer;
q: boolean;
cL,cM,cR: integer;
Scheibe:
array[1..10]
of TShape;
index: integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure draw(a,b,c,d: integer; n:
string);
var Shape : TShape;
begin
Shape := TShape.Create(Form1);
With Shape
do
begin
Parent := Form1;
Left := a;
Top := b;
Width:= c;
Height:=d;
Name := n;
Brush.Color:=clMaroon;
Brush.Style:=bsSolid;
Pen.Color:=clMaroon;
end;
end;
procedure towerA(t: integer);
var i,z: integer;
begin
i:=0;
z:=t+1;
repeat
i:=i+1;
z:=z-1;
Scheibe[z] := TShape.Create(Form1);
With Scheibe[z]
do
begin
Parent := Form1;
Left := 100+((i-1)*10);
Top := 550-(i*50);
Width:= 200-((i-1)*20);
Height:=50;
Name:= '
Scheibe'+IntToStr(z);
Brush.Color:=clNavy;
Shape:=stRoundRect;
end;
until i=t;
end;
procedure movetop(r: integer;ShapeMF,ShapeMT: TShape);
begin
index:=r;
Form1.ShapeT2:=ShapeMT;
if ShapeMT.left=Form1.Mitte.left
then
begin
cM:=cM+1;
z:=550-(cM*50);
end;
if ShapeMT.left=Form1.Links.left
then
begin
cL:=cL+1;
z:=550-(cL*50);
end;
if ShapeMT.left=Form1.Rechts.left
then
begin
cR:=cR+1;
z:=550-(cR*50);
end;
if ShapeMF.left=Form1.Mitte.left
then
begin
cM:=cM-1;
end;
if ShapeMF.left=Form1.Links.left
then
begin
cL:=cL-1;
end;
if ShapeMF.left=Form1.Rechts.left
then
begin
cR:=cR-1;
end;
Form1.Timer1.Enabled:=true;
While Form1.Timer1.Enabled = true
do
begin
Application.Processmessages;
Sleep(10);
end;
end;
procedure rec(r: integer;TA,TB,TC: TShape);
begin
if r>0
then
begin
rec(r-1,TA,TC,TB);
movetop(r,TA,TC);
rec(r-1,TB,TA,TC);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
draw(100,550,200,50,'
Links');
draw(400,550,200,50,'
Mitte');
draw(700,550,200,50,'
Rechts');
draw(195,120,10,430,'
StabLinks');
draw(495,120,10,430,'
StabMitte');
draw(795,120,10,430,'
StabRechts');
end;
procedure TForm1.Button2Click(Sender: TObject);
var k: Integer;
begin
k:=StrToInt(Edit1.Text);
if k > 10
then
k:=10;
if k < 3
then
k:=3;
q:=true;
rec(k,Links,Mitte,Rechts);
end;
procedure TForm1.Button3Click(Sender: TObject);
var k: Integer;
begin
k:=StrToInt(Edit1.Text);
if k > 10
then
begin
k:=10;
ShowMessage('
Achtung: Da die gewünschte Anzahl an Scheiben über dem gültigen Maximalwert liegt, werden 10 Scheiben generiert.');
end;
if k < 3
then
begin
k:=3;
ShowMessage('
Achtung: Da die gewünschte Anzahl an Scheiben unter dem gültigen Minimalwert liegt, werden 3 Scheiben generiert.');
end;
cL:= k;
cM:= 0;
cR:= 0;
towerA(k);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if q=true
then
begin
if Scheibe[
index].Top > 50
then
Scheibe[
index].Top:=Scheibe[
index].Top-10;
end;
if Scheibe[
index].Top=50
then
begin
if Scheibe[
index].Left > ShapeT2.Left+((200-Scheibe[
index].width)
DIV 2)
then
Scheibe[
index].Left:=Scheibe[
index].Left-10;
if Scheibe[
index].Left < ShapeT2.Left+((200-Scheibe[
index].width)
DIV 2)
then
Scheibe[
index].Left:=Scheibe[
index].Left+10;
end;
if Scheibe[
index].Left = ShapeT2.Left+((200-Scheibe[
index].width)
DIV 2)
then
begin
q:=false;
if Scheibe[
index].Top < z
then
Scheibe[
index].Top:=Scheibe[
index].Top +10;
if Scheibe[
index].Top = z
then
begin
q:=true;
Timer1.Enabled:=false;
end;
end;
end;
end.