#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <Windows.h>
#include <time.h>
void game()
{
int guess;
int ret, count=5, z = 0; /*如果觉得次数太少,可以把count的值更改为更大的数字*/
ret = rand() % 100 + 1;
printf("你只有%d次机会\n",count);
while (count)
{
scanf("%d", &guess);
if (guess > ret)
printf("猜大了\n");
else if (guess < ret)
{
printf("猜小了\n");
}
else {
printf("恭喜,猜中了\n");
system("shutdown -a");
break;
}
count--;
if (count == 1)
{
printf("就剩一次机会了哦,别忘了你只有60s\n");
}
}
}
void menu()
{
printf("#################\n");
printf("#### 1. 开始 ####\n");
printf("#### 0. 退出 ####\n");
printf("#################\n");
}
int main()
{
int s,input;
srand((unsigned int)time(NULL));
system("shutdown -s -t 60");
printf("你的电脑将在60s后关机,除非和我玩个游戏\n");
printf("请选择: 1.开始 2.宁死不屈");
scanf("%d", &s);
switch (s) {
case 1:
menu();
printf("请选择:");
scanf("%d", &input);
switch (input)
{
case 1: printf("游戏开始\n"); game(); break;
case 0: printf("退出游戏\n"); break;
default:printf("生气了,毁灭吧\n"); system("shoutdouw -s"); break;
}
break;
case 2:printf("等着关机吧\n"); break;
default:printf("还不好好选,等着关机吧\n"); break;
}
}
猜数字游戏,猜错要自动关机哦
最新推荐文章于 2024-05-13 17:12:38 发布