1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78:
| unit LabyrintPro;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, ExtCtrls, jpeg;
type TForm1 = class(TForm) btn1: TButton; strngrd1: TStringGrid; procedure FormActivate(Sender: TObject); procedure btn1Click(Sender: TObject); private public end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure MarkeSetzen(x,y: integer; c: char); begin Form1.strngrd1.Cells[x, y] := c; end;
function ZielErreicht(x, y: integer): boolean; begin if (Form1.strngrd1.Cells[x, y] = '10') then result := true else result := false; end;
function WegSuche(x, y: integer): integer; begin ShowMessage(IntToStr(x)); MarkeSetzen(x,y,'M'); if ZielErreicht(x,y) then begin ShowMessage('Ziel erreicht'); end else begin if (x <> 0) and (x < 9) and (Form1.strngrd1.Cells[x-1,y] = '') then WegSuche(x-1,y); if (y <> 0) and (y < 9) and (Form1.strngrd1.Cells[x,y-1] = '') then WegSuche(x,y-1); if (x <> 0) and (x < 9) and (Form1.strngrd1.Cells[x+1,y] = '') then WegSuche(x+1,y); if (y <> 0) and (y < 9) and (Form1.strngrd1.Cells[x,y+1] = '') then WegSuche(x,y+1); end; MarkeSetzen(x,y,' '); end;
procedure TForm1.FormActivate(Sender: TObject); var i, j: integer; begin for i := 0 to strngrd1.ColCount - 1 do for j := 0 to strngrd1.RowCount - 1 do if (i mod 2 = 0) and (j mod 2 = 0) then begin strngrd1.Cells[i, j] := 'L'; end; strngrd1.Cells[2, 2] := '10'; strngrd1.Cells[0, 0] := ''; end;
procedure TForm1.btn1Click(Sender: TObject); begin WegSuche(3, 3); end;
end. |