数字炸弹重置版1.02

#include<bits/stdc++.h>
#include<windows.h>
#include <iostream>
#include<ctime>
#include<cstdlib>
#include<fstream>
#include<conio.h>
using namespace std;
void saveScore(long long score) {
    ofstream outFile("score.dat");
    if(outFile.is_open()){
        outFile<<score;
        outFile.close();
        cout<<"保存成功!分数已记录\n";
    }
	else{
        cout<<"保存失败!无法打开文件\n";
    }
}
long long loadScore(){
    ifstream inFile("score.dat");
    long long score;
    if (inFile.is_open()){
        inFile>>score;
        inFile.close();
    }
    return score;
}
bool login() {
    string username,password;
    cout<<"登录\n";
    cout << "用户名: \n";
    cin >> username;
    cout << "密码: \n";
    char pwd[100];
    int i=0;
    while((pwd[i]=_getch())!='\r'){
        if(pwd[i]=='\b'&&i>0) {
            cout<<"\b \b";
            i--;
        }
		else if(pwd[i]!='\b'){
            cout<<"*";
            i++;
        }
    }
    pwd[i]='\0';
    password = string(pwd);
    if (username=="th111"&&password=="1234567") {
        return true;
    }
	else{
        return false;
    }
}
void HideCursor(){
	CONSOLE_CURSOR_INFO cursor_info={1,0}; 
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
char c;
long long fengshu=100;
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";
		cin>>c;
		while(c<'1'||c>'4'){
			cout<<"输入无效\n";
			cin>>c; 
		}
		if(c=='1'){
			cout<<"输入难度1.菜鸟2.人类3.神\n";
			cin>>c;
			while(!(c<='3')||!(c>='1')){
				cout<<"输入无效\n";
				cin>>c; 
			}
			int shangjie,sh,xiajie=1,zhadan,cishu=1,caideshu;
			if(c=='1')shangjie=100;
			if(c=='2')shangjie=7198;
			if(c=='3')shangjie=114514;
			sh=shangjie;
			zhadan=rand()%shangjie+1;
			while(shangjie!=zhadan&&xiajie!=zhadan){
				system("cls");
				cout<<xiajie<<"到"<<shangjie<<'\n';
				cin>>caideshu;
				while((caideshu>=shangjie||caideshu<=xiajie)&&caideshu!=zhadan){
					cout<<"输入无效\n";
					cin>>caideshu;
					cishu+=5;
				}
				if(caideshu==zhadan)break;
				if(caideshu<zhadan)xiajie=caideshu;
				if(caideshu>zhadan)shangjie=caideshu;
				cishu++;
			}
			cout<<"猜中了\n"<<"1.不加倍\n"<<"2.加倍(有概率负数)\n";
			int jb;
			cin>>jb;
			while(jb<1&&jb>2){
				cout<<"输入无效";
			}
			if(jb==1){
				jb=0;
			}
			else{
				jb=5;
			}
			int p=(jb+1)*sh/cishu/5+1;
			cout<<"增加±"<<p<<"分";
			if(jb==0)fengshu+=p;
			else fengshu=fengshu+pow(-1,rand()%2)*p;
			Sleep(1000);
			system("cls");
		}
		if(c=='2'){
			cout<<"luogu:th111,xinyoudui:yhxyd2594\n";
			system("start https://www.luogu.com.cn/user/2086779");
			cout<<"任意键返回\n";
			_getch();
		}
		if(c=='3'){
			saveScore(fengshu);
            cout<<"按任意键返回\n";
            _getch(); 
		}
		if(c=='4'){
			if(login()){
                fengshu=loadScore();
                cout<<"\n登录成功!欢迎回来\n";
                cout<<"当前分数已加载:"<<fengshu<<endl;
                cout<<"按任意键返回\n";
                _getch();
            }
			else{
                cout<<"\n登录失败!用户名或密码错误\n";
                cout<<"按任意键返回\n";
                _getch();
            }
            system("cls");
		}
	}

}

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