恶魔轮盘赌

· · 休闲·娱乐

#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;
}

2024-12-22-7:30

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; int knife; // 小刀 int magnifier; // 放大镜 int cigar; // 香烟 int handcuff; // 手铐 };

body a, b;

bool butt[20]; bool skip_next[2] = {0, 0};

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

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

void wait() { cout << "\nPress Enter to continue..."; cin.get(); system("cls"); }

void clearbuf() { while (cin.get() != '\n'); }

void show_status(char who) { body &p = (who == 'A') ? a : b; cout << who << " 状态: 血量=" << p.heal << " | 刀=" << p.knife << " 镜=" << p.magnifier << " 烟=" << p.cigar << " 铐=" << p.handcuff << endl; }

// 选道具界面 // 选道具界面(总共最多3个) void choose_items(body &p, char who) { p.knife = p.magnifier = p.cigar = p.handcuff = 0; int total = 0;

cout << who << ",请选择道具(总共最多3个):\n\n";
cout << "  1. 小刀    - 开枪伤害×2\n";
cout << "  2. 放大镜  - 查看当前子弹(看完可决定是否开枪)\n";
cout << "  3. 香烟    - 回复1点血量\n";
cout << "  4. 手铐    - 对方下回合跳过\n\n";

while (total < 3) {
    cout << "当前已选 " << total << "/3 个道具\n";
    cout << "  1.小刀(" << p.knife << ")  2.放大镜(" << p.magnifier
         << ")  3.香烟(" << p.cigar << ")  4.手铐(" << p.handcuff << ")\n";
    cout << "选择要增加的道具编号 (1~4),或输入0结束选择: ";

    int choice;
    cin >> choice;
    clearbuf();

    if (choice == 0) break;
    if (choice == 1) { p.knife++; total++; }
    else if (choice == 2) { p.magnifier++; total++; }
    else if (choice == 3) { p.cigar++; total++; }
    else if (choice == 4) { p.handcuff++; total++; }
    else cout << "无效输入!\n";
}

cout << "\n" << who << " 最终携带: ";
cout << "刀×" << p.knife << " 镜×" << p.magnifier
     << " 烟×" << p.cigar << " 铐×" << p.handcuff << endl;
wait();

}

int use_item_menu(body &p, char who) { if (p.knife == 0 && p.magnifier == 0 && p.cigar == 0 && p.handcuff == 0) { return 0; }

cout << who << " 的道具:\n";
if (p.knife > 0) cout << "  1. 小刀(伤害×2)\n";
if (p.magnifier > 0) cout << "  2. 放大镜(查看当前子弹)\n";
if (p.cigar > 0) cout << "  3. 香烟(回复1血)\n";
if (p.handcuff > 0) cout << "  4. 手铐(对方下回合跳过)\n";
cout << "  0. 不使用道具\n";
cout << "选择: ";

int choice;
cin >> choice;
clearbuf();

switch (choice) {
    case 1: if (p.knife > 0) { p.knife--; return 1; } break;
    case 2: if (p.magnifier > 0) { p.magnifier--; return 2; } break;
    case 3: if (p.cigar > 0) { p.cigar--; p.heal = min(p.heal + 1, 4); return 3; } break;
    case 4: if (p.handcuff > 0) { p.handcuff--; return 4; } break;
}
return 0;

}

