unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, ExtCtrls, StdCtrls,comCtrls,ScktComp,Menus;type
  TForm1 = class(TForm)
    Panel1: TPanel;
    DrawGrid1: TDrawGrid;
    Label1: TLabel;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
    yy : array[0..18,0..18] of integer;     {0 表示没有 1表示黑棋, 2表示白棋}
    ISback :boolean;
  public
    { Public declarations }
    function IsYin(IsBack : boolean) :Boolean; {判断是否赢棋}  end;var
  Form1: TForm1;implementation{$R *.dfm} {判断是否赢棋}
function Tform1.IsYin(IsBack : boolean) : Boolean;var
i,j : integer;
wtag: integer;
label exit1;
  begin
      IsYin := false;
      if IsBack then
          wtag:=1 else
          wtag:=2;
          for i :=0 to 18 do    //是否有行连成
              for j:=0 to 14 do
                  begin
                      if (i<15) and (yy[i,j]=wtag)
                                and (yy[i+1,j]=wtag)
                                and (yy[i+2,j]=wtag)
                                and (yy[i+3,j]=wtag)
                                and (yy[i+4,j]=wtag) then
                          begin
                                IsYin := true;
                                 Goto  exit1;                          end;
                      if (yy[i,j]=wtag)   //是否有列连成
                               and  (yy[i,j]=wtag)
                               and (yy[i+1,j]=wtag)
                               and (yy[i+2,j]=wtag)
                               and (yy[i+3,j]=wtag)
                               and (yy[i+4,j]=wtag) then
                          begin
                              IsYin :=true;
                              goto exit1;
                          end;                       if (i<15) and (yy[i,j]=wtag)
                                and (yy[i+1,j+1]=wtag)
                                and (yy[i+2,j+2]=wtag)
                                and (yy[i+3,j+3]=wtag)
                                and (yy[i+4,j+4]=wtag) then
                          begin
                              IsYin :=true;
                              goto exit1;
                          end;                        if  (yy[i,j]=wtag)
                                and (yy[i-1,j+1]=wtag)
                                and (yy[i-2,j+2]=wtag)
                                and (yy[i-3,j+3]=wtag)
                                and (yy[i-4,j+4]=wtag) then
                          begin
                              IsYin :=true;
                              goto exit1;
                          end;
                  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
                  yy[i,j] :=0;
            end;
            ISback :=true;
            DrawGrid1.Canvas.Pen.Color := clBlack;
            DrawGrid1.Canvas.Brush.Color:=clBlack;
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 yy[col,row] =0 then
     begin
          if IsBack then
              begin
                  DRAWgrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21, (row+1)*21 );
                  yy[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 );
                  yy[col,row] := 2;
              end ;
          if ISyIN(isBack) THEN
             Begin
                if ISbACK THEN
                 IF messageDLG('黑方胜利',mtInformation,[mbOK],0) =mrOK then
                     begin
                          for i:=0 to 18 do
                            for j:=0 to 18 do
                               begin
                                  yy[i,j]:=0;
                               end;
                               DrawGrid1.Invalidate;
                     end;
             end;         if not ISback then
                 IF messageDLG('白方胜利',mtInformation,[mbOK],0) =mrOK then
                     begin
                          for i:=0 to 18 do
                            for j:=0 to 18 do
                               begin
                                  yy[i,j]:=0;
                               end;
                               DrawGrid1.Invalidate;
                     end;     end;
       isBACK := NOT isBack;
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 yy[acol,arow] =1 then
      DrawGrid1.Canvas.Ellipse( acol*21,arow*21,(acol+1)*21, (arow+1)*21)
   else if yy[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;end.有点小问题,希望高手指点

解决方案 »

  1.   

    还用goto,好像是什么delphi教程里的垃圾代码,重写一个好了
      

  2.   

    偶尔用goto也不错的:),不过代码太长了,谁也没有功夫看,把有问题的地方指出来呀
      

  3.   

    用goto很正常啊
    Linux内核的C代码用了大量的goto
    可能是内核的缘故,一切为速度考虑吧
      

  4.   

    var 
    i,j : integer; 
    wtag: integer; 
    label exit1;
    begin      IsYin := false;
          if IsBack then
              wtag:=1 else 
              wtag:=2; 
              for i :=0 to 18 do    //是否有行连成 
                  for j:=0 to 14 do 
                      begin 
                          if (i <15) and (yy[i,j]=wtag) 
                                    and (yy[i+1,j]=wtag) 
                                    and (yy[i+2,j]=wtag) 
                                    and (yy[i+3,j]=wtag) 
                                    and (yy[i+4,j]=wtag) then 
                              begin 
                                    IsYin := true; 
                                    Goto  exit1;                           end; 
                          if (yy[i,j]=wtag)  //是否有列连成 
                                  and  (yy[i,j]=wtag) 
                                  and (yy[i+1,j]=wtag) 
                                  and (yy[i+2,j]=wtag) 
                                  and (yy[i+3,j]=wtag) 
                                  and (yy[i+4,j]=wtag) then 
                              begin 
                                  IsYin :=true; 
                                  goto exit1; 
                              end;                       if (i <15) and (yy[i,j]=wtag) 
                                    and (yy[i+1,j+1]=wtag) 
                                    and (yy[i+2,j+2]=wtag) 
                                    and (yy[i+3,j+3]=wtag)
                                    and (yy[i+4,j+4]=wtag) then
                              begin
                                  IsYin :=true;
                                  goto exit1;
                              end;                        if  (yy[i,j]=wtag)
                                    and (yy[i-1,j+1]=wtag)
                                    and (yy[i-2,j+2]=wtag)
                                    and (yy[i-3,j+3]=wtag)
                                    and (yy[i-4,j+4]=wtag) then
                              begin
                                  IsYin :=true;
                                  goto exit1;
                              end;
                      end;
      exit1 : Exit ;
    end;
      

  5.   

    我是来操 tjianliang(亮剑)这个垃圾全家女人的。干他全家女人后卖到泰国做人妖。
    祝这个小杂种不得好死:一看就是狗日出来的。///////////////////////
    灌水机自动所发。无须回复