关于文曲星上猜数字游戏的c编程方法
下面图老师小编要向大家介绍下关于文曲星上猜数字游戏的c编程方法,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!
!-- frame contents -- !-- /frame contents --
#includestdio.h
#includestdlib.h
#includetime.h
#includemath.h
#define SIZE 4
main()
{
int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra;
char ch;
srand(time(NULL));
while(enter==1)
{ stop=2;
while(stop==2)
{ extra=1;
for(i=0;i<=SIZE-1;i++)
a[i]=rand()%10;
for(i=0;i<=SIZE-1;i++)
{for(j=i+1;j<=SIZE-1;j++)
{ if(a[i]==a[j]) extra=2; }
}
if(a[0]!=0&&extra==1) {stop=1;printf("%d%d%d%d",a[0],a[1],a[2],a[3]);}
}
counter=1;
while(counter<=6)
{ printf("Please guess the number:");
scanf("%d",&guessnum);
for(i=0;i<=SIZE-1;i++)
b[i]=guessnum/(int)pow(10,SIZE-1-i)%10;
countera=0;
for(i=0;i<=SIZE-1;i++)
{ if(a[i]==b[i]) countera++;}
counter0=0;
for(i=0;i<=SIZE-1;i++)
{ for(j=0;j<=SIZE-1;j++)
{if(a[i]==b[j]) counter0++;}
}
counterb=(counter0-countera);
if(countera==4) {printf("Wonderful!You guessed the number.Then,please input your choice,'1' represents going on,'2' represents breaking");
counter=7;
scanf("%d",&enter);
}
else {printf("%dA%dB",countera,counterb);
counter++;
}
}
}
while((ch=getchar())!='s'&&ch!='S');
return 0;
}
更多内容请看Java编程开发手册 网络游戏攻略 游戏开发专题,或