unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ExtCtrls, Spin;
type
TForm1 =
class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Label1: TLabel;
RadioGroup1: TRadioGroup;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Gr: integer;
//Größe des Quadrats
Quadrat:
array of array of integer;
X, Y, X1, Y1, I: Integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
case RadioGroup1.ItemIndex
of
0: Gr:=2;
1: Gr:=4;
2: Gr:=6;
else exit;
end;
for I:=0
to Gr
do
begin
StringGrid1.Rows[I].Clear;
StringGrid1.Cols[I].Clear;
end;
Memo1.Clear;
StringGrid1.ColCount:=Gr+1;
StringGrid1.RowCount:=Gr+1;
SetLength(Quadrat, Gr*Gr, Gr*Gr);
X:=Gr-trunc(Gr/2);
Y:=Gr-trunc(Gr/2)+1;
Quadrat[X, Y]:=1;
StringGrid1.Cells[X, Y]:=IntToStr(Quadrat[X, Y]);
Memo1.Lines.Add('
Quadrat['+IntToStr(X)+'
,'+IntToStr(Y)+'
] '
+'
= '+IntToStr(Quadrat[X, Y]));
for I:=2
to Gr*Gr+2*Gr+1
do
begin
if StringGrid1.Cells[X+1, Y+1]='
'
then
begin
X:=X+1;
Y:=Y+1;
end
else
begin
X:=X+3;
Y:=Y+2;
end;
if X>Gr
then
begin
X:=X-Gr-1;
end;
if Y>Gr
then
begin
Y:=Y-Gr-1;
end;
Quadrat[X, Y]:=I;
StringGrid1.Cells[X, Y]:=IntToStr(Quadrat[X, Y]);
Memo1.Lines.Add('
Quadrat['+IntToStr(X)+'
,'+IntToStr(Y)+'
] '
+'
= '+IntToStr(Quadrat[X, Y]));
end;
end;
end.