這只是五子棋的一個排列判定,只能輸入坐標兩人對仗. 缺少圖象函數和鼠標函數; 請指點怎樣才能讓它選擇重玩和鼠標函數的的寫法 , 請多多指教!!! #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: ");
if(f>0)
printf("B: inputx&y: ");
scanf("%d %d", &x,&y );
if((x>=NUM2)(y>=NUM1)) /*坐標不能超過棋盤格數*/
{f=-f;printf("the number is too big ! ");continue;}
if(c[y+1][x+1]!=0) /*已下棋的坐標不能再輸入*/
{f=-f;printf("you can not put here! ");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 ",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 ",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 ",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 ",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 ",t3);}
else flag3=1;
}