c语言小游戏登陆界面
时间: 2023-06-22 22:20:54 浏览: 116
好,这是一个简单的C语言小游戏登陆界面的代码示例:
```
#include <stdio.h>
#include <string.h>
int main() {
char username[20];
char password[20];
int attempts = 3;
printf("Welcome to the game! \n");
while (attempts > 0) {
printf("Please enter your username: ");
scanf("%s", username);
printf("Please enter your password: ");
scanf("%s", password);
if (strcmp(username, "user") == 0 && strcmp(password, "pass") == 0) {
printf("Login successful! \n");
break;
} else {
attempts--;
printf("Invalid username or password. %d attempts remaining. \n", attempts);
}
}
if (attempts == 0) {
printf("Too many failed attempts. Exiting... \n");
} else {
printf("Starting the game... \n");
}
return 0;
}
```
这个程序中,用户需要输入用户名和密码来登陆游戏。如果输入正确,程序会输出“Login successful!”并开始游戏;如果输入错误,程序会提示“Invalid username or password.”并显示剩余的尝试次数。如果尝试次数用完了,程序会输出“Too many failed attempts. Exiting...”并退出。