bool do_turn(bool wter, int k, int &mter, int all) { // 手铐判定 if (wter && skip_next[0]) { say("A 被手铐铐住了,跳过回合!\n"); skip_next[0] = 0; wait(); return false; // 换人 } if (!wter && skip_next[1]) { say("B 被手铐铐住了,跳过回合!\n"); skip_next[1] = 0; wait(); return true; // 换人 }

body &self = wter ? a : b;
char myname = wter ? 'A' : 'B';

say(">>> ");
cout << myname;
say(" 的回合 <<<\n");

show_status('A');
show_status('B');
cout << endl;

// 使用道具
int item = use_item_menu(self, myname);

if (item == 1) {
    nowhit = 2;
    say("你拿出了小刀!本回合伤害×2!\n");
} else {
    nowhit = 1;
}

if (item == 2) {
    if (butt[mter]) {
        say("放大镜显示:>>> 实弹 <<<\n");
    } else {
        say("放大镜显示:>>> 空弹 <<<\n");
    }
    cout << "是否开枪?(y=开枪, n=不开枪结束回合): ";
    char shoot;
    cin >> shoot;
    clearbuf();
    if (shoot == 'n' || shoot == 'N') {
        say("你选择不开枪,回合结束。\n");
        nowhit = 1;
        wait();
        return !wter;
    }
}

if (item == 3) {
    say("你抽了一根烟,恢复了1点血量。\n");
}

if (item == 4) {
    if (wter) skip_next[1] = 1;
    else skip_next[0] = 1;
    say("你给对手铐上了手铐!下回合对方跳过!\n");
}

// 选目标
char hit;
cout << "选择目标:打 A 还是 B?(a/b): ";
cin >> hit;
clearbuf();
hit = tolower(hit);
while (hit != 'a' && hit != 'b') {
    cout << "无效,选 a 或 b: ";
    cin >> hit;
    clearbuf();
    hit = tolower(hit);
}

say("\n扣动扳机...\n");
Sleep(800);

if (butt[mter]) {
    cout << ">>> 实弹! <<<\n";
    if (hit == 'a') a.heal -= nowhit;
    else b.heal -= nowhit;
    wter = !wter;  // 实弹换人
} else {
    cout << ">>> 空弹! <<<\n";
}

nowhit = 1;
mter++;
Sleep(1000);
wait();
return wter;

}

int check() { if (a.heal <= 0 && b.heal > 0) return 1; // B赢 if (b.heal <= 0 && a.heal > 0) return -1; // A赢 if (a.heal <= 0 && b.heal <= 0) return 2; // 同归于尽 return 0; }

int main() { srand(time(0)); system("cls");

say("=== 恶魔轮盘赌 v3.0 ===\n");
say("道具由玩家自由选择携带\n\n");
wait();

// 开局选道具
say("--- A 选择道具 ---\n");
choose_items(a, 'A');
say("--- B 选择道具 ---\n");
choose_items(b, 'B');

say("道具选择完毕!开始游戏!\n");
wait();

int awin = 0, bwin = 0;

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

    int all = getrand(3, 10);
    int live = getrand(1, all - 1);

    for (int i = 1; i <= live; i++) butt[i] = 1;
    for (int i = all; i > 1; i--) {
        swap(butt[i], butt[getrand(1, i)]);
    }

    cout << "第 " << h << " 回合\n";
    cout << "弹巢: " << live << " 发实弹, " << (all - live) << " 发空弹\n\n";

    // 血量
    if (aheal && bheal) {
        a.heal = aheal; b.heal = bheal;
        aheal = bheal = 0;
    } else {
        a.heal = b.heal = healthy[h];
    }

    show_status('A');
    show_status('B');
    wait();

    bool wter = getrand(0, 1);
    int mter = 1;

    while (mter <= all) {
        wter = do_turn(wter, mter, mter, all);

        // 剩余弹药
        int remain_live = 0, remain_vir = 0;
        for (int i = mter; i <= all; i++) {
            if (butt[i]) remain_live++;
            else remain_vir++;
        }
        cout << "剩余: 实弹=" << remain_live << " 空弹=" << remain_vir << endl;
        cout << "A 血量=" << a.heal << "  B 血量=" << b.heal << endl;
        wait();

        int isend = check();
        if (isend == 1) {
            say("B 赢得了第 ");
            cout << h;
            say(" 回合!\n");
            bwin++;
            wait();
            break;
        } else if (isend == -1) {
            say("A 赢得了第 ");
            cout << h;
            say(" 回合!\n");
            awin++;
            wait();
            break;
        } else if (isend == 2) {
            say("同归于尽!\n");
            wait();
            break;
        }
    }

    // 弹药用完都没死 → 加时
    if (mter > all && a.heal > 0 && b.heal > 0) {
        say("弹药用尽!进入加时!\n");
        wait();
        h--;
        aheal = a.heal; bheal = b.heal;
    }
}

// 最终结果
system("cls");
say("====================\n");
say("  比赛结束!\n");
say("====================\n\n");
cout << "A 赢: " << awin << " 回合\n";
cout << "B 赢: " << bwin << " 回合\n\n";
say("最终胜利者是:");
if (awin > bwin) cout << "A !!!\n";
else if (bwin > awin) cout << "B !!!\n";
else cout << "平局!!!\n";

wait();
return 0;

} 2026-8-28 16:35