恶魔轮盘赌

· · 休闲·娱乐

#include <bits/stdc++.h>
#include <windows.h>

using namespace std;

int healthy[4] = {-1,2,3,4};
int aheal,bheal;
int nowhit = 1;
int nif[4] = {-1,1,2,2};

struct body {
    int heal;
    char buf[10];
    int nif;
};

body a,b;

int term,wter;
bool butt[20];

int getrand(int min,int max) {
    return (rand() % (max - min + 1)) + min;
}

void say(string a) {
    for(int i = 0; i < a.size(); i++) {
        cout << a[i];
        Sleep(75);
    }
}

void wait() {
    cout << "Press Enter to continue..." << endl;
    getchar();
    system("cls");
}

bool cho(bool wter,int k) {
    char isuse = 'n';
    if(wter) {
        say("a的回合");
        nowhit = 1;
        cout << endl;
        wait();
        if(a.nif>0) {
            say("是否使用小刀?y or n");
            isuse = getchar();
            wait();
            if(isuse == 'y') a.nif--;
            nowhit = 1;
        }
    } else {
        say("b的回合");
        nowhit = 1;
        cout << endl;
        wait();
        if(b.nif>0) {
            say("是否使用小刀?y or n");
            isuse = getchar();
            wait();
            if(isuse == 'y') b.nif--;
            nowhit = 1;
        }
    }
    if(isuse == 'y') nowhit = 2;
    else nowhit = 1;
    say("你选择打a还是b");
    char hit = getchar();
    wait();
    say("你选择了");
    cout << hit;
    say("这很有意思");
    cout << endl;
    say("这一发子弹是......");
    if(butt[k]) {
        cout << "实弹" << endl;;

        if(hit == 'a') a.heal-=nowhit;
        else b.heal-=nowhit;
        nowhit = 1;
        Sleep(2000);
    } else {
        cout << "空弹" <<endl;
        Sleep(2000);
    }
    wait();
    cout << "a的血量:" << a.heal << endl;
    cout << "b的血量:" << b.heal << endl;
    wait();
    if(wter && ((hit=='a' && butt[k] == 0) || (hit == 'b' && butt[k] == 1))) wter = 1;
    else if(!wter && (hit == 'b' && butt[k] == 0) || (hit == 'a' && butt[k] == 1)) wter = 0;
    else if(!wter && (hit == 'b' && butt[k] == 1) || (hit == 'a' && butt[k] == 0)) wter = 1;
    else if(wter && ((hit=='a' && butt[k] == 1) || (hit == 'b' && butt[k] == 0))) wter = 0;
    return wter;
}

int check() {
    if(a.heal <= 0) return 1;
    if(b.heal <= 0) return -1;
    else return 0;
}

int main() {
    srand(time(0));

    cout << "只有双人对战,敬请谅解!" << endl;
    wait();
    int awin = 0,bwin = 0;

    for(int h = 1; h <= 3; h++) {
        memset(butt,0,sizeof(butt));
        int all = getrand(3,10);

        int live = getrand(1,(all-2));
        int tmp1 = live;
        int vir = all-live;
        for(int i = 1; i <= live; i++) butt[i] = 1;
        for(int i = all; i > 0; i--) {
            swap(butt[i],butt[getrand(1,i)]);
        }
        cout << live << "实弹  " << vir << "空弹" << endl;
        if(h == 1) say("第I回合,有1把刀");
        if(h == 2) say("第II回合,有2把刀");
        if(h == 3) say("第III回合,有2把刀");
        a.nif = b.nif = nif[h];
        cout << '\n';
        wait();
        if(aheal && bheal) {
            a.heal = aheal;
            b.heal = bheal;
            aheal = 0;
            bheal = 0;
        } else {
            int heal = healthy[h];
            a.heal = heal;
            b.heal = heal;
        }
        ++term;
        int noww = 0;
        wter = getrand(0,1);
        if(wter) {
            noww = 1;
        } else {
            noww = 0;
        }
        int mter = 1;

        while(all) {
            noww = cho(noww,mter);
            mter++;
            all--;
            int isend = check();
            if(isend == 1) {
                cout << "b赢得了此次回合" <<endl;
                wait();
                bwin++;
                break;
            } else if(isend == -1) {
                cout << "a赢得了此次回合" << endl;;
                wait();
                awin++;
                break;
            }
        }
        if(!all && a.heal && b.heal) {
            say("没有人在这一回合胜出,增加一回合");
            cout << endl;
            wait();
            h--;
            aheal = a.heal;
            bheal = b.heal;
        }
    }
    say("比赛已经结束,看看谁赢了....................很好,我很有眼光\n");
    say("胜利者是:");
    if(awin > bwin) cout << 'a';
    else  cout << 'b';
    cout << endl;
    wait();
    say("恭喜!游戏结束\n");
    wait();
    Sleep(5000);
    return 0;
}