unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Timer1: TTimer;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
MannX: Integer= 60;
MannY: Integer= 60;
JagdX: Integer;
JagdY: Integer;
Zufall: Integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
refresh;
Button1.Visible := false;
Timer1.Enabled := true;
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if Key= Ord('
W')
then
begin
dec(mannY,7);
Refresh;
Canvas.Rectangle(MannX,MannY,MannX + 50,MannY+50);
Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
end;
if Key= Ord('
S')
then
begin
inc(MannY,7);
Refresh;
Canvas.Rectangle(MannX,MannY,MannX + 50,MannY+50);
Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
end;
if Key= Ord('
A')
then
begin
Dec(MannX,7);
Refresh;
Canvas.Rectangle(MannX,MannY,MannX + 50,MannY+50);
Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
end;
if Key= Ord('
D')
then
begin
//rechts
inc(MannX,7);
Refresh;
Canvas.Rectangle(MannX,MannY,MannX + 50,MannY+50);
Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
zufall:=random(4);
if Zufall = 0
then inc(JagdX,10);
if Zufall = 1
then dec(JagdX,10);
if Zufall = 2
then inc(JagdY,10);
if Zufall = 3
then dec(JagdY,10);
refresh;
Canvas.Brush.Color := clred;
Canvas.Rectangle(MannX,MannY,MannX + 50,MannY+50);
Canvas.Brush.Color := clyellow;
Canvas.Rectangle(JagdX,JagdY,JagdX+50,JagdY+50);
if (MannX + 50 > JagdX)
and (MannX < JagdX + 50)
and (MannY + 50 > JagdY)
and
(MannY < JagdY+50)
then
begin
JagdX := Random(200) + 1;
JagdY := Random(200) + 1;
refresh;
Canvas.Rectangle(JagdX, JagdY, JagdX + 50, JagdY + 50);
Label1.Caption:= ('
Congrantulations');
Button1.Visible := true;
Timer1.Enabled := false;
end;
If
(JagdX + 50 > 780)
then dec(JagdX,20);
If
(JagdX + 50 < 0)
then inc(JagdX,20);
if
(JagdX < 5)
then inc(JagdX,20);
If
(JagdY < 7)
then inc(Jagdy,20);
end;