unit Monster5;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TMonster = class
  private
    Name,
    Wesen,
    BildName: String;
  public
    constructor Create (N, W, DateiName: String);
    procedure Erscheinen;
    function Typ: String; virtual;
    destructor Destroy; override;
  end;

  TGMonster = class (TMonster)
  public
    function Typ: String; override;
  end;

  TSMonster = class (TMonster)
  public
    function Typ: String; override;
  end;

  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

const Pfad = '.\bilder\';   // 'c:\delphi\buch\bilder\';
var
  Form1: TForm1;
  WerWohl : TMonster;
  Sichtbar: Boolean;
  Zufall  : Integer;

implementation

{$R *.DFM}

constructor TMonster.Create (N, W, DateiName: String);
begin
  Name := N; Wesen := W; BildName := DateiName;
end;

destructor TMonster.Destroy;
begin
  Form1.Label1.Caption := '';
  Form1.Label2.Caption := '';
  Form1.Label3.Caption := '';
  inherited Destroy;
end;


procedure TMonster.Erscheinen;
begin
  Form1.Label1.Caption := 'Name:  ' + Name;
  Form1.Label2.Caption := 'Wesen: ' + Wesen;
  Form1.Label3.Caption := 'Typ:   ' + Typ;
  Form1.Image1.Picture.LoadFromFile (Pfad+BildName);
end;

function TMonster.Typ: String;
begin
  Typ := 'Monster';
end;

function TGMonster.Typ: String;
begin
  Typ := 'GeistesMonster';
end;

function TSMonster.Typ: String;
begin
  Typ := 'SeelenMonster';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  randomize;
  Sichtbar := true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Sichtbar then
  begin
    Zufall := random(6);
    case Zufall of
      0,3: WerWohl := TMonster.Create
           ('Frankie', 'ungewöhnlich', 'Frank.bmp');
      1,4: WerWohl := TGMonster.Create
           ('Berti', 'nachdenklich', 'Albert.bmp');
      2,5: WerWohl := TSMonster.Create
           ('Sigi', 'mitfühlend', 'Sigmund.bmp');
    end;
    WerWohl.Erscheinen;
    Image1.Show;
    Button1.Caption := 'Verschwinden';
  end
  else
  begin
    WerWohl.Free;
    Image1.Hide;
    Button1.Caption := 'Erscheinen';
  end;
  Sichtbar := not Sichtbar;
end;

end.
