西蒙游戏代码

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<stdbool.h>
#include<time.h>

int main()
{
unsigned int score_c = 0;
unsigned int zuichang = 0;
const unsigned int s = 10;
unsigned int x = 0;
clock_t start_time = 0;
clock_t kaishi_t = 0;
time_t seed = 0;
char answer = 0;
unsigned int deley = 1;
bool correct = 1;
unsigned int tries = 0;
unsigned int digits = 2;
unsigned int zuihou_g = 0;
unsigned int shuzi_t = 0;
unsigned int xianshi_t = 0;
unsigned int biaozhun_t = 0;
unsigned int youxi_t = 0;
unsigned int score2 = 0;
char y = 0;
printf(“你好姚文旭!这是西蒙游戏!\n”);
printf(“输入你看到的数字,数字之间要加空格哦!\n”);
printf(“数字越多,时间越短,得分越高!\n”);
printf(“请输入Enter键开始!\n”);
scanf("%c", &y);
while (y == 10)
{
do {//开始游戏
deley = 1;//初始化游戏
correct = 1;
tries = 0;
digits = 2;
kaishi_t = clock();
while (correct)//初始化游戏后,开始游戏
{
++tries;
srand(time(&seed));
if (tries == 1)
printf(“输入你看到的数字:\n”);
for (int i = 1; i <= digits; ++i)
printf("%d “, rand() % 10);
start_time = clock();//数字出来时的时间
for (; clock() - start_time < deley * CLOCKS_PER_SEC;)
printf(”\r");
for (int i = 1; i <= digits; ++i)
printf(" “);//数字出来到消失deley秒
printf(”\r");
srand(seed);
for (int i = 1; i <= digits; ++i)
{
scanf("%d", &x);
if (x != rand() % 10)
correct = 0;
}
printf("%s\n", correct ? “correct” : “wrong”);
if (correct == 1 && tries % 3 == 0)
++digits;
}
//下面要计算分数
//先计算最长数字,最长数字每个s分
zuichang = (tries % 3 == 1 ? digits - 1 : digits);
if (zuichang == 1)zuichang = 0;
score_c = zuichang * s;
//下面计算时间分数
//先计算标准时间,标准时间是:玩家每输入一个数字需要1秒,加上每组digits显示的时间
//玩家输入数字的时间
if (tries % 3 != 0)
zuihou_g = digits * (tries % 3) + (tries / 3)((digits - 1)(digits - 2) / 2 - 1);
else
if (digits == 2)
zuihou_g = 6;
else
zuihou_g = (tries / 3)*((digits - 1)*digits / 2 - 1 + digits);
//输入数字的时间
shuzi_t = zuihou_g * 1;/总次数乘以1秒/
//计算显示数字的时间
xianshi_t = tries * deley;
//标准时间
biaozhun_t = xianshi_t + shuzi_t;
//计算玩家游戏时间
youxi_t = (clock() - kaishi_t) / CLOCKS_PER_SEC;
score2 = youxi_t * s;
if (youxi_t < biaozhun_t)
score2 = (biaozhun_t - youxi_t)*s;
printf(“你的时间是%d秒,分数是%d\n%s”, youxi_t, score_c + score2, score_c + score2
> 300 ? “姚文旭你太棒了!” : “不到300,姚文旭继续加油!\n”);
getchar();
fflush(stdin);
printf(“要继续玩吗?n/y\n”);
scanf("%c", &answer);
printf("\n");
} while (tolower(answer) == ‘y’);
if (answer != ‘y’)
break;
}
system(“pause”);
return 0;
}

发布了21 篇原创文章 · 获赞 0 · 访问量 374

猜你喜欢

转载自blog.csdn.net/gaoxingzhe/article/details/104299189