unit Raten5A;

interface

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

type
  TGame = class
    Eingabe, Zufall: Integer;
    Afeld: TLabel;
    Efeld: TEdit;
    constructor Create (AA: TLabel; EE: TEdit);
    procedure Run;
    destructor Free;
  end;

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

var
  Form1: TForm1;
  Game1: TGame;

implementation

{$R *.DFM}

constructor TGame.Create (AA: TLabel; EE: TEdit);
begin
  randomize;
  Zufall := random(1000) + 1;
  Afeld := AA;
  Efeld := EE;
end;

procedure TGame.Run;
begin
  try
    Eingabe := StrToInt (Efeld.Text);
    if Eingabe = Zufall then Afeld.Caption := 'Richtig!';
    if Eingabe < Zufall then Afeld.Caption := 'Zu klein!';
    if Eingabe > Zufall then Afeld.Caption := 'Zu groß';
  except
    Afeld.Caption := 'Quatsch!';
  end;
end;

destructor TGame.Free;
begin
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Game1.Run;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Game1 := TGame.Create (Label1, Edit1);
end;

end.
