数字炸弹1.04

#include<iostream>
#include<fstream>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<windows.h>
#include<conio.h>
using namespace std;
char c;
long long fengshu=100;
void HideCursor(){
    CONSOLE_CURSOR_INFO cursor_info = {1,0}; 
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
string getPasswordInput(){
    char pwd[100];
    char ch;
    int i=0;
    while((ch=_getch())!='\r'){
        if(ch=='\b'&&i>0){
            cout<<"\b\b";
            i--;
        }else{
            if(ch!='\b'){
                pwd[i]=ch;
                cout<<"*";
                i++;
            }
        }
    }
    pwd[i]='\0';
    return string(pwd);
}
void saveScore(long long score){
    string saveName,savePass;
    cout<<"\n存档设置\n";
    cout<<"请输入要保存的用户名: ";
    cin>>saveName;
    cout<<"请输入要设置的密码: ";
    string pwd=getPasswordInput();
    ofstream outFile("score.dat");
    if(outFile.is_open()){
        outFile<<saveName<<" "<<pwd<<" "<<score;
        outFile.close();
        cout<<"\n\n保存成功!账号["<<saveName<<"]的进度已记录。\n";
    }else{
        cout<<"保存失败!无法打开文件\n";
    }
}
void loadScore(long long &currentScore){
    ifstream inFile("score.dat");
    if(!inFile.is_open()){
        cout<<"\n未找到存档文件,请先进行游戏并保存!\n";
        return;
    }
    string fileName,filePass;
    long long fileScore;
    inFile>>fileName>>filePass>>fileScore;
    inFile.close();
    string inputName,inputPass;
    cout<<"\n读取存档\n";
    cout<<"请输入用户名: ";
    cin>>inputName;
    cout<<"请输入密码: ";
    inputPass=getPasswordInput();
    if(inputName==fileName&&inputPass==filePass){
        currentScore=fileScore;
        cout<<"\n\n登录成功!欢迎回来,"<<inputName<<"!\n";
        cout<<"您的历史最高分已加载:"<<currentScore<<endl;
    } else {
        cout<<"\n\n登录失败!用户名或密码错误。\n";
        cout<<"(提示:如果你忘记了,可以直接开始新游戏并重新保存覆盖)\n";
    }
    _getch();
}
int main(){
    system("color 1B");
    srand(time(0));
    system("cls");
    HideCursor();
    while(1){
        system("cls");
        cout<<"数字炸弹\n" 
            <<"分数 "<<fengshu<<'\n'
            <<"1. 开始游戏\n"
            <<"2. 查看作者\n"
            <<"3. 保存\n"
            <<"4. 读取存档\n"
            <<"5. 退出\n";
        cin>>c;
        if(c=='1'){
            cout<<"输入难度 1.菜鸟 2.人类 3.神\n";
            cin>>c;
            while(c<'1'||c>'3'){ 
                cout<<"输入无效\n";
                cin>>c; 
            }
            int shangjie,sh,xiajie=1,zhadan,cishu=1,caideshu;
            if(c=='1')shangjie=100;
            else if(c=='2')shangjie=7198;
            else shangjie=114514;
            sh=shangjie;
            zhadan=rand()%shangjie+1;
			int mode;
			cout<<"选择模式:\n1. 经典模式(无限次)\n2. 生命模式(3条命)\n";
			cin>>mode;
			int lives=(mode==2)?3:999;
			while(cishu<=100){ 
    			system("cls");
    			if(mode==2){
					cout<<"生命: ";
					for(int i=0;i<lives;i++){
						cout<<"*";
					}
					cout<<endl;
				}
    			cout<<xiajie<<"到"<<shangjie<<endl;
    			cin>>caideshu;
    			if(caideshu<=xiajie||caideshu>=shangjie){
        			cout<<"输入无效!必须在范围内。\n";
        			Sleep(800);
        			continue;
    			}
    			if(caideshu==zhadan)break; 
    			if(mode==2){
        			lives--;
        			if(lives==0) {
            			cout<<"炸弹爆炸了!分数减10\n";
            			fengshu-=10; 
            			_getch();
            			break;
        			}
    			}
    			if(caideshu<zhadan)xiajie=caideshu;
    			else shangjie=caideshu;
    			cishu++;
			}
            if(lives!=0){
            	cout<<"猜中了!炸弹是 "<<zhadan<<endl;
            	cout<<"1. 不加倍\n"<<"2. 加倍(有概率负数)\n";
            	int jb;
            	cin>>jb;
            	while(jb<1||jb>2){
                	cout<<"输入无效\n";
                	cin>>jb;
            	}
            	int p=(jb+1)*sh/cishu/5+1;
            	cout<<"增加 "<<p<<"分\n";
            	if(jb==1){
                	fengshu+=p;
                	cout<<"得分增加!";
            	}else{
                	int aacc=pow(-1,rand()%2)*p;
                	if(aacc<0){
						cout<<"运气不好,分数变负了!\n"<<"1.进入商店\n"<<"2.退出";
						cin>>c;
						if(c=='1'){
							cout<<"1.50分取消扣分\n"<<"2.200分负变正\n"<<"3.退出\n";
							cin>>c;
							if(c=='1'){
								aacc=0;
							}
							if(c=='2'){
								aacc=abs(aacc);
							}
						}
					}
					fengshu+=2*aacc;
            	}
        	}
            cout<<"当前分数:"<<fengshu<<endl;
            cout<<"按任意键返回\n";
            _getch();
        }else if(c=='2'){
            cout<<"作者信息\n";
            cout<<"洛谷: th111\n";
            cout<<"信友队: yhxyd2594\n";
            Sleep(1000);
            system("start https://www.luogu.com.cn/user/2086779");
            cout<<"按任意键返回\n";
            _getch();  
        }else if(c=='3'){
            saveScore(fengshu);
            cout<<"按任意键返回\n";
            _getch();  
        }else if(c=='4'){
            loadScore(fengshu);
            
        }else if(c=='5'){
            break;
		}
    }
    return 0;
}

此话题已在最后回复的 15 天后被自动关闭。不再允许新回复。