密码开游戏

· · 个人记录

#include<bits/stdc++.h>
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>
using namespace std;
void read(string a,int b) {
    for(int i=0; i<a.size(); i++) {
        cout<<a[i];
        Sleep(b);
    }
}
unsigned int BKDRHash(char *str) {
    unsigned int seed = 520; //种子,可更改
    unsigned int hash = 0;
    while (*str) {
        hash = hash * seed + (*str++);
    }
    return hash;
}
int main() {
    system("title 密码开游戏");
    system("cls");
    cout<<"这是你第一次玩这款游戏吗?\n";
    cout<<"1.Yes 2.No\n";
    int Yes;
    cin>>Yes;
    if(Yes==1)
        cout<<"";
    else if(Yes==2) {
        ifstream fin;
        ofstream fout;
        cout<<"请输入你的账户名:";
        string name;
        cin>>name;
        cout<<"请输入你的密码:";
        char kkk;
        char mima[1005];
        int l=0;
        while(kkk!='\r') 
        {
            kkk=_getch();
            if(kkk!=VK_BACK) mima[l++]=kkk,cout<<"*";
            else if(l>0)
            {
                mima[l]='\0';
                l--;
                cout<<"\b \b";
            }
        }
        mima[l-1]='\0';
        //cout<<mima;
        unsigned long long ans;
        string c,wm;
        cout<<"\n";
        read("这个文件的名字是什么?\n",30);
        cin>>wm;
        wm+=".dat";
        fin.open(wm.c_str());
        fin>>ans;
        if(BKDRHash(mima)!=ans) {
            lllllllll:
            //cout<<BKDRHash(mima)<<" "<<ans; 
            cout<<"Jcer死";
            return 0;
        }
        fin>>c;
        if(c!=name) {
            goto lllllllll;
        }
        fin.close();
        ifstream infile;
        cout<<"验证成功\n";
        cout<<"你要玩什么:";
        string yx,line,xy;
        cin>>yx;
        xy="title "+yx;
        yx+=".exe";
        system("cls");
        system(yx.c_str());
        system(xy.c_str());
    }
    cout<<"请输入你的用户名:";
    string c;
    cin>>c;
    cout<<"请输入你的密码(如果输入错误请关闭程序):";
    char hh,t=0;
    char ans[1005];
    while(hh!='\r') {
        hh=_getch();
        if(hh!=VK_BACK) ans[t++]=hh,cout<<"*";
        else if(t>0)
        {
            ans[t]='\0';
            t--;
            cout<<"\b \b";
        }
    }
    cout<<endl;
    read("开始核对密码,你的密码为:",30);
    cout<<ans;
    ans[t-1]='\0';
    Sleep(2000);
    cout<<"1.是的,这是我的密码  2.这不是我的密码!";
    cout<<endl;
    char l=_getch();
    if(l=='1') {
        read("这个文件的名字你想叫什么?\n",30);
        string wm;
        cin>>wm;
        wm+=".dat";
        cout<<"保存成功!\n";
        ofstream fout;
        fout.open(wm.c_str());
        fout<<BKDRHash(ans)<<endl<<c;
        fout.close ();
        Sleep(2000);
        read("你的密码位于",30);
        read(wm.c_str(),30);
        read("里面\n",30);
        Sleep(500);
        read("再见\n",30);
        return 0;
    } else {
        cout<<"那你关闭程序在启动一次";
        cout<<endl;
        cout<<"我先停止运行了";
        return 0;
    }
    return 0;
}