#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
int main()
{
char input = 'y';
int limit = 2;
long long getNum = 0LL;
long long showNum;
int i;
clock_t now;
int score = 0;
srand(time(NULL));
do
{
showNum = 0LL;
//输出字符串
for (i=0;i<limit;i++)
{
if(i==0)
{
showNum = 10*showNum + 1 + rand()%9;
}
else
{
showNum = 10*showNum + rand()%10;
}
}
printf("%lld",showNum);
//等待1秒后消除
now = clock();
for (; (clock()-now) < (CLOCKS_PER_SEC*2) ;)
printf("\r");
for(i=0;i<limit;i++)
{
printf(" ");
}
printf("\r");
//接受用户输入并判断
printf("请重复输入之前的数字:\n");
scanf("%lld",&getNum);
if (showNum == getNum)
{
printf("正确.\n");
score += 10*limit;
limit++;
input = 'y';
}
else
{
printf("错误,游戏结束.\n");
printf("总得分:%d\n",score);
limit = 2;
score = 0;
fflush(stdin);
printf("是否继续(y/n):\n");
scanf("%c",&input);
}
}
while(tolower(input)=='y');
}
猜数字小游戏
最新推荐文章于 2024-05-11 15:14:02 发布