论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > C语言程序设计教程
Tag:新手,函数,指针,数据类型,对象,Turbo,入门,运算符,数组,结构,二级,,tc,游戏,试题,问答,编译,视频教程

五子棋

文章类别:C语言程序设计 | 发表日期:2008-9-24 14:46:52

这只是五子棋的一个排列判定,只能输入坐标两人对仗. 缺少图象函数和鼠标函数;

请指点怎样才能让它选择重玩和鼠标函数的的写法 ,

请多多指教!!!

 

 

#include"stdio.h"
#include"math.h"         
#define NUM1 5   /*改变棋盘的宽 要大于4*/
#define NUM2 5   /*改变棋盘的长 要大于4*/
#define W 27    /*比NUM1*NUM2+1大的数*/
#define V 28    /*比NUM1*NUM2+2大的数  W不能等于V */
main()
{ static  int a[NUM1][NUM2],b[NUM1][NUM2],c[NUM1+1][NUM2+1];
                                   /*c数组比a,b大 第一横和列作为坐标 方便输入*/
  int x,y,i,j,m,n,f=1;
    int p=0;
int zuo_biaox=0,zuo_biaoy=0;

for(zuo_biaox=1;zuo_biaox<NUM1+1;zuo_biaox=zuo_biaox+1)
      c[0][zuo_biaox]=zuo_biaox-1;
for(zuo_biaoy=1;zuo_biaoy<NUM2+1;zuo_biaoy=zuo_biaoy+1)
      c[zuo_biaoy][0]=zuo_biaoy-1;

 

  for(p=0;p<=NUM1*NUM2;p=p+1)
   {int e=1;
    int m1=1,n1=1,t1=0,s1=0,flag1=0,flak1=0,z1=0;
    int m2=1,n2=1,t2=0,s2=0,flag2=0,flak2=0,z2=0;
    int m3=1,n3=1,t3=0,s3=0,flag3=0,flak3=0,z3=0;
    int m4=1,n4=1,t4=0,s4=0,flag4=0,flak4=0,z4=0;
    f=-f;
    if(f<0)
     printf("A: inputx&y:\n");
    if(f>0)
     printf("B: inputx&y:\n");
    scanf("%d %d", &x,&y );
    if((x>=NUM2)||(y>=NUM1))    /*坐标不能超过棋盘格数*/
     {f=-f;printf("the number is too big !\n");continue;}  
    if(c[y+1][x+1]!=0)              /*已下棋的坐标不能再输入*/
     {f=-f;printf("you can not put here!\n");continue;}
      i=x;
      j=y;
     if(f<0){c[j+1][i+1]=1,c[0][0]=1;}
     if(f>0){c[j+1][i+1]=2,c[0][0]=2;}
    
     if(f<0)                    /*判定a 数组*/
      {a[j][i]=1;
       for(e=1 ;e<=4;e=e+1)
       {switch(e)
        {case 1:               /*判定前后数值是否与自己相同*/
                 while ((m1<=5)&&(flag1==0))
                 {if(a[j][i+m1]/1==1)
                  {m1=m1+1, t1=t1+1,printf("t1=%d \n",t1);}
                  else flag1=1;
                 }
 
                  while ((n1<=5)&&(flak1==0))
                  {if(a[j][i-n1]/1==1)
                   {n1=n1+1,s1=s1+1,printf(" s1=%d \n",s1);}
                   else flak1=1;
                 }
                  z1=s1+t1+1;
                  if(z1>=5) {p=W ;e=10;}
                  break;
                  
          case 2:              /*判定上下数值是否与自己相同*/
                  while ((m1<=5)&&(flag2==0))
                  {if(a[j+m2][i]/1==1)
                   {m2=m2+1, t2=t2+1,printf("t2=%d \n",t2);}
                   else flag2=1;
                  }
 
                   while ((n2<=5)&&(flak2==0))
                   {if(a[j-n2][i]/1==1)
                    {n2=n2+1,s2=s2+1,printf(" s2=%d \n",s2);}
                     else flak2=1;
                  }
                    z2=s2+t2+1;
                    if(z2>=5)  {p=W ;e=10;}
                    break;
   
           case 3:              /*判定右倾斜数值是否与自己相同*/
                    while ((m3<=5)&&(flag3==0))
                    {if(a[j-m3][i+m3]/1==1)
                     {m3=m3+1, t3=t3+1,printf("t3=%d \n",t3);}
                     else flag3=1;
                    }
 
                    while ((n3<=5)&&(flak3==0))
                    {if(a[j+n3][i-n3]/1==1)
                     {n3=n3+1,s3=s3+1,printf(" s3=%d \n",s3);}
                     else flak3=1;
                    }
                     z3=s3+t3+1;
                     if(z3>=5)  {p=W; e=10;}
                     break;


            case 4:               /*判定右倾斜数值是否与自己相同*/
                    while ((m4<=5)&&(flag4==0))
                    {if(a[j-m4][i-m4]/1==1)
                     {m4=m4+1, t4=t4+1,printf("t4=%d \n",t4);}
                     else flag4=1;
                    }
 
                    while ((n4<=5)&&(flak4==0))
                    {if(a[j+n4][i+n4]/1==1)
                     {n4=n4+1,s4=s4+1,printf(" s4=%d \n",s4);}
                      else flak4=1;
                    }
                     z4=s4+t4+1;
                     if(z4>=5)  {p=W; e=10;}
                     break;
       } 
      }
     }
     if(f>0) /*判定b 数组*/
      {b[j][i]=2;
        for(e=1 ;e<=4;e=e+1)
        {switch(e)
         {case 1:                 /*判定前后数值是否与自己相同*/
                  while ((m1<=5)&&(flag1==0))
                  {if(b[j][i+m1]/2==1)
                   {m1=m1+1, t1=t1+1,printf("t1=%d \n",t1);}
                   else flag1=1;
                  }
 
                  while ((n1<=5)&&(flak1==0))
                  {if(b[j][i-n1]/2==1)
                   {n1=n1+1,s1=s1+1,printf(" s1=%d \n",s1);}
                   else flak1=1;
                  }
                  z1=s1+t1+1;
                  if(z1>=5)  {p=V; e=10;}
                  break;
                   
           case 2:                  /*判定上下数值是否与自己相同*/
                   while ((m1<=5)&&(flag2==0))
                   {if(b[j+m2][i]/2==1)
                    {m2=m2+1, t2=t2+1,printf("t2=%d \n",t2);}
                     else flag2=1;
                   }
 
                   while ((n2<=5)&&(flak2==0))
                   {if(b[j-n2][i]/2==1)
                    {n2=n2+1,s2=s2+1,printf(" s2=%d \n",s2);}
                    else flak2=1;
                   }
                   z2=s2+t2+1;
                   if(z2>=5)  {p=V; e=10;}
                   break;
   
            case 3:                 /*判定右倾斜数值是否与自己相同*/
                    while ((m3<=5)&&(flag3==0))
                    {if(b[j-m3][i+m3]/2==1)
                     {m3=m3+1, t3=t3+1,printf("t3=%d \n",t3);}
                     else flag3=1;
                    }
 
                    while ((n3<=5)&&(flak3==0))
                    {if(b[j+n3][i-n3]/2==1)
                     {n3=n3+1,s3=s3+1,printf(" s3=%d \n",s3);}
                     else flak3=1;
                    }
                    z3=s3+t3+1;
                    if(z3>=5) {p=V; e=10;}
                    break;


            case 4:                 /*判定右倾斜数值是否与自己相同*/
                    while ((m4<=5)&&(flag4==0))
                    {if(b[j-m4][i-m4]/2==1)
                     {m4=m4+1, t4=t4+1,printf("t4=%d \n",t4);}
                     else flag4=1;
                    }
 
                    while ((n4<=5)&&(flak4==0))
                    {if(b[j+n4][i+n4]/2==1)
                     {n4=n4+1,s4=s4+1,printf(" s4=%d \n",s4);}
                     else flak4=1;
                    }
                    z4=s4+t4+1;
                    if(z4>=5)  {p=V; e=10;}
                    break;
       }  /*switch*/
      }   /*for s*/
     } 
       for(m=0;m<NUM1+1;m=m+1)
       {printf("\n");
         for(n=0;n<NUM2+1;n=n+1)printf("%d ",c[m][n]);}
              printf("\n");

 

    if(p>=NUM1*NUM2+1) break;
   }
       for(m=0;m<NUM1+1;m=m+1)
       {printf("\n");
         for(n=0;n<NUM2+1;n=n+1)printf("%d ",c[m][n]);
              printf("\n");}

         printf("p=%d\n",p);
         if(p==W) printf("The winner is A!\n");
         if(p==V) printf("The winner is B!\n");
         if(p==NUM1*NUM2+1) printf("Noone win!");
 }   
      

上一篇:{应用}俄罗斯方块大全 人气:5201
下一篇:{应用}DOS游戏编程21条 人气:6399
视频教程列表
文章教程搜索
 
C语言程序设计推荐教程
C语言程序设计热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058