unit wuzq;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ExtCtrls;type
TForm1 = class(TForm)
Panel1: TPanel;
DrawGrid1: TDrawGrid;
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure DrawGrid1Click(Sender: TObject);
private
Tag:array[0..18,0..18]of integer;
{0 代表没有,1 黑子,2 代表白子}
IsBlack:boolean;
{ Private declarations }
public
{ Public declarations }
function IsWin(IsBlack:boolean):boolean;
label exit1;
var
i,j:integer;
wtag:integer;
begin
IsWin:=false;
if IsBlack then
wtag:=1 else
wtag:=2;
for i:=0 to 18 do
for j:=0 to 14 do
begin
{是否有行连接}
if (i<15)
and (Tag[i,j]=wtag)
and (Tag[i+1,j]=wtag)
and (Tag[i+2,j]=wtag)
and (Tag[i+3,j]=wtag)
and (Tag[i+4,j]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
{是否有列连接}
if (Tag[i,j]=wtag)
and (Tag(i,j+1)=wtag)
and (Tag(i,j+2)=wtag)
and (Tag(i,j+3)=wtag)
and (Tag(i,j+4)=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
{是否主对角连接}
if (i<15)
and (Tag[i,j]=wtag)
and (Tag[i+1,j+1]=wtag)
and (Tag[i+2,j+2]=wtag)
and (Tag[i+3,j+3]=wtag)
and (Tag[i+4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
{是否副对角连接}
if (Tag[i,j]=wtag)
and (Tag[i-1,j+1]=wtag)
and (Tag[i-2,j+2]=wtag)
and (Tag[i-3,j+3]=wtag)
and (Tag[i-4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
end;
exit1;
end;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
if tag[aco,arow]=1 then
DrawGrid1.Canvaas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
else if tag[acol,arow]=2 then
DrawGrid1.Canvaas.Arc(acol*21,arow*21,(acol+1)*21,(arow+1)*21,acol*21,arow*21,acol*21,arow*21,)
else
begin
DrawGrid1.Canvas.Pen.Color:=clWhite;
DrawGrid1.Canvas.Brush.Color:=clWhite;
DrawGrid1.Canvaas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
end;
end;procedure TForm1.DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
col,row:integer;
i,j:integer;
begin
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
DrawGrid1.MouseToCell(x,y,col,row);
if tag[col,row]=0 then
begin
if IsBlack then
begin
DrawGrid1.Canvaas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
tag[col,row]=1;
end else
begin
DrawGrid1.Canvaas.Arc(acol*21,arow*21,(acol+1)*21,(arow+1)*21,acol*21,arow*21,acol*21,arow*21,)
tag[col,row]:=2;
end;
if IsWin(IsBlack) then
begin
if IsBlack then
if MessageDlg(‘黑棋胜利’,mtInformation,[mbOK],0)=mrOK then
begin
for i:=0 to 18 do
for j:=0 to 18 do
begin
tag[i,j]:=0
end;
DrawGrid1.Invalidate;
end;
end;
IsBlack:=not IsBlack;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var
i,j:integer;
begin
for i:=0 to 18 do
for j:=0 to 18 do
begin
Tag[i,j]=0
end;
IsBlack:=true;
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
end;
procedure TForm1.DrawGrid1Click(Sender: TObject);
beginend;end;
运行时出现错误
请您帮我改正!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ExtCtrls;type
TForm1 = class(TForm)
Panel1: TPanel;
DrawGrid1: TDrawGrid;
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure DrawGrid1Click(Sender: TObject);
private
Tag:array[0..18,0..18]of integer;
{0 代表没有,1 黑子,2 代表白子}
IsBlack:boolean;
{ Private declarations }
public
{ Public declarations }
function IsWin(IsBlack:boolean):boolean;
label exit1;
var
i,j:integer;
wtag:integer;
begin
IsWin:=false;
if IsBlack then
wtag:=1 else
wtag:=2;
for i:=0 to 18 do
for j:=0 to 14 do
begin
{是否有行连接}
if (i<15)
and (Tag[i,j]=wtag)
and (Tag[i+1,j]=wtag)
and (Tag[i+2,j]=wtag)
and (Tag[i+3,j]=wtag)
and (Tag[i+4,j]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
{是否有列连接}
if (Tag[i,j]=wtag)
and (Tag(i,j+1)=wtag)
and (Tag(i,j+2)=wtag)
and (Tag(i,j+3)=wtag)
and (Tag(i,j+4)=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
{是否主对角连接}
if (i<15)
and (Tag[i,j]=wtag)
and (Tag[i+1,j+1]=wtag)
and (Tag[i+2,j+2]=wtag)
and (Tag[i+3,j+3]=wtag)
and (Tag[i+4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
{是否副对角连接}
if (Tag[i,j]=wtag)
and (Tag[i-1,j+1]=wtag)
and (Tag[i-2,j+2]=wtag)
and (Tag[i-3,j+3]=wtag)
and (Tag[i-4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
end;
exit1;
end;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
if tag[aco,arow]=1 then
DrawGrid1.Canvaas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
else if tag[acol,arow]=2 then
DrawGrid1.Canvaas.Arc(acol*21,arow*21,(acol+1)*21,(arow+1)*21,acol*21,arow*21,acol*21,arow*21,)
else
begin
DrawGrid1.Canvas.Pen.Color:=clWhite;
DrawGrid1.Canvas.Brush.Color:=clWhite;
DrawGrid1.Canvaas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
end;
end;procedure TForm1.DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
col,row:integer;
i,j:integer;
begin
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
DrawGrid1.MouseToCell(x,y,col,row);
if tag[col,row]=0 then
begin
if IsBlack then
begin
DrawGrid1.Canvaas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
tag[col,row]=1;
end else
begin
DrawGrid1.Canvaas.Arc(acol*21,arow*21,(acol+1)*21,(arow+1)*21,acol*21,arow*21,acol*21,arow*21,)
tag[col,row]:=2;
end;
if IsWin(IsBlack) then
begin
if IsBlack then
if MessageDlg(‘黑棋胜利’,mtInformation,[mbOK],0)=mrOK then
begin
for i:=0 to 18 do
for j:=0 to 18 do
begin
tag[i,j]:=0
end;
DrawGrid1.Invalidate;
end;
end;
IsBlack:=not IsBlack;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var
i,j:integer;
begin
for i:=0 to 18 do
for j:=0 to 18 do
begin
Tag[i,j]=0
end;
IsBlack:=true;
DrawGrid1.Canvas.Pen.Color:=clBlack;
DrawGrid1.Canvas.Brush.Color:=clBlack;
end;
procedure TForm1.DrawGrid1Click(Sender: TObject);
beginend;end;
运行时出现错误
请您帮我改正!
还不够烦的呢!
找个能用的不就行了嘛!?网上多得是!不行我给你发一个