diff --git a/lazarus/click/project1.ico b/lazarus/click/project1.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/lazarus/click/project1.ico differ diff --git a/lazarus/click/project1.lpi b/lazarus/click/project1.lpi new file mode 100644 index 0000000..3afe492 --- /dev/null +++ b/lazarus/click/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/click/project1.lpr b/lazarus/click/project1.lpr new file mode 100644 index 0000000..58c35dc --- /dev/null +++ b/lazarus/click/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/click/project1.res b/lazarus/click/project1.res new file mode 100644 index 0000000..e994dfa Binary files /dev/null and b/lazarus/click/project1.res differ diff --git a/lazarus/click/unit1.lfm b/lazarus/click/unit1.lfm new file mode 100644 index 0000000..72740f2 --- /dev/null +++ b/lazarus/click/unit1.lfm @@ -0,0 +1,11 @@ +object Form1: TForm1 + Left = 463 + Height = 686 + Top = 197 + Width = 354 + Caption = 'Form1' + OnCreate = FormCreate + OnMouseDown = FormMouseDown + OnPaint = FormPaint + LCLVersion = '1.6.2.0' +end diff --git a/lazarus/click/unit1.pas b/lazarus/click/unit1.pas new file mode 100644 index 0000000..f085db4 --- /dev/null +++ b/lazarus/click/unit1.pas @@ -0,0 +1,133 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Math; + +type + + { TForm1 } + + TForm1 = class(TForm) + procedure FormCreate(Sender: TObject); + procedure FormMouseDown(Sender: TObject; Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); + procedure FormPaint(Sender: TObject); + private + { private declarations } + public + { public declarations } + end; + +const + cols = 10; + rows = 20; + size = 30; + colorsCount = 3; + colors: array [0..5] of TColor = (clWhite, clYellow, clRed, clBlue, clGray, clLtGray); + +var + Form1: TForm1; + board: array[0..cols, 0..rows] of TColor; + +implementation + +{$R *.lfm} + +function getBlock(x, y: integer): TColor; +begin + Result := clBlack; + if (x >= 0) and (x < cols) and (y >= 0) and (y < rows) then + Result := board[x, y]; +end; + +procedure Check(x, y: integer); +var + color: TColor; +begin + color := getBlock(x, y); + if (color <> colors[0]) and (color <> clBlack) then begin + if getBlock(x-1, y) = color then begin + board[x, y] := colors[0]; + Check(x-1, y); + board[x-1, y] := colors[0]; + end; + if getBlock(x+1, y) = color then begin + board[x, y] := colors[0]; + Check(x+1, y); + board[x+1, y] := colors[0]; + end; + if getBlock(x, y-1) = color then begin + board[x, y] := colors[0]; + Check(x, y-1); + board[x, y-1] := colors[0]; + end; + if getBlock(x, y+1) = color then begin + board[x, y] := colors[0]; + Check(x, y+1); + board[x, y+1] := colors[0]; + end; + end; +end; + +procedure Fall; +var + x, y, dx, dy: integer; +begin + dx := 0; + for x := 0 to cols-1 do begin + dy := 0; + for y := 0 to rows-1 do begin + if board[x, y] <> colors[0] then begin + if (dx<>0) or (dy<>0) then begin + board[x-dx, y-dy] := board[x, y]; + board[x, y] := colors[0]; + end; + end else begin + Inc(dy); + end; + end; + if dy=rows then Inc(dx); + end; +end; + +{ TForm1 } + +procedure TForm1.FormCreate(Sender: TObject); +var + x, y: integer; +begin + randomize; + for x := 0 to cols-1 do begin + for y := 0 to rows-1 do begin + board[x, y] := colors[ RandomRange(1, colorsCount+1) ]; + end; + end; +end; + +procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); +begin + Check(x div size, rows-1-(y div size)); + Fall; + if ssCtrl in Shift then FormCreate(nil); + Refresh; +end; + +procedure TForm1.FormPaint(Sender: TObject); +var + x, y: integer; +begin + for x := 0 to cols-1 do begin + for y := 0 to rows-1 do begin + Canvas.Brush.Color := board[x, rows-y-1]; + Canvas.FillRect(Rect(x*size, y*size, (x+1)*size, (y+1)*size)); + end; + end; +end; + +end. +