Задача: сделать крестики - нолики для двоих на безграничном поле, выигрывает, тот кто посптаит 5 в ряд.
Подскажите как сделать, чтобы поле увеличивалось вместе с окном.
И как осуществить проверку 5ти в ряд.
Спасибо.
a: Array [1..10,1..10] of Byte;
Function won(X,Y,P: Byte): Boolean;
Function won(x,y,p: Byte): Boolean;
Const
VK = 5;
var
i,j: Byte;
begin
i:=x;
j:=x;
while (a[y,i-1] = p)
do Dec(i);
while (a[y,j+1] = p)
do Inc(j);
if j-i >= VK-1
then begin
won:=true;
exit
end;
won:=false
end;
Function won(x,y,p: Byte): Boolean;
Const
VK = 5;
var
i,j: Byte;
begin
i:=x;
j:=x;
while (a[y,i-1] = p)
do Dec(i);
while (a[y,j+1] = p)
do Inc(j);
if j-i >= VK-1
then begin
won:=true;
exit
end;
i:=y;
j:=y;
while (a[i-1,x] = p)
do Dec(i);
while (a[j+1,x] = p)
do Inc(j);
if j-i >= VK-1
then begin
won:=true;
exit
end;
i:=x;
j:=x;
while (a[y-(x-i+1),i-1] = p)
do Dec(i);
while (a[y+(j-x+1),j+1] = p)
do Inc(j);
if j-i >= VK-1
then begin
won:=true;
exit
end;
i:=x;
j:=x;
while (a[y+(x-i+1),i-1] = p)
do Dec(i);
while (a[y-(j-x+1),j+1] = p)
do Inc(j);
if j-i >= VK-1
then begin
won:=true;
exit
end;
won:=false
end;
m:=width div a;
n:=height div b
procedure TForm7.FormResize(Sender: TObject);
var I, J: integer;
begin
I:=Form7.ClientHeight;
J:=Form7.ClientWidth;
Pole.Height:=I;
Pole.Width:=J;
Pole.RowCount:=I div 15;
Pole.ColCount:=J div 15;
Form7.Caption:='Крестики - Нолики '+IntToStr(Pole.RowCount)+'x'+IntToStr(Pole.ColCount);
end;
procedure TForm8.poleSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
if pole.Cells[ACol, ARow]='' then
begin
if fig.ItemIndex=0 then
begin
Pole.Cells[ACol, ARow]:=' x';
if won(ACol, ARow, ' x')=true then ShowMessage('Крестики выграли');
end;
if fig.ItemIndex=1 then
begin
Pole.Cells[ACol, ARow]:=' o';
if won(ACol, ARow, ' o')=true then ShowMessage('Нолики выграли');
end;
fig.ItemIndex:=fig.ItemIndex-1;
if fig.ItemIndex<0 then fig.ItemIndex:=1;
end;
end;
function TForm8.won(x,y: Byte; p:string): Boolean;
Const
VK = 5;
var
i,j: Byte;
begin
i:=x;
j:=x;
while (Form8.pole.Cells[y,i-1] = p)
do Dec(i);
while (Form8.pole.Cells[y,j+1] = p)
do Inc(j);
if j-i >= VK-1
then begin
won:=true;
exit
end;
i:=y;
j:=y;
while (Form8.pole.Cells[i-1,x] = p)
do Dec(i);
while (Form8.pole.Cells[j+1,x] = p)
do Inc(j);
if j-i >= VK-1
then begin
won:=true;
exit
end;
i:=x;
j:=x;
while (Form8.pole.Cells[y-(x-i+1),i-1] = p)
do Dec(i);
while (Form8.pole.Cells[y+(j-x+1),j+1] = p)
do Inc(j);
if j-i >= VK-1
then begin
won:=true;
exit
end;
i:=x;
j:=x;
while (Form8.pole.Cells[y+(x-i+1),i-1] = p)
do Dec(i);
while (Form8.pole.Cells[y-(j-x+1),j+1] = p)
do Inc(j);
if j-i >= VK-1
then begin
won:=true;
exit
end;
won:=false
end;