我想用delphi写一个五子棋游戏,现在第一步画棋盘就遇到了麻烦,不知道哪位高手能指点一二或者给点参考资料,现在比较穷困,只能给20分了,结贴一定再补
解决方案 »
- Add IDL Files出错
- 解决象棋棋盘问题
- 如何获得图片(JPG文件)的真实尺寸?
- 使用Magic eDeveloper发送邮件
- 找会员系统资料,有的请介绍一下,谢谢。还有高分等着你。
- 简单问题(在线待)
- 誰知道那有介紹sql語句的書籍
- 100分 调用DLL文件错误提示:Exception:EResNotFound in Module DLL.dll at000318C4
- delph5的ado出错问题
- 用MediaPlayer在win2000播放mp3时,有严重的暴音,音质很差(win98没事),请问有没有别的比较好的的控件?谢谢
- listview编译出错,诚恳望指教
- 3D模型,XOF,PPM文件如何建立,能否提供详细资料
该站点刚刚去过,去了才知道垃圾阿
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids;type
Tmainform = class(TForm)
Panel1: TPanel;
DrawGrid1: TDrawGrid;
Timer1: TTimer;
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);
private
{ Private declarations }
tag:array[0..18,0..18] of integer;
isblack:boolean;
public
{ Public declarations }
maindir:string[80];
function iswin(isblack:boolean):boolean;
end;var
mainform: Tmainform;implementation{$R *.dfm}
function tmainform.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 Tmainform.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:=false;
maindir:=extractfilepath(paramstr(0));
end;procedure Tmainform.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*2,arow*21,acol*2,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 Tmainform.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
isblack:=false;
drawgrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21,(row+1)*21);
tag[col,row]:=1;
end else
begin
isblack:=true;
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
begin
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;
end.
我这个程序有点问题就是,当我五子一线的时候,非要对方再走一步才显示我赢了!
希望哪位可以修改一下?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids;type
Tmainform = class(TForm)
Panel1: TPanel;
DrawGrid1: TDrawGrid;
Timer1: TTimer;
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);
private
{ Private declarations }
tag:array[0..18,0..18] of integer;
isblack:boolean;
public
{ Public declarations }
maindir:string[80];
function iswin(isblack:boolean):boolean;
end;var
mainform: Tmainform;implementation{$R *.dfm}
function tmainform.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 Tmainform.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:=false;
maindir:=extractfilepath(paramstr(0));
end;procedure Tmainform.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*2,arow*21,acol*2,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 Tmainform.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
//isblack:=false; //没用可删
//drawgrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21,(row+1)*21); //没用可删
tag[col,row]:=1;
end
else
begin
//isblack:=true; //没用可删
//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
begin
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;
isblack:=not isblack; //移到新的位置
end;
end;
end.