大家好,我是派蒙,我写了一个《屠夫躲猫猫》的游戏,下面是源代码:
cpp
#include <stdio.h>
#include <conio.h>
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
string ID[1001];
string Name[1001],Key[1001];
int main(void){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02);
cout<<"========================================================"<<endl<<endl<<endl;
cout<<" 屠夫躲猫猫"<<endl;
cout<<" Butcher Hide And Seek"<<endl;
Sleep(4000);
ID[0]="VIP000";
Name[0]="派蒙";
Key[0]="MIHOYO";
ID[1]="VIP001";
Name[1]="纳西妲";
Key[1]="MIHOYO";
ID[2]="VIP002";
Name[2]="芙宁娜";
Key[2]="MIHOYO";
ID[3]="SVIP666";
Name[3]="原神";
Key[3]="MIHOYO";
int cnt=4;
bool zt=1;
long long I=100000;
string n,m;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02);
while(1){
system("cls");
bool K=0;
zt=1;
cout<<"========================================================"<<endl;
cout<<"注册/登录"<<endl;
cout<<"(本机注册的账户只能在本机中使用)"<<endl;
if(zt==1){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xF0);
}else if(zt==0){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02);
}
cout<<"1.没有账号,注册一个"<<endl;
if(zt==0){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xF0);
}else if(zt==1){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02);
}
cout<<"2.有账号,直接登录" <<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02);
cout<<"(W/S选择,Y确定)"<<endl;
int a=getch();
system("cls");
switch(a){
case 'W':zt=1;
case 'S':zt=0;
case 'Y':if(zt==1){
cout<<"========================================================"<<endl;
cout<<"请输入用户名:"<<endl;
cin>>Name[cnt];
cout<<"请设置密码:"<<endl;
cin>>Key[cnt];
ID[cnt]=I;
I++;
cnt++;
system("cls");
}else if(zt==0){
cout<<"========================================================"<<endl;
cout<<"用户名/ID:";
cin>>n;
cout<<"密码:";
cin>>m;
int cnt1;
for(int i=0;i<=cnt;i++){
if(n==Name[i]&&m==Key[i]||n==ID[i]&&m==Key[i]){
K=1;
cnt1=i;
break;
}
}
if(K==1){
system("cls");
cout<<"========================================================"<<endl<<endl;
cout<<" 抵制不良游戏,拒绝盗版游戏。"<<endl;
cout<<" 注意自我保护,谨防受骗上当。"<<endl;
cout<<" 适度游戏益脑,沉迷游戏伤身。"<<endl;
cout<<" 合理安排时间,享受健康生活。"<<endl<<endl;
cout<<" 初始化资源中..."<<endl;
int n=20;
cout<<" _____________________"<<endl;
cout<<" ";
while(n--){
cout<<"█";
Sleep(300);
}
while(1){
system("cls");
cout<<"========================================================"<<endl;
cout<<"□"<<Name[cnt1]<<endl;
cout<<"选择模式:(输入对应中文)"<<endl;
string out="开始游戏";
for(int i=0;i<=7;i+=2){
cout<<out[i]<<out[i+1];
Sleep(500);
}
cout<<endl;
out="退出登录";
for(int i=0;i<=7;i+=2){
cout<<out[i]<<out[i+1];
Sleep(500);
}
cout<<endl;
out="修改资料";
for(int i=0;i<=7;i+=2){
cout<<out[i]<<out[i+1];
Sleep(500);
}
cout<<endl;
while(1){
string n;
cin>>n;
if(n=="开始游戏"){
system("cls");
cout<<"========================================================"<<endl;
cout<<"请选择躲藏位置:(输入对应中文)"<<endl;
cout<<"床底下/衣柜里/窗帘后/马桶里/桌底下/沙发底/沙发后/原地不动"<<endl;
cin>>n;
int Location;
if(n=="床底下"){
Location=0;
}else if(n=="衣柜里"){
Location=1;
}else if(n=="窗帘后"){
Location=2;
}else if(n=="马桶里"){
Location=3;
}else if(n=="桌底下"){
Location=4;
}else if(n=="沙发底"){
Location=5;
}else if(n=="沙发后"){
Location=6;
}else if(n=="原地不动"){
Location=7;
}
bool died=0;
for(int cnt=1;cnt<=6;cnt++){
system("cls");
cout<<"========================================================"<<endl;
cout<<"第";
Sleep(1000);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x04);
cout<<cnt;
Sleep(1000);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x02);
cout<<"回";
Sleep(1000);
cout<<"合"<<endl;
Sleep(2000);
cout<<"嘘,屠夫来了。 你的位置:";
if(Location==0){
cout<<"床底下\n";
}else if(Location==1){
cout<<"衣柜里\n";
}else if(Location==2){
cout<<"窗帘后\n";
}else if(Location==3){
cout<<"马桶里\n";
}else if(Location==4){
cout<<"桌底下\n";
}else if(Location==5){
cout<<"沙发底\n";
}else if(Location==6){
cout<<"沙发后\n";
}
Sleep(1000);
if(Location==7){
cout<<"由于你没有躲藏,你被屠夫发现了。你死了。";
died=1;
Sleep(4000);
break;
}
int go=rand()%6;
if(go==Location){
cout<<"你被屠夫抓到了,你死了。"<<endl;
died=1;
break;
Sleep(4000);
system("cls");
}else{
cout<<"屠夫看向了";
if(go==0){
cout<<"床底下";
}else if(go==1){
cout<<"衣柜里";
}else if(go==2){
cout<<"窗帘后";
}else if(go==3){
cout<<"马桶里";
}else if(go==4){
cout<<"桌底下";
}else if(go==5){
cout<<"沙发底";
}else if(go==6){
cout<<"沙发后";
}
Sleep(1000);
cout<<",他抓住了一名玩家,一人被淘汰。";
Sleep(3000);
system("cls");
}
}
if(died==1){
break;
}else{
system("cls");
cout<<"======================================================="<<endl;
cout<<"你存活到了最后,你赢了!";
Sleep(3000);
system("cls");
}
}else if(n=="退出登录"){
cout<<"======================================================="<<endl<<endl;
cout<<" 正在退出......"<<endl;
Sleep(5000);
system("cls");
break;
}else if(n=="修改资料"){
cout<<"======================================================="<<endl<<endl;
cout<<"请选择要修改的选项"<<endl;
out="昵称";
for(int i=0;i<=7;i+=2){
cout<<out[i]<<out[i+1];
Sleep(500);
}
cout<<endl;
out="密码";
for(int i=0;i<=7;i+=2){
cout<<out[i]<<out[i+1];
Sleep(500);
}
cout<<endl;
cin>>n;
if(n=="昵称"){
system("cls");
cout<<"======================================================="<<endl;
cout<<"输入新昵称:";
cin>>n;
Name[cnt1]=n;
system("cls");
cout<<"======================================================="<<endl;
cout<<"修改成功!";
}else if(n=="密码"){
system("cls");
cout<<"======================================================="<<endl;
cout<<"输入旧密码:";
cin>>n;
if(n==Key[cmt1]){
system("cls");
cout<<"======================================================="<<endl;
cout<<"输入新密码"<<endl;
cin>>n;
Key[cnt1]=n;
cout<<"修改成功!"<<endl;
}else{
system("cls");
cout<<"======================================================="<<endl;
cout<<"密码错误!"<<endl;
}
}
}
}
}//-
return 0;
}else{
cout<<"密码或用户名错误,请重新输入!!!"<<endl;
Sleep(1000);
system("cls");
}
}
}
}
}