unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
MannX: Integer;
MannY: Integer;
JagdX: Integer;
JagdY: Integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Visible := false;
Canvas.Brush.Color := clred;
Form1.Canvas.Rectangle(MannX,MannY,MannX+50,MannY+50);
Form1.Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
if (MannX + 50 > JagdX)
and (MannX < JagdX + 50)
and {3} (MannY + 50 > JagdY)
and (MannY < JagdY+50)
then
begin
JagdX := Random(4000) + 1;
JagdY := Random(4000) + 1;
Canvas.Rectangle(JagdX, JagdY, JagdX + 50, JagdY + 50);
// 2
end;
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if Key= Ord('
W')
then
begin
dec(mannY,5);
Form1.Refresh;
Canvas.Rectangle(MannX,MannY,MannX + 50,MannY+50);
JagdX:=random(40)+1;
JagdY:=random(40)+1;
Form1.Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
end;
if Key= Ord('
S')
then
begin
inc(MannY,5);
Form1.Refresh;
Canvas.Rectangle(MannX,MannY,MannX + 50,MannY+50);
JagdX:=random(40)+1;
JagdY:=random(40)+1;
Form1.Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
end;
if Key= Ord('
A')
then
begin
Dec(MannX,5);
Refresh;
Canvas.Rectangle(MannX,MannY,MannX + 50,MannY+50);
inc(JagdX, random(41)-20) ;
inc(JagdY, random(41)-20) ;
Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
end;
if Key= Ord('
D')
then
begin
//rechts
inc(MannX,5);
Form1.Refresh;
Canvas.Rectangle(MannX,MannY,MannX + 50,MannY+50);
JagdX:=random(40)+1;
JagdY:=random(40)+1;
Form1.Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
end;
end;
end.