| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 910 人关注过本帖
标题:请各路高手前辈修改我的五子棋代码!!!
只看楼主 加入收藏
天梦幻羽
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-4-30
收藏
 问题点数:0 回复次数:0 
请各路高手前辈修改我的五子棋代码!!!
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
    { Private declarations }
    Tag:array[0..18,0..18]of integer;
    {0表示没有,1表示黑棋,2表示白棋}
    IsBlack:boolean;
  public
    { Public declarations }
    function IsWin(IsBlack:boolean):boolean://判断是否赢棋
  end;

var
  mainform: Tmainform;

implementation

{$R *.dfm}
function Tmainform.IsWin(IsBlack:boolean):boolean;
tabel 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:=0n to 18 do
    begin
      Tag[i,j]:=0;
    end;
  IsBlack:=true;'
  DrawGrid1.Canvas.Pen.Color:=clBlack;
  DrawGrid1.Canvas.Brush.Color:=clBlack;
  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*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 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
           DrawGrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21,(row+1)*21);
           tag[col,row]:=2;
        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;
           Drawagrid1.Invalidate;
         end;
      end;
      IsBlack:=not IsBlackend;
   end;
end;
end.
搜索更多相关主题的帖子: 五子棋 前辈 代码 
2008-05-07 13:34
快速回复:请各路高手前辈修改我的五子棋代码!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016742 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved