📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
DrawGrid1: TDrawGrid;
procedure FormCreate(Sender: TObject);
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
tag:array[0..18,0..18] of integer;
isblack:boolean;
{ Private declarations }
public
function iswin(isblack:boolean):boolean;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
function TForm1.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;
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.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
drawgrid1.Canvas.Pen.Color :=clblack;
drawgrid1.Canvas.Brush.Color :=clblack;
if tag[acol,arow]=1 then
drawgrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
else if tag[acol,arow]=2 then
drawgrid1.Canvas.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.Canvas.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 //在private里,tag定义为数组
begin
if isblack then
begin
drawgrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21,(row+1)*21);
tag[col,row]:=1;
end else
begin
drawgrid1.Canvas.Arc(col*21,row*21,(col+1)*21,(row+1)*21,col*21,row*21,col*21,row*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;
if not 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;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -