我想用delphi写一个五子棋游戏,现在第一步画棋盘就遇到了麻烦,不知道哪位高手能指点一二或者给点参考资料,现在比较穷困,只能给20分了,结贴一定再补

解决方案 »

  1.   

    http://www.somade.com/是个很专业的技术社区,去那里找找吧,或许有你要的答案~
      

  2.   

    http://www.somade.com/
    该站点刚刚去过,去了才知道垃圾阿
      

  3.   

    unit main;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;
       end;
    end;
    end.
    我这个程序有点问题就是,当我五子一线的时候,非要对方再走一步才显示我赢了!
    希望哪位可以修改一下?
      

  4.   

    程序格式乱的一塌糊涂。
    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.