Не работает твой код пяти в ряд. Вот процедура и функция, немного измененная:
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;