unit Unit10;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, Gauges;
type
TForm1 =
class(TForm)
Image1: TImage;
BitBtn1: TBitBtn;
Panel2: TPanel;
BitBtn3: TBitBtn;
Gauge1: TGauge;
BitBtn2: TBitBtn;
procedure FormActivate(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure sucheanfangspunkt;
procedure zeichnelabyrinth(b,h:integer);
function zeichnelinienstueck : boolean;
function istbelegt(i,j:integer) : boolean;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
function zielgefunden : boolean;
private
{ Private-Deklarationen }
public
x: integer;
y: integer;
vx: integer;
vy: integer;
dx,dy : integer;
fertig: boolean;
striche : integer;
n, u, a: integer;
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormActivate(Sender: TObject);
begin
randomize;
vx:= 10;
vy:= 10;
dx := 1;
dy := 0;
n := 0;
u := 0;
a := 0;
image1.canvas.rectangle(0,0,image1.width,image1.height);
image1.canvas.pen.color:= clwhite;
image1.canvas.MoveTo(1,300);
image1.canvas.lineTo(10,300);
image1.canvas.MoveTo(299,0);
image1.canvas.lineTo(290,0);
image1.canvas.pen.color:= clblack;
BitBtn2.Enabled := false;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
close;
end;
function TForm1.istbelegt(i,j:integer) : boolean;
begin
result := image1.canvas.pixels[i*vx,j*vy]=clblack;
if (i<0)
or (j<0)
or (i>30)
or (j>30)
then result := true;
end;
procedure tform1.sucheanfangspunkt;
begin
repeat
x:=random((31));
y:=random((31));
until istbelegt(x,y);
end;
function tform1.zeichnelinienstueck : boolean;
var ende : boolean;
i,d : integer;
begin
i := random(10);
case i
of
0 :
begin dx := -1; dy := 0;
end;
1 :
begin dx := 0; dy := -1;
end;
2 :
begin dx := +1; dy := 0;
end;
3 :
begin dx := 0; dy := +1;
end;
end;
i := 0;
repeat
if(istbelegt(x+dx,y+dy))
then
begin
inc(i);
d := dx;
dx := -dy;
dy := d;
if i >= 4
then ende := true;
end;
until ende;
result := false;
if not(istbelegt(x+dx,y+dy))
then
begin
result := true;
image1.canvas.MoveTo(x*vx,y*vy);
x := x+dx; y := y+dy;
image1.canvas.lineto(x*vx+dx,y*vy+dy);
// sleep(10);
// image1.Refresh;
inc(n);
gauge1.progress:=n;
end;
end;
procedure tform1.zeichnelabyrinth(b,h:integer);
var max : integer;
begin
max:= (b-1)*(h-1);
n:= 0;
repeat
sucheanfangspunkt;
repeat
until not(zeichnelinienstueck);
until n*10>=max*10;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
image1.canvas.rectangle(0,0,image1.width,image1.height);
image1.canvas.pen.color:= clwhite;
image1.canvas.MoveTo(1,300);
image1.canvas.lineTo(10,300);
image1.canvas.MoveTo(299,0);
image1.canvas.lineTo(290,0);
image1.canvas.pen.color:= clblack;
screen.Cursor := crHourGlass;
BitBtn1.Enabled := false;
BitBtn2.Enabled := false;
BitBtn3.Enabled := false;
zeichnelabyrinth(30,30);
BitBtn1.Enabled := true;
BitBtn2.Enabled := true;
BitBtn3.Enabled := true;
screen.Cursor := crDefault;
end;
function tform1.zielgefunden;
begin
if image1.canvas.pixels[295,5]=clred
then result:= true
else result:= false
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var aktx,akty : integer;
begin
aktx:=5;
akty:=295;
image1.canvas.pen.width:=9;
image1.canvas.pen.color:=clred;
repeat
until zielgefunden=true;
image1.canvas.pen.width:=1;
end;
end.