双人pvp

· · 个人记录

请看准正版

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int zl1,zl2,money1=5,money2=5,bj1,bj2,mj1,mj2;
int hp1=10,hp2=10,jl1=5,jl2=5;
bool b1,b2,m1,m2;
string nm1,nm2;
void dagong1(){
    jl1--;
    cout<<"打工中"<<endl;
    Sleep(1000); 
    srand(time(0));
    int f=rand()%15;
    if(f==3){               
        srand(time(0));
        int zs=rand()%2;
        cout<<"你获得了"<<zs*10<<"枚金币"<<endl;
        money1+=10*zs;
    }else if(f==2){
        cout<<"资本家太黑心了没给你金币"<<endl;
    }else if(f==1){
        cout<<"资本家太黑心了没给你金币"<<endl;
        cout<<"于是你打了他"<<endl;
        cout<<"金币-"<<5<<endl;
        money1-=5;
    }else{
        srand(time(0));
        int jb=rand()%10;
        cout<<"你获得了"<<jb<<"枚金币"<<endl;
        money1+=jb;
    }
    Sleep(800); 
    system("cls");
}
void dagong2(){
    jl2--;
    cout<<"打工中"<<endl;
    Sleep(1000); 
    srand(time(0));
    int f=rand()%15;
    if(f==3){               
        srand(time(0));
        int zs=rand()%2;
        cout<<"你获得了"<<zs*10<<"枚金币"<<endl;
        money2+=10*zs;
    }else if(f==2){
        cout<<"资本家太黑心了没给你金币"<<endl;
    }else if(f==1){
        cout<<"资本家太黑心了没给你金币"<<endl;
        cout<<"于是你打了他"<<endl;
        cout<<"金币-"<<5<<endl;
        money2-=5;
    }else{
        srand(time(0));
        int jb=rand()%10;
        cout<<"你获得了"<<jb<<"枚金币"<<endl;
        money2+=jb;
    }
    Sleep(800); 
    system("cls");
}
int main(){
    char h;
    cout<<"1号名字";
    cin>>nm1; 
    system("cls");
    cout<<"2号名字";
    cin>>nm2; 
    system("cls");
    while(1){
        if(hp1==0){ 
            system("cls");
            cout<<"2号赢"<<endl;
            return 0;
        }
        if(hp2==0){ 
            system("cls");
            cout<<"1号赢"<<endl;
            return 0;
        }
        while(1){
            if(money1<0){
                cout<<"你欠了钱 被打了"<<endl;
                hp1--;
            }
            cout<<nm1<<endl;
            cout<<"金币:"<<money1<<endl;
            cout<<"血量:"<<hp1<<"战力:"<<zl1<<endl;
            cout<<"精力:"<<jl1<<endl; 
            cout<<"(0)下一回合"<<endl;
            cout<<"(1)打工"<<endl;
            if(b1==1){
                cout<<"(2)升级兵营 "<<bj1*10<<"$"<<endl;
            } else{
                cout<<"(2)建造兵营 10$"<<endl;
            }
            if(m1==1){
                cout<<"(3)升级贸易 "<<mj1*15<<"$"<<endl;
            } else{
                cout<<"(3)建造贸易 15$"<<endl;
            }
            cin>>h;
            if(h=='0'){
                break;
            }else if(h=='1'){
                if(jl1<=0){
                    cout<<"没精力了"<<endl;
                }else{
                    dagong1();
                }
            }else if(h=='2'){
                if(b1){
                    if(money1>=bj1*10){
                        money1-=bj1*10;
                        bj1++;
                    }else{
                        cout<<"没钱"<<endl;
                    }
                }else{
                    if(money1>=10){
                        money1-=10;
                        bj1++;
                        b1=1;
                    }else{
                        cout<<"没钱"<<endl;
                    }
                }
            }else if(h=='3'){
                if(b1){
                    if(money1>=mj1*15){
                        money1-=mj1*15;
                        mj1++;
                    }else{
                        cout<<"没钱"<<endl;
                    }
                }else{
                    if(money1>=15){
                        money1-=15;
                        mj1++;
                        m1=1;
                    }else{
                        cout<<"没钱"<<endl;
                    }
                }
            }else{
                cout<<"输入错误"<<endl;
            }
            Sleep(800); 
            system("cls");
        }
        while(1){
            if(money2<0){
                cout<<"你欠了钱 被打了"<<endl;
                hp1--;
            }
            cout<<nm2<<endl;
            cout<<"金币:"<<money2<<endl;
            cout<<"血量:"<<hp2<<"战力:"<<zl2<<endl;
            cout<<"精力:"<<jl2<<endl; 
            cout<<"(0)下一回合"<<endl;
            cout<<"(1)打工"<<endl;
            if(b2==1){
                cout<<"(2)升级兵营 "<<bj2*10<<"$"<<endl;
            } else{
                cout<<"(2)建造兵营 10$"<<endl;
            }
            if(m2==1){
                cout<<"(3)升级贸易 "<<mj2*15<<"$"<<endl;
            } else{
                cout<<"(3)建造贸易 15$"<<endl;
            }
            cin>>h;
            if(h=='0'){
                break;
            }else if(h=='1'){
                if(jl2<=0){
                    cout<<"没精力了"<<endl;
                }else{
                    dagong2();
                }
            }else if(h=='2'){
                if(b2){
                    if(money2>=bj2*10){
                        money2-=bj2*10;
                        bj2++;
                    }else{
                        cout<<"没钱"<<endl;
                    }
                }else{
                    if(money2>=10){
                        money2-=10;
                        bj2++;
                        b2=1;
                    }else{
                        cout<<"没钱"<<endl;
                    }
                }
            }else if(h=='3'){
                if(b2){
                    if(money2>=mj2*15){
                        money2-=mj2*15;
                        mj2++;
                    }else{
                        cout<<"没钱"<<endl;
                    }
                }else{
                    if(money2>=15){
                        money2-=15;
                        mj2++;
                        m2=1;
                    }else{
                        cout<<"没钱"<<endl;
                    }
                }
            }else{
                cout<<"输入错误"<<endl;
            }
            Sleep(800); 
            system("cls");
        }
        Sleep(300); 
        system("cls");
        if(zl1>zl2){
            hp2--;
        }else{
            hp1--;
        }
        jl1+=3; 
        zl1+=bj1*5;
        money1+=mj1*3;
        jl2+=3; 
        zl2+=bj2*5;
        money2+=mj2*3;
    }
    return 0;
}