unit Test;
interface
uses
System.Generics.Collections;
type
TPerson =
class
public
Name:
String;
X, Y: Integer;
constructor Create(
name:
String);
procedure SetKoordinaten(x, y: Integer);
end;
TFamilie =
class
public
Vater: TPerson;
Mutter: TPerson;
Kinder: TList<TPerson>;
constructor Create(vater: TPerson, mutter: TPerson);
end;
TGraphBuilder =
class
public
Familie: TFamilie;
Picture: TCanvas;
constructor Create(familie: TFamilie)
procedure Draw;
end;
Const
Abstand: Integer = 50;
Breite: Integer = 100;
Hoehe: Integer = 40;
implementation
// TPerson
constructor TPerson.Create(
name:
String);
begin
inherited;
Name =
name;
end;
procedure SetKoordinaten(x, y: Integer);
begin
X = x;
Y = y;
end;
// TFamilie
constructor TFamilie.Create(vater: TPerson, mutter: TPerson);
begin
inherited;
Vater = vater;
Mutter = mutter;
Kinder = TList.Create;
end;
// TGraphBuilder
constructor TGraphBuilder.Create(familie: TFamilie);
begin
inherited;
Familie = familie;
end;
procedure TGraphBuilder.Draw;
var
i: Integer;
begin
Familie.Vater.SetKoordinaten(0, 0);
Familie.Mutter.SetKoordinaten(Vater.X + Breite + Abstand, 0);
// Vater/Mutter zeichnen
Picture.Rectangle(Vater.X, Vater.Y, Vater.X + Breite, Vater.Y + Hoehe);
Picture.Rectangle(Mutter.X, Vater.Y, Mutter.X + Breite, Mutter.Y + Hoehe);
// Kinder
for i:= Low(Familie.Kinder)
To High(Familie.Kinder)
do begin
if i = 0
then
Kinder(i).SetKoordinaten(i * Breite, Vater.Y + Hoehe + Abstand);
else
Kinder(i).SetKoordinaten(i * Breite + Abstand, Vater.Y + Hoehe + Abstand);
end;
Picture.Rectangle(Kinder(i).X, Kinder(i).Y, Kinder(i).X + Breite, Kinder(i).Y + Hoehe);
Picture.Textout(Kinder(i).X, Kinder(i).Y, Kinder(i).
Name);
end;
end;
end.