unit m_lab;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, interakt, ExtCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
bt_create: TButton;
bt_search: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Timer1: TTimer;
BtStop: TButton;
Btgoon: TButton;
procedure bt_createClick(Sender: TObject);
procedure bt_searchClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure BtStopClick(Sender: TObject);
procedure BtgoonClick(Sender: TObject);
private
feld: array[0..19,0..18] of char;
zielerreicht: boolean;
procedure labyrinth(sp,zl: integer);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.bt_createClick(Sender: TObject);
var x, i, j: integer;
begin
zielerreicht:= false;
for i:= 0 to 19 do begin
for j:= 0 to 18 do begin
feld[i,j]:=' ';
StringGrid1.Cells[i,j]:= feld[i,j];
end;
end;
x:=0;
while x < 19 do
begin
for i:= 0 to 19 do
begin
feld[i,x]:='M';
StringGrid1.Cells[i,x]:= feld[i,x];
end;
x:=x+2;
end;
for i:=0 to 18 do begin
feld[0,i]:='M';
StringGrid1.Cells[0,i]:= feld[0,i];
end;
for i:=0 to 18 do begin
feld[19,i]:='M';
StringGrid1.Cells[19,i]:= feld[19,i];
end;
feld[2,2]:=' ';
StringGrid1.Cells[2,2]:= feld[2,2];
feld[7,4]:=' ';
StringGrid1.Cells[7,4]:= feld[7,4];
feld[13,6]:=' ';
StringGrid1.Cells[13,6]:= feld[13,6];
feld[1,8]:=' ';
StringGrid1.Cells[1,8]:= feld[1,8];
feld[14,10]:=' ';
StringGrid1.Cells[14,10]:= feld[14,10];
feld[7,12]:=' ';
StringGrid1.Cells[7,12]:= feld[7,12];
feld[11,13]:='M';
StringGrid1.Cells[11,13]:= feld[11,13];
feld[1,14]:=' ';
StringGrid1.Cells[1,14]:= feld[1,14];
feld[16,16]:=' ';
StringGrid1.Cells[16,16]:= feld[16,16];
feld[1,17]:='Z';
StringGrid1.Cells[1,17]:= feld[1,17];
feld[1,1]:= 'S';
stringgrid1.cells[1,1] := feld[1,1];
end;
procedure TForm1.labyrinth(sp,zl: integer);
var
zlz, spz : integer;
begin
if not zielerreicht then
begin
if (feld[sp,zl]<>'M') and (feld[sp,zl]<>'.') then
begin
if feld[sp,zl]='Z' then
begin
zielerreicht:=true;
feld[sp,zl]:= 'E';
StringGrid1.Cells[sp,zl]:= feld[sp,zl];
StringGrid1.Cells[1,1]:= feld[1,1];
label1.visible := true;
warte;
end
else
feld[sp,zl]:='.';
StringGrid1.Cells[sp,zl]:= feld[sp,zl];
warte;
spz:=1;
zlz:=17;
if (sp < 19) and (sp > 0) and (zl< 18) and (zl > 0) then
begin
if (sp>spz)then
begin
if (zl>zlz) then
begin
if abs(sp-spz)>abs(zl-zlz)
then
begin
labyrinth(sp-1,zl);
labyrinth(sp,zl-1);
end
else
begin
labyrinth(sp,zl-1);
labyrinth(sp-1,zl);
end;
labyrinth(sp+1,zl);
labyrinth(sp,zl+1);
if not zielerreicht then
begin
feld[sp,zl]:='X';
StringGrid1.Cells[sp,zl]:= feld[sp,zl];
end;
end
else
begin
labyrinth(sp-1,zl);
labyrinth(sp,zl+1);
labyrinth(sp+1,zl);
labyrinth(sp,zl-1);
if not zielerreicht then
begin
feld[sp,zl]:='X';
StringGrid1.Cells[sp,zl]:= feld[sp,zl];
end;
end
end
else
if (zl>zlz)then
begin
labyrinth(sp+1,zl);
labyrinth(sp,zl-1);
labyrinth(sp-1,zl);
labyrinth(sp,zl+1);
if not zielerreicht then
begin
feld[sp,zl]:='X';
StringGrid1.Cells[sp,zl]:= feld[sp,zl];
end;
end
else
begin
labyrinth(sp+1,zl);
labyrinth(sp,zl+1);
labyrinth(sp-1,zl);
labyrinth(sp,zl-1);
if not zielerreicht then
begin
feld[sp,zl]:='X';
StringGrid1.Cells[sp,zl]:= feld[sp,zl];
end;
end;
end;
end;
end;
end;
procedure TForm1.bt_searchClick(Sender: TObject);
begin
labyrinth(1,1);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
mach_weiter;
end;
procedure TForm1.BtStopClick(Sender: TObject);
begin
timer1.Enabled := false;
BtStop.Visible := false;
Btgoon.Visible := true;
end;
procedure TForm1.BtgoonClick(Sender: TObject);
begin
timer1.Enabled := true;
Btgoon.visible := false;
Btstop.Visible := true;
end;
end.