diff --git a/lazarus/maze/level.txt b/lazarus/maze/level.txt new file mode 100644 index 0000000..5febf5e --- /dev/null +++ b/lazarus/maze/level.txt @@ -0,0 +1,10 @@ +########## +#........# +#.######.. +#......#.# +#.####.#.# +#...#.X#.# +#.#....#.# +#.##.##### +#..#.....# +########.# diff --git a/lazarus/maze/project1.ico b/lazarus/maze/project1.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/lazarus/maze/project1.ico differ diff --git a/lazarus/maze/project1.lpi b/lazarus/maze/project1.lpi new file mode 100644 index 0000000..3afe492 --- /dev/null +++ b/lazarus/maze/project1.lpi @@ -0,0 +1,79 @@ + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <Icon Value="0"/> + </General> + <i18n> + <EnableI18N LFM="False"/> + </i18n> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="LCL"/> + </Item1> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="project1.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="project1"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/lazarus/maze/project1.lpr b/lazarus/maze/project1.lpr new file mode 100644 index 0000000..58c35dc --- /dev/null +++ b/lazarus/maze/project1.lpr @@ -0,0 +1,21 @@ +program project1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, Unit1 + { you can add units after this }; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/lazarus/maze/project1.res b/lazarus/maze/project1.res new file mode 100644 index 0000000..e994dfa Binary files /dev/null and b/lazarus/maze/project1.res differ diff --git a/lazarus/maze/unit1.lfm b/lazarus/maze/unit1.lfm new file mode 100644 index 0000000..28b61f9 --- /dev/null +++ b/lazarus/maze/unit1.lfm @@ -0,0 +1,11 @@ +object Form1: TForm1 + Left = 275 + Height = 504 + Top = 248 + Width = 509 + Caption = 'Form1' + OnCreate = FormCreate + OnKeyDown = FormKeyDown + OnPaint = FormPaint + LCLVersion = '1.6.2.0' +end diff --git a/lazarus/maze/unit1.pas b/lazarus/maze/unit1.pas new file mode 100644 index 0000000..a36cbbe --- /dev/null +++ b/lazarus/maze/unit1.pas @@ -0,0 +1,103 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, LCLType; + +type + + { TForm1 } + + TForm1 = class(TForm) + procedure FormCreate(Sender: TObject); + procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); + procedure FormPaint(Sender: TObject); + private + { private declarations } + public + { public declarations } + end; + +const + rows = 10; + cols = 10; + size = 30; + +var + Form1: TForm1; + board: array[0..rows, 0..cols] of boolean; + px, py: integer; + +implementation + +{$R *.lfm} + +procedure TForm1.FormCreate(Sender: TObject); +var + f: textfile; + c: char; + x, y: integer; +begin + AssignFile(f, 'level.txt'); + Reset(f); + for y:=0 to rows-1 do begin + for x:=0 to cols-1 do begin + Read(f, c); + if c = '.' then board[x, y] := true; + if c = '#' then board[x, y] := false; + if c = 'X' then begin + board[x, y] := true; + px := x; + py := y; + end; + end; + Readln(f, c); + end; + CloseFile(f); +end; + +procedure TForm1.FormPaint(Sender: TObject); +var + x, y: integer; +begin + for y:=0 to rows-1 do begin + for x:=0 to cols-1 do begin + if board[x, y] = false then begin + Canvas.Rectangle(x*size, y*size, (x+1)*size, (y+1)*size); + end; + end; + end; + + Canvas.Ellipse(px*size, py*size, (px+1)*size, (py+1)*size); +end; + +procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; + Shift: TShiftState); +var + x, y: integer; +begin + x := px; + y := py; + + if Key = VK_UP then y := py - 1; + if Key = VK_DOWN then y := py + 1; + if Key = VK_LEFT then x := px - 1; + if Key = VK_RIGHT then x := px + 1; + + if board[x, y] then begin + px := x; + py := y; + end; + + if (x < 0) or (y < 0) or (x >= cols) or (y >= rows) then begin + ShowMessage('You are escaped from this maze!'); + end; + + Refresh; +end; + +end. +