unit Raten5;

interface

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

type
  TGame = class
    Eingabe, Zufall: Integer;
    Raten: TControl;
    constructor Create;
    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;
begin
  randomize;
  Zufall := random(1000) + 1;
end;

procedure TGame.Run;
begin
  try
    Eingabe := StrToInt (Form1.Edit1.Text);
    if Eingabe = Zufall then Form1.Label1.Caption := 'Richtig!';
    if Eingabe < Zufall then Form1.Label1.Caption := 'Zu klein!';
    if Eingabe > Zufall then Form1.Label1.Caption := 'Zu groß';
  except
    Form1.Label1.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;
end;

end.
