simple simon游戏 出问题了。。
我写了个 simple simon游戏,就是让计算机先显示一个三位数,然后等一秒后删除它,让用户输入,如果正确就继续。如果连续三次正确,就增加一位(变成显示四位数),整个程序就差一步了,就是无论我输入什么,都显示wrong。
百思不得其解呀!!!!
大家帮我看一下(setbuf是linux中清除缓冲区的函数)
程序代码:#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
char wu; //没实际作用,就是为了输入回车再开始游戏
int right,another_game,cishu,shu,truee,fang; //right判断玩家输入正误
int turn,len,start_time; //回合数和数字长度和开始显示数字的时间
int number[30],player[30];
do //外面的循环负责游戏的初始化和判断是否重新开始游戏
{
right;
turn=0;
len=3;
srand(time(NULL)); //生成随机数的种子数
printf("欢迎玩simple simon\n你要记住一闪而过的数字\n而且难度会"
"越来越大\n按回车键开始(首次玩需按两回)\n");
getchar();
scanf("%c",&wu);
do
{
turn++;
for(int i=0;i<len;i++)
number[i]=rand()%10; //store the true number
for(int i=0,truee=0;i<len;i++)//这个for用来把number里面的生成的
{ //数存到truee这个变量中
fang=1;
for(int j=1;j<=len-1-i;j++)
fang*=10;
truee+=number[i]*fang;
}
setbuf(stdout,NULL); //清空缓冲区
for(int i=0;i<len;i++)
printf("%d",number[i]);
start_time=clock();
while(clock()-start_time<CLOCKS_PER_SEC);
setbuf(stdout,NULL);
for(int i=1;i<=len;i++)
printf("\b");
setbuf(stdout,NULL);
for(int i=1;i<=len;i++)
printf(" ");
printf("该你输入啦\n");
setbuf(stdin,NULL);
scanf("%d",&shu); //保存玩家的输入
if(shu==truee)
right=1;
else
right=0;
if(turn%3==0)
len++;
if(right)
printf("right!!!\n");
else
printf("wrong!!!\n");
}while(right);
printf("重新开始吗?('Y' OR 'N')\n");
setbuf(stdin,NULL);
if(tolower(getchar())=='y')
another_game=1;
else
another_game=0;
}
while(another_game);
}



