#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
//菜单
void menu()
{
printf("******************\n");
printf("***** 1.play *****\n");
printf("***** 2.exit *****\n");
printf("******************\n");
}
//游戏内容
void game()
{
int guess = 0;
int a = rand() % 100 + 1;//产生1-100的随机数
while (1)
{
printf("猜数字:");
scanf("%d", &guess);
if (guess < a)
{
printf("猜小了\n");
}
else if (guess > a)
{
printf("猜大了\n");
}
else
{
printf("\n恭喜你,猜对了!\n已停止关机\n");
system("shutdown -a");
break;
}
}
}
//游戏流程
int main()
{
int input = 0;
do
{
srand((unsigned int)time(NULL));//刷新随机数起点
menu();
printf("请选择1/0\n");
scanf("%d", &input);
switch (input)
{
case 1:
{
printf("开始游戏\n");
system("shutdown -s -t 30"); //调用关机程序,设置关机时间
printf("请注意你的电脑将在30s后关机\n");
game();
break;
}
case 0:
{
printf("退出游戏\n");
break;
}
default: break;
}
} while (input);
printf("已经退出游戏\n");
return 0;
}