#include <stdio.h>
#pragma warning (disable:4996)
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#define USERNAME "wang"
#define PASSWORD "1234"
#define NUM 32
void play()
{
int gass = 0;
int i = rand() % 100;
while (1)
{
printf("请在1到100输入你猜的值:\n");
scanf("%d", &gass);
if (gass > i)
{
printf("猜的大了");
}
else if (gass < i)
{
printf("猜小了");
}
else {
printf("猜对了");
break;
}
}
}
void meun()
{
printf("#############################\n");
printf("#############################\n");
printf("## 猜字谜游戏欢迎你 ##\n");
printf("#############################\n");
printf("#############################\n");
printf("##1.play 2.exit##\n");
printf("#############################\n");
printf("###please choice: ###\n");
printf("#############################\n");
}
void Suozi(int k)
{
for (; k >= 0; k--)
{
printf("输入错误次数太多请等候:%2d\r", k);
Sleep(1000);
}
}
void Lock(int lock)
{
switch (lock)
{
case 1: Suozi(5);
break;
case 2: Suozi(10);
break;
case 3: Suozi(20);
default :
break;
}
}
int login()
{
int count = 0;
int lock = 0;
char username[NUM];//定义数组数组大小和后面的内容不能全省略。
char password[NUM];
do {
username[0] = '\0';//清空数组里的内容,字符串以\0结束。
password[0] = '\0';
printf("请输入你的用户名\n");
scanf("%s", username);
printf("请输入你的密码\n");
scanf("%s", password);
if (0 == (strcmp(username, USERNAME) && strcmp(password, PASSWORD)))//字符串的比较不能用
//直接用操作符进行比较,要用函数strcmp(数组,数组) 相等返回0;
{
return 1;
}
else {
count++;
printf("输入有误,重新输入\n");
if (count == 3)
{
lock++;
if (lock > 3)
{
return 0;
}
Lock(lock);
count = 0;
}
}
} while (1);
}
int main()
{
int select = 0;
srand((unsigned)time(NULL));
int ret =login();
if (ret)
{
printf("欢迎你");
while (1) {
meun();
printf("输入你的选择:\n");
scanf("%d", &select);
switch (select)
{
case 1:
play();
break;
case 2:
break;
}
}
}
else {
printf("给你的机会太多了,没机会了");
}
return 0;
}
猜字谜游戏加登录和登录出错惩罚
最新推荐文章于 2024-05-21 20:56:54 发布