|
|
356e8e |
unit Unit1;
|
|
|
356e8e |
|
|
|
356e8e |
{$mode objfpc}{$H+}
|
|
|
356e8e |
|
|
|
356e8e |
interface
|
|
|
356e8e |
|
|
|
356e8e |
uses
|
|
|
356e8e |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
|
|
|
356e8e |
|
|
|
356e8e |
type
|
|
|
356e8e |
|
|
|
356e8e |
{ TForm1 }
|
|
|
356e8e |
|
|
|
356e8e |
TForm1 = class(TForm)
|
|
|
356e8e |
Button1: TButton;
|
|
|
356e8e |
procedure Button1Click(Sender: TObject);
|
|
|
356e8e |
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
|
|
|
356e8e |
Shift: TShiftState; X, Y: Integer);
|
|
|
356e8e |
procedure FormPaint(Sender: TObject);
|
|
|
356e8e |
private
|
|
|
356e8e |
{ private declarations }
|
|
|
356e8e |
public
|
|
|
356e8e |
{ public declarations }
|
|
|
356e8e |
end;
|
|
|
356e8e |
|
|
|
356e8e |
const
|
|
|
356e8e |
columns = 4;
|
|
|
356e8e |
rows = 4;
|
|
|
356e8e |
diameter = 40;
|
|
|
356e8e |
|
|
|
356e8e |
var
|
|
|
356e8e |
Form1: TForm1;
|
|
|
356e8e |
board: array[0..rows, 0..columns] of boolean;
|
|
|
356e8e |
|
|
|
356e8e |
implementation
|
|
|
356e8e |
|
|
|
356e8e |
{$R *.lfm}
|
|
|
356e8e |
|
|
|
356e8e |
procedure TForm1.FormPaint(Sender: TObject);
|
|
|
356e8e |
var
|
|
|
356e8e |
r, c: integer;
|
|
|
356e8e |
begin
|
|
|
356e8e |
for r := 0 to rows-1 do begin
|
|
|
356e8e |
for c := 0 to columns-1 do begin
|
|
|
356e8e |
if board[r, c] then begin
|
|
|
356e8e |
Canvas.Brush.Color := clBlue;
|
|
|
356e8e |
end else begin
|
|
|
356e8e |
Canvas.Brush.Color := clYellow;
|
|
|
356e8e |
end;
|
|
|
356e8e |
Canvas.Ellipse(c*diameter, r*diameter, (c+1)*diameter, (r+1)*diameter);
|
|
|
356e8e |
end;
|
|
|
356e8e |
end;
|
|
|
356e8e |
end;
|
|
|
356e8e |
|
|
|
356e8e |
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
|
|
|
356e8e |
Shift: TShiftState; X, Y: Integer);
|
|
|
356e8e |
var
|
|
|
356e8e |
r, c: integer;
|
|
|
356e8e |
begin
|
|
|
356e8e |
c := X div diameter;
|
|
|
356e8e |
r := Y div diameter;
|
|
|
356e8e |
|
|
|
356e8e |
if (r>=0) and (c>=0) and (r
|
|
|
356e8e |
board[r, c] := not board[r, c];
|
|
|
356e8e |
if r > 0 then board[r-1, c] := not board[r-1, c];
|
|
|
356e8e |
if r < rows-1 then board[r+1, c] := not board[r+1, c];
|
|
|
356e8e |
if c > 0 then board[r, c-1] := not board[r, c-1];
|
|
|
356e8e |
if c < columns-1 then board[r, c+1] := not board[r, c+1];
|
|
|
356e8e |
end;
|
|
|
356e8e |
|
|
|
356e8e |
Refresh;
|
|
|
356e8e |
end;
|
|
|
356e8e |
|
|
|
356e8e |
procedure TForm1.Button1Click(Sender: TObject);
|
|
|
356e8e |
var
|
|
|
356e8e |
i: integer;
|
|
|
356e8e |
x, y: integer;
|
|
|
356e8e |
begin
|
|
|
356e8e |
for i := 0 to 100 do begin
|
|
|
356e8e |
x := round(Random * columns * diameter);
|
|
|
356e8e |
y := round(Random * rows * diameter);
|
|
|
356e8e |
FormMouseDown(nil, mbLeft, [], x, y);
|
|
|
356e8e |
end;
|
|
|
356e8e |
end;
|
|
|
356e8e |
|
|
|
356e8e |
end.
|
|
|
356e8e |
|