unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
DrawGrid1: TDrawGrid;
procedure FormCreate(Sender: TObject);
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
xo:bool; //
implementation
{$R *.dfm}
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
i,j:integer;
summvert,summhorz,summdiag1,summdiag2:string;
begin
if (DrawGrid1.Cell[ACol,ARow]<>'') then exit; //пустое ли поле
if xo
then DrawGrid1.Cell[ACol,ARow]:='X'
else DrawGrid1.Cell[ACol,ARow]:='O'; // -, -
xo:=not xo; //
for i:=0 to 19 do //
for j:=0 to 19 do
begin
summvert:=DrawGrid1.cell[i,j]+DrawGrid1.cell[i+1,j]+DrawGrid1.cell[i+2,j]+DrawGrid1.cell[i+3,j]+DrawGrid1.cell[i+4,j];
summhorz:=DrawGrid1.cell[i,j]+DrawGrid1.cell[i,j+1]+DrawGrid1.cell[i,j+2]+DrawGrid1.cell[i,j+3]+DrawGrid1.cell[i,j+4];
summdiag1:=DrawGrid1.cell[i,j]+DrawGrid1.cell[i+1,j+1]+DrawGrid1.cell[i+2,j+2]+DrawGrid1.cell[i+3,j+3]+DrawGrid1.cell[i+4,j+4];
summdiag2:=DrawGrid1.cell[i,j+4]+DrawGrid1.cell[i+1,j+3]+DrawGrid1.cell[i+2,j+2]+DrawGrid11.cell[i+3,j+1]+DrawGrid1.cell[i+4,j];
if (summvert='XXXXX') or (summhorz='XXXXX') or (summdiag1='XXXXX') or(summdiag2='XXXXX') then MessageDlg('X-win', mtInformation,[mbOk], 0);
if (summvert='OOOOO') or (summhorz='OOOOO') or (summdiag1='OOOOO') or(summdiag2='OOOOO') then MessageDlg('O-win', mtInformation,[mbOk], 0);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
xo:=true; // -, -
end;
end.