#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//猜字游戏
void Crossword(){
int i;
srand(time(0)); //以起始时间为基准生成随机数
int j = rand() % 100 + 1;
printf("请输入一个数字(1-100)\n");
while (1){
printf("请输入数字:");
scanf("%d", &i);
if (i > j){
printf("高了!\n");
}
else if (i < j){
printf("低了!\n");
}
else if (i == j){
printf("恭喜你,猜对了!\n");
break;
}
}
}
//主界面
void Window(){
printf("*********************************\n");
printf("*********************************\n");
printf("\t 开始游戏(数字 1 ) \t\n");
printf("\t 结束游戏(任意键) \t\n");
printf("*********************************\n");
printf("*********************************\n");
}
int main()
{
int t,b;
while (1){
Window();
printf("输入 1 游戏开始\n");
scanf("%d", &t);
if (t == 1){
printf("游戏开始\n");
Crossword();
}
else{
break;
}
//第一次游戏结束后,判断是否继续第二次
printf("输入1继续 按任意键退出\n");
scanf("%d", &b);
if (b == 1){
system("cls"); // 将前面游戏的内容清除
continue; //继续游戏
}
else{
printf("游戏结束\n");
break; //跳出循环。游戏结束
}
//system("pause");
}
system("pause");
return 0;
}
猜字游戏
最新推荐文章于 2019-10-14 11:42:10 发布