大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 五子棋源代码

五子棋源代码

时间: 2021-07-31 作者:daque

unit main;  interface  uses   windows, messages, sysutils, classes, controls, forms, dialogs,   extctrls, stdctrls, comctrls, buttons, graphics, mmsystem;  type   tform1 = class(tform)    statusbar1: tstatusbar;    groupbox1: tgroupbox;    groupbox2: tgroupbox;    panel1: tpanel;    label1: tlabel;    bitbtn1: tbitbtn;    bitbtn2: tbitbtn;    label3: tlabel;    label4: tlabel;    bitbtn3: tbitbtn;    image1: timage;    image2: timage;    label5: tlabel;    label2: tlabel;    label6: tlabel;    label7: tlabel;    label8: tlabel;    label9: tlabel;    label10: tlabel;    timer1: ttimer;    label11: tlabel;    procedure bitbtn2click(sender: tobject);    procedure bitbtn1click(sender: tobject);    procedure image2mousedown(sender: tobject; button: tmousebutton;     shift: tshiftstate; x, y: integer);    procedure formcreate(sender: tobject);    procedure bitbtn3click(sender: tobject);    procedure timer1timer(sender: tobject);    procedure label11mousedown(sender: tobject; button: tmousebutton;     shift: tshiftstate; x, y: integer);   private    { private declarations }   public    { public declarations }   end;   fivechess_struct=record       x1 : integer;       y1 : integer;       x2 : integer;       y2 : integer;       state : byte;   end;   fivechess_data=array [0..14,0..14] of fivechess_struct;   player = ( non,white,black);  var   form1: tform1;   start_flag : boolean;   fivechess_array:fivechess_data ;   online: player;   whitewin,blackwin:byte;   whitetime,blacktime:integer;   px1,px2,py1,py2 : integer;   undo_i,undo_j : integer;  function ini_main():boolean ;  implementation  uses option;  {$r *.dfm}  //{$r aoe.res}  procedure ini_fivechess_array();  var    i , j,k: integer;  begin     for i:=0 to 14 do begin       for j:=0 to 14 do begin         fivechess_array[i,j].x1:=16+25*j;         fivechess_array[i,j].y1:=16+25*i;         fivechess_array[i,j].x2:=36+25*j;         fivechess_array[i,j].y2:=36+25*i;         fivechess_array[i,j].state:=0;         end;      end;  end;  procedure draw_qipan();  var     i,j : integer;  begin     form1.image2.canvas.brush.color:=rgb(247,207,16);     form1.image2.canvas.fillrect(rect(0,0,400,400));     form1.image2.canvas.pen.color:=rgb(0,0,0);     for i:=1 to 16 do begin       form1.image2.canvas.moveto(0,25*i);       form1.image2.canvas.lineto (400,25*i);       form1.image2.canvas.moveto(25*i,0);       form1.image2.canvas.lineto (25*i,400);     end;  end;  procedure undo_run();  var     x1,x2,y1,y2 : integer;  begin     if (undo_i<>-1) and (undo_j<>-1) then  begin       fivechess_array[undo_i,undo_j].state :=0;       x1:= fivechess_array[undo_i,undo_j].x1-2;       y1:= fivechess_array[undo_i,undo_j].y1-2;       x2:= fivechess_array[undo_i,undo_j].x2+2;       y2:= fivechess_array[undo_i,undo_j].y2+2;       form1.image2.canvas.brush.color:=rgb(247,207,16);       form1.image2.canvas.fillrect(rect(x1,y1,x2,y2));       form1.image2.canvas.pen.color:=rgb(0,0,0);       form1.image2.canvas.moveto((x1+x2)div 2-1 , y1);       form1.image2.canvas.lineto((x1+x2)div 2-1 , y2);       form1.image2.canvas.moveto(x1,(y1+y2)div 2-1);       form1.image2.canvas.lineto(x2,(y1+y2)div 2-1);       end;     if online=black then       online:=white     else       online:=black;    end;  function ini_main():boolean ;  begin     result:=true;     px1:=0;     px2:=0;     py1:=0;     py2:=0;     undo_i:=-1;     undo_j:=-1;     whitetime:=0;     blacktime:=0;     form1.label9.caption :=inttostr(whitewin);     form1.label10.caption :=inttostr(blackwin);     ini_fivechess_array;     draw_qipan;  end;  function judge_success_on_off (x,y,state:integer):boolean;  var     i,j,k,count : integer;  begin     count:=0;     result:=false;     // 确定竖列     for i:=x-4 to x+4 do       if (i>=0) and (i<=15) then       begin          if fivechess_array[i,y].state=state then            begin              inc(count) ;              if count=5 then begin                result:=true;                break;                end;            end          else            count:=0;       end;    //确定横行    count:=0;    for j:=y-4 to y+4 do      if (j>=0) and (j<=15) then       begin          if fivechess_array[x,j].state=state then            begin              inc(count) ;              if count=5 then begin                result:=true;                break;                end;            end          else            count:=0;       end;    //确定'\'目标    count:=0;    for k:=-4 to 4 do begin        i:=x+k;        j:=y+k;        if (j>=0) and (j<=15) and(i>=0) and(i<=15) then         begin          if fivechess_array[i,j].state=state then            begin              inc(count) ;              if count=5 then begin                result:=true;                break;                end;            end          else            count:=0;       end;    end;   //确定'/'目标    count:=0;    for k:=-4 to 4 do begin        i:=x+k;        j:=y-k;        if (j>=0) and (j<=15) and(i>=0) and(i<=15) then         begin          if fivechess_array[i,j].state=state then            begin              inc(count) ;              if count=5 then begin                result:=true;                break;                end;            end          else            count:=0;       end;    end; end; procedure tform1.bitbtn2click(sender: tobject); begin    application.terminate ; end; procedure tform1.bitbtn1click(sender: tobject); begin    start_flag:=true;    if start_flag then begin     form1.image2.enabled := true;     form1.timer1.enabled := true;     ini_main;    end; end; function draw_qizi_white(x,y : integer):boolean; var    i,j,x1,x2,y1,y2 : integer; begin    result := false;    for i:=0 to 14 do      for j:=0 to 14 do begin        if (x> fivechess_array[i,j].x1)and(x<fivechess_array[i,j].x2)       and (y> fivechess_array[i,j].y1)and(y<fivechess_array[i,j].y2)       and (fivechess_array[i,j].state=0)  then       begin          if fivechess_array[undo_i,undo_j].state<>0 then begin            form1.image2.canvas.brush.color:=rgb(100,100,100);            form1.image2.canvas.fillrect (rect(px1,py1,px2,py2));           end;           form1.image2.canvas.brush.color:=rgb(255,255,255);           form1.image2.canvas.ellipse ( fivechess_array[i,j].x1,           fivechess_array[i,j].y1,fivechess_array[i,j].x2,fivechess_array[i,j].y2);           form1.image2.canvas.brush.color:=rgb(255,255,255);           form1.image2.canvas.ellipse ( fivechess_array[i,j].x1-2,           fivechess_array[i,j].y1-2,fivechess_array[i,j].x2-2,fivechess_array[i,j].y2-2);           fivechess_array[i,j].state:=1;           undo_i:=i;           undo_j:=j;           form1.image2.canvas.brush.color:=clred;           px1:= fivechess_array[i,j].x1+3;           py1:= fivechess_array[i,j].y1+3;           px2:= fivechess_array[i,j].x2-7;           py2:= fivechess_array[i,j].y2-7;           form1.image2.canvas.ellipse (px1,py1,px2,py2);           if judge_success_on_off(i,j, fivechess_array[i,j].state) then            begin               whitewin:=whitewin+1;               if whitewin>1 then                application.messagebox ('臭棋篓!比鱼头还臭!','胜负乃兵家常事',0)               else                application.messagebox ('白方已成功!','胜负乃兵家常事',0);               form1.label9.caption:=inttostr(whitewin);               form1.image2.enabled :=false;               form1.timer1.enabled := false;            end;           result := true;           break;        end;     end;  end;  function draw_qizi_black(x,y : integer): boolean;  var     i,j,x1,x2,y1,y2 : integer;  begin     result:=false;     for i:=0 to 14 do       for j:=0 to 14 do begin         if (x> fivechess_array[i,j].x1)and(x<fivechess_array[i,j].x2)          and (y> fivechess_array[i,j].y1)and(y<fivechess_array[i,j].y2)          and (fivechess_array[i,j].state=0)  then          begin            if fivechess_array[undo_i,undo_j].state<>0 then begin               form1.image2.canvas.brush.color:=rgb(255,255,255);               form1.image2.canvas.fillrect (rect(px1,py1,px2,py2));             end;             form1.image2.canvas.brush.color:=rgb(0,0,0);             form1.image2.canvas.ellipse ( fivechess_array[i,j].x1,                fivechess_array[i,j].y1,fivechess_array[i,j].x2,fivechess_array[i,j].y2);             form1.image2.canvas.brush.color:=rgb(100,100,100);             form1.image2.canvas.ellipse ( fivechess_array[i,j].x1-2,             fivechess_array[i,j].y1-2,fivechess_array[i,j].x2-2,fivechess_array[i,j].y2-2);             fivechess_array[i,j].state := 2;             undo_i:=i;             undo_j:=j;             form1.image2.canvas.brush.color:=clred;             px1:= fivechess_array[i,j].x1+3;             py1:= fivechess_array[i,j].y1+3;             px2:= fivechess_array[i,j].x2-7;             py2:= fivechess_array[i,j].y2-7;             form1.image2.canvas.ellipse (px1,py1,px2,py2);             if judge_success_on_off(i,j, fivechess_array[i,j].state) then              begin                 blackwin:=blackwin+1;                 if blackwin>1 then                  application.messagebox ('不会吧!莫非比鱼头还臭!','胜负乃兵家常事',0)                 else                  application.messagebox ('黑方已成功!','胜负乃兵家常事',0);                 form1.label10.caption:=inttostr(blackwin);                 form1.image2.enabled :=false;                 form1.timer1.enabled := false;              end;             result:=true;             break;           end;     end;  end;  procedure tform1.image2mousedown(sender: tobject; button: tmousebutton;   shift: tshiftstate; x, y: integer);  begin       if online = white then  begin        if draw_qizi_white(x,y) then          online := black        end       else          if draw_qizi_black(x,y) then           online:=white;  end;  procedure tform1.formcreate(sender: tobject);  begin     online:=white;     form1.label11.caption :='人不到遍体鳞伤'#13+'就不会领会懊悔!';     start_flag:=false;     form1.image2.enabled := false;       end;  procedure tform1.bitbtn3click(sender: tobject);  begin      form2.show;  end;  procedure tform1.timer1timer(sender: tobject);  begin     if online=white then       whitetime:=whitetime +1     else       blacktime:=blacktime +1;     form1.label7.caption:=inttostr(whitetime);     form1.label8.caption:=inttostr(blacktime);  end;  procedure tform1.label11mousedown(sender: tobject; button: tmousebutton;   shift: tshiftstate; x, y: integer);  begin     if (button = mbleft) and (ssshift in shift) and (form1.image2.enabled = true)then       undo_run;     end;  end.  end;  //////////////////////////  unit option;  interface  uses   windows, messages, sysutils, classes, graphics, controls, forms, dialogs,   stdctrls, buttons;  type   tform2 = class(tform)    groupbox1: tgroupbox;    radiobutton1: tradiobutton;    radiobutton2: tradiobutton;    bitbtn1: tbitbtn;    bitbtn2: tbitbtn;    groupbox2: tgroupbox;    radiobutton3: tradiobutton;    radiobutton4: tradiobutton;    radiobutton5: tradiobutton;    procedure formcreate(sender: tobject);    procedure bitbtn1click(sender: tobject);    procedure bitbtn2click(sender: tobject);   private    { private declarations }   public    { public declarations }   end;  var   form2: tform2;  implementation  uses     main;  {$r *.dfm}  procedure tform2.formcreate(sender: tobject);  begin      form2.radiobutton1.checked := true;      form2.radiobutton3.checked := true;  end;  procedure tform2.bitbtn1click(sender: tobject);  begin     if form2.radiobutton1.checked = true then       online := white     else       online := black;     if  form2.radiobutton3.checked then        begin           whitewin:=0;           blackwin:=0;        end ;     ini_main;     form2.close;  end;  procedure tform2.bitbtn2click(sender: tobject);  begin     form2.close ;  end;  end.

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.