[go: up one dir, main page]

Skip to content

Commit

Permalink
Move main of maze to Maze unit
Browse files Browse the repository at this point in the history
  • Loading branch information
zaher committed Apr 9, 2022
1 parent fc31a3c commit 767ee72
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 67 deletions.
65 changes: 65 additions & 0 deletions src/tyrolib/delphi/test/TestMaze.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ TCell = class
function Check: TCell;
end;

TMazeMain = class(TTyroMain)
public
procedure Init; override;
procedure Setup; override;
procedure Draw; override;
procedure Unload; override;
end;

var
Cells:TCells;

Expand Down Expand Up @@ -173,4 +181,61 @@ procedure TCell.Show;
end;
end;

{ TMazeMain }

procedure TMazeMain.Draw;
begin
inherited;
Canvas.PenAlpha := 0;
Canvas.PenColor := clBlack;
Canvas.DrawText(30, 30, 'Ready!', clBlack);

for var aCell in Cells do
aCell.Show;

FCurrent.FHit := True;
FNext := FCurrent.Check;
if FNext<>nil then
begin
FNext.FHit := True;
Stack.Push(FCurrent);
FCurrent.RemoveWalls(FNext);
FCurrent := FNext;
end
else
begin
if Stack.Count<>0 then
FCurrent := Stack.Pop;
end;
end;

procedure TMazeMain.Init;
begin
inherited;
FCW := FWidth div FCols;
Cells := TObjectList<TCell>.Create;
Stack := TStack<TCell>.Create;

ShowWindow(FWidth, FHeight);
for var row in [0..FRows-1] do
for var col in [0..FCols-1] do
Cells.Add(TCell.Create(row, col, FCW));

FCurrent := Cells[0];
end;

procedure TMazeMain.Setup;
begin
inherited;
SetFPS(10);
//Options := Options + [moShowFPS];
end;

procedure TMazeMain.Unload;
begin
inherited;
FreeAndNil(Cells);
FreeAndNil(Stack);
end;

end.
68 changes: 1 addition & 67 deletions src/tyrolib/delphi/test/test.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -12,75 +12,9 @@ uses
Generics.Collections,
TestMaze in 'TestMaze.pas';

type
TMyMain = class(TTyroMain)
public
procedure Init; override;
procedure Setup; override;
procedure Draw; override;
procedure Unload; override;
end;

{ TMyMain }

procedure TMyMain.Draw;
begin
inherited;
Canvas.PenAlpha := 0;
Canvas.PenColor := clBlack;
Canvas.DrawText(30, 30, 'Ready!', clBlack);

for var aCell in Cells do
aCell.Show;

FCurrent.FHit := True;
FNext := FCurrent.Check;
if FNext<>nil then
begin
FNext.FHit := True;
Stack.Push(FCurrent);
FCurrent.RemoveWalls(FNext);
FCurrent := FNext;
end
else
begin
if Stack.Count<>0 then
FCurrent := Stack.Pop;
end;
end;

procedure TMyMain.Init;
begin
inherited;
FCW := FWidth div FCols;
Cells := TObjectList<TCell>.Create;
Stack := TStack<TCell>.Create;

ShowWindow(FWidth, FHeight);
for var row in [0..FRows-1] do
for var col in [0..FCols-1] do
Cells.Add(TCell.Create(row, col, FCW));

FCurrent := Cells[0];
end;

procedure TMyMain.Setup;
begin
inherited;
SetFPS(10);
//Options := Options + [moShowFPS];
end;

procedure TMyMain.Unload;
begin
inherited;
FreeAndNil(Cells);
FreeAndNil(Stack);
end;

begin
Randomize;
Main := TMyMain.Create;
Main := TMazeMain.Create;
try
Main.Run;
except
Expand Down

0 comments on commit 767ee72

Please sign in to comment.