#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>

using namespace std;

// 清屏函数(兼容Windows和Linux)
void clearScreen() {
    #ifdef _WIN32
        system("cls");
    #else
        system("clear");
    #endif
}

// 子弹类型枚举
enum BulletType {
    REAL,    // 实弹
    BLANK    // 空包弹
};

// 道具枚举(原版核心道具)
enum ItemType {
    NONE,
    MAGNIFIER,      // 放大镜:查看当前膛内子弹类型
    KNIFE,          // 小刀:下一发实弹伤害×2
    BEER,           // 啤酒:退出当前膛内子弹,转到下一发
    CIGARETTE,      // 香烟:恢复1点生命值
    HANDCUFF,       // 手铐:对手下回合跳过
    ADRENALINE,     // 肾上腺素:偷对手1个道具并使用
    REVERSER,       // 逆转器:反转当前子弹属性
    EXPIRED_DRUG    // 过期药物:40%+2血/60%-1血
};

// 道具结构体
struct Item {
    ItemType type;
    string name;
    string desc;
    int count;      // 数量
    bool used;      // 是否本局已使用(限制强力道具)

    Item(ItemType t, string n, string d, int c = 1) : type(t), name(n), desc(d), count(c), used(false) {}
};

// 游戏核心类
class DevilRoulette {
private:
    // 子弹系统
    vector<BulletType> bulletChambers; // 6个膛的子弹类型
    int currentChamber;                // 当前枪膛位置(索引0-5)
    bool knifeEffect;                  // 小刀双倍伤害效果
    
    // 生命值系统(胜负核心)
    int playerHP;                      // 玩家生命值(初始5)
    int devilHP;                       // 恶魔生命值(初始5)
    
    // 游戏状态
    bool isGameOver;                   // 游戏是否结束
    string winner;                     // 获胜者
    string loseReason;                 // 失败原因
    bool devilSkipTurn;                // 恶魔是否被手铐限制跳过回合
    bool playerSkipTurn;               // 玩家是否被手铐限制跳过回合
    
    // 道具系统
    vector<Item> playerItems;          // 玩家道具栏
    vector<Item> devilItems;           // 恶魔道具栏

    // 初始化轮盘(生成6个膛的子弹类型)
    void initRoulette() {
        bulletChambers.clear();
        // 随机生成2-3发实弹,其余为空包弹(原版比例)
        int realBulletCount = rand() % 2 + 2;
        for (int i = 0; i < 6; i++) {
            if (i < realBulletCount) {
                bulletChambers.push_back(REAL);
            } else {
                bulletChambers.push_back(BLANK);
            }
        }
        // 打乱子弹顺序
        random_shuffle(bulletChambers.begin(), bulletChambers.end());
        
        currentChamber = 0; // 索引从0开始
        knifeEffect = false;
        isGameOver = false;
        winner = "";
        loseReason = "";
        devilSkipTurn = false;
        playerSkipTurn = false;
        
        // 初始化生命值
        playerHP = 5;
        devilHP = 5;
        
        cout << "【恶魔轮盘赌】左轮已装填完毕!" << endl;
        cout << "(系统视角)子弹分布:";
        for (int i = 0; i < 6; i++) {
            cout << (bulletChambers[i] == REAL ? "实弹" : "空包弹") << " ";
        }
        cout << endl;
        
        // 初始化道具栏
        initItems();
    }

    // 初始化道具栏
    void initItems() {
        // 玩家初始道具
        playerItems.clear();
        playerItems.push_back(Item(MAGNIFIER, "放大镜", "查看当前膛内子弹是实弹/空包弹", 2));
        playerItems.push_back(Item(KNIFE, "小刀", "下一发实弹伤害×2(单局1次)", 1));
        playerItems.push_back(Item(BEER, "啤酒", "退出当前膛内子弹,转到下一发", 1));
        playerItems.push_back(Item(CIGARETTE, "香烟", "恢复1点生命值", 2));
        playerItems.push_back(Item(HANDCUFF, "手铐", "恶魔下回合完全跳过", 1));
        playerItems.push_back(Item(REVERSER, "逆转器", "反转当前子弹属性(单局1次)", 1));
        playerItems.push_back(Item(EXPIRED_DRUG, "过期药物", "40%+2血/60%-1血", 1));
        
        // 恶魔初始道具
        devilItems.clear();
        devilItems.push_back(Item(MAGNIFIER, "放大镜", "查看当前膛内子弹是实弹/空包弹", 1));
        devilItems.push_back(Item(BEER, "啤酒", "退出当前膛内子弹,转到下一发", 1));
        devilItems.push_back(Item(HANDCUFF, "手铐", "玩家下回合完全跳过", 1));
        devilItems.push_back(Item(ADRENALINE, "肾上腺素", "偷玩家1个道具并使用", 1));
    }

    // 胜负判定核心函数
    bool checkGameOver() {
        if (playerHP <= 0) {
            isGameOver = true;
            winner = "恶魔";
            loseReason = "你的生命值已耗尽";
            return true;
        }
        if (devilHP <= 0) {
            isGameOver = true;
            winner = "玩家";
            loseReason = "恶魔的生命值已耗尽";
            return true;
        }
        return false;
    }

    // 开枪判定(含伤害计算)
    void shoot(string shooter, string target) {
        BulletType currentBullet = bulletChambers[currentChamber];
        int damage = 1;
        
        // 小刀双倍伤害效果
        if (knifeEffect && currentBullet == REAL) {
            damage = 2;
            knifeEffect = false;
        }
        
        cout << "\n🔫 枪响了!当前膛内是【" << (currentBullet == REAL ? "实弹" : "空包弹") << "】" << endl;
        
        if (currentBullet == REAL) {
            cout << "💥 命中实弹!造成" << damage << "点伤害!" << endl;
            if (target == "玩家") {
                playerHP -= damage;
                if (playerHP < 0) playerHP = 0;
                cout << "你的生命值剩余:" << playerHP << "/5" << endl;
            } else {
                devilHP -= damage;
                if (devilHP < 0) devilHP = 0;
                cout << "恶魔的生命值剩余:" << devilHP << "/5" << endl;
            }
            // 开枪后立即检查胜负
            if (checkGameOver()) {
                return;
            }
        } else {
            cout << "🔇 命中空包弹!无伤害!" << endl;
            // 空包弹奖励:随机获得道具
            if (shooter == "玩家") {
                randomGetItem(playerItems, "玩家");
            } else {
                randomGetItem(devilItems, "恶魔");
            }
        }
        
        // 枪膛转动到下一发
        currentChamber = (currentChamber + 1) % 6;
    }

    // 显示道具栏
    void showItems(vector<Item>& items, string owner) {
        cout << "\n===== " << owner << "的道具栏 =====" << endl;
        if (owner == "玩家") {
            cout << "0. 不使用道具" << endl;
        }
        int validIdx = 1;
        for (int i = 0; i < items.size(); i++) {
            if (items[i].count > 0 && !items[i].used) {
                cout << validIdx << ". " << items[i].name << " - " << items[i].desc 
                     << " (剩余: " << items[i].count << ")" << endl;
                validIdx++;
            }
        }
        cout << "======================" << endl;
    }

    // 使用道具
    void useItem(int itemIdx, vector<Item>& userItems, vector<Item>& targetItems, string user) {
        if (itemIdx == 0 || userItems.empty()) return; // 不使用道具
        
        int validIdx = 1;
        for (auto& item : userItems) {
            if (item.count <= 0 || item.used) continue;
            
            if (itemIdx == validIdx) {
                cout << "\n" << user << "使用了【" << item.name << "】!" << endl;
                item.count--;
                // 强力道具标记为已使用(单局限制)
                if (item.type == KNIFE || item.type == REVERSER || item.type == ADRENALINE) {
                    item.used = true;
                }

                switch (item.type) {
                    case MAGNIFIER:
                        cout << "🔍 放大镜生效!当前膛内是【" 
                             << (bulletChambers[currentChamber] == REAL ? "实弹" : "空包弹") << "】" << endl;
                        break;
                    case KNIFE:
                        knifeEffect = true;
                        cout << "🔪 小刀生效!下一发实弹伤害翻倍!" << endl;
                        break;
                    case BEER:
                        cout << "🍻 啤酒生效!退出当前膛内子弹,转到下一发!" << endl;
                        currentChamber = (currentChamber + 1) % 6;
                        cout << "当前枪膛已切换到第" << (currentChamber + 1) << "膛" << endl;
                        break;
                    case CIGARETTE:
                        if (user == "玩家") {
                            playerHP = min(playerHP + 1, 5);
                            cout << "🚬 香烟生效!你的生命值恢复1点,当前:" << playerHP << "/5" << endl;
                        } else {
                            devilHP = min(devilHP + 1, 5);
                            cout << "😈 恶魔使用香烟!生命值恢复1点,当前:" << devilHP << "/5" << endl;
                        }
                        break;
                    case HANDCUFF:
                        if (user == "玩家") {
                            devilSkipTurn = true;
                            cout << "🔗 手铐生效!恶魔下回合将被强制跳过!" << endl;
                        } else {
                            playerSkipTurn = true;
                            cout << "😈 恶魔使用手铐!你下回合将被强制跳过!" << endl;
                        }
                        break;
                    case ADRENALINE:
                        {
                            // 偷对手1个道具
                            vector<int> validItems;
                            for (int i = 0; i < targetItems.size(); i++) {
                                if (targetItems[i].count > 0 && targetItems[i].type != ADRENALINE) {
                                    validItems.push_back(i);
                                }
                            }
                            if (!validItems.empty()) {
                                int stealIdx = validItems[rand() % validItems.size()];
                                Item& stolenItem = targetItems[stealIdx];
                                stolenItem.count--;
                                
                                // 给自己增加该道具
                                bool found = false;
                                for (auto& it : userItems) {
                                    if (it.type == stolenItem.type) {
                                        it.count++;
                                        found = true;
                                        break;
                                    }
                                }
                                if (!found) {
                                    userItems.push_back(Item(stolenItem.type, stolenItem.name, stolenItem.desc, 1));
                                }
                                
                                cout << "💉 肾上腺素生效!偷取了对手的【" << stolenItem.name << "】并立即使用!" << endl;
                                // 立即使用偷来的道具(递归调用)
                                if (user == "玩家") {
                                    useItem(userItems.size(), userItems, targetItems, user);
                                }
                            } else {
                                cout << "💉 肾上腺素生效!但对手没有可偷的道具!" << endl;
                            }
                        }
                        break;
                    case REVERSER:
                        cout << "🔄 逆转器生效!当前子弹属性反转!" << endl;
                        bulletChambers[currentChamber] = (bulletChambers[currentChamber] == REAL) ? BLANK : REAL;
                        cout << "当前膛内变为【" 
                             << (bulletChambers[currentChamber] == REAL ? "实弹" : "空包弹") << "】" << endl;
                        break;
                    case EXPIRED_DRUG:
                        {
                            int randRate = rand() % 10;
                            if (randRate < 4) {
                                // 40%概率+2血
                                if (user == "玩家") {
                                    playerHP = min(playerHP + 2, 5);
                                    cout << "💊 过期药物生效!幸运加成!生命值+2,当前:" << playerHP << "/5" << endl;
                                } else {
                                    devilHP = min(devilHP + 2, 5);
                                    cout << "😈 恶魔使用过期药物!生命值+2,当前:" << devilHP << "/5" << endl;
                                }
                            } else {
                                // 60%概率-1血
                                if (user == "玩家") {
                                    playerHP = max(playerHP - 1, 0);
                                    cout << "💊 过期药物生效!副作用触发!生命值-1,当前:" << playerHP << "/5" << endl;
                                } else {
                                    devilHP = max(devilHP - 1, 0);
                                    cout << "😈 恶魔使用过期药物!副作用触发!生命值-1,当前:" << devilHP << "/5" << endl;
                                }
                            }
                            // 检查用药后是否游戏结束
                            checkGameOver();
                        }
                        break;
                    default:
                        break;
                }
                return;
            }
            validIdx++;
        }
        
        cout << "无效的道具选择!" << endl;
    }

    // 随机获得道具
    void randomGetItem(vector<Item>& items, string owner) {
        int randItem = rand() % 7 + 1; // 1-7对应7种道具
        ItemType newType = static_cast<ItemType>(randItem);
        
        // 查找道具并增加数量
        bool found = false;
        for (auto& item : items) {
            if (item.type == newType) {
                item.count++;
                found = true;
                cout << "\n🎁 " << owner << "获得了【" << item.name << "】x1" << endl;
                break;
            }
        }
        
        if (!found) {
            // 新增道具(根据类型生成名称和描述)
            string name, desc;
            switch (newType) {
                case MAGNIFIER: name = "放大镜"; desc = "查看当前膛内子弹是实弹/空包弹"; break;
                case KNIFE: name = "小刀"; desc = "下一发实弹伤害×2(单局1次)"; break;
                case BEER: name = "啤酒"; desc = "退出当前膛内子弹,转到下一发"; break;
                case CIGARETTE: name = "香烟"; desc = "恢复1点生命值"; break;
                case HANDCUFF: name = "手铐"; desc = "对手下回合完全跳过"; break;
                case ADRENALINE: name = "肾上腺素"; desc = "偷对手1个道具并使用"; break;
                case EXPIRED_DRUG: name = "过期药物"; desc = "40%+2血/60%-1血"; break;
                default: return;
            }
            items.push_back(Item(newType, name, desc, 1));
            cout << "\n🎁 " << owner << "获得了新道具【" << name << "】x1" << endl;
        }
    }

    // 游戏结算界面
    void gameSettlement() {
        clearScreen();
        cout << "========================================" << endl;
        cout << "               游戏结算                " << endl;
        cout << "========================================" << endl;
        cout << "最终结果:" << (winner == "玩家" ? "🎉 你获胜了!" : "😈 你失败了!") << endl;
        cout << "失败原因:" << loseReason << endl;
        cout << "----------------------------------------" << endl;
        cout << "你的最终生命值:" << playerHP << "/5" << endl;
        cout << "恶魔最终生命值:" << devilHP << "/5" << endl;
        cout << "----------------------------------------" << endl;
        cout << "你的剩余道具:" << endl;
        for (auto& item : playerItems) {
            if (item.count > 0) {
                cout << "- " << item.name << " x" << item.count << endl;
            }
        }
        if (playerItems.empty()) {
            cout << "- 无" << endl;
        }
        cout << "========================================" << endl;
        cout << "\n⚠️  重要提示:本游戏仅为虚拟娱乐,现实中严禁模仿!" << endl;
    }

public:
    // 构造函数
    DevilRoulette() {
        srand(time(0));  // 初始化随机数种子
        initRoulette();
    }

    // 开始游戏
    void startGame() {
        // 游戏欢迎界面
        clearScreen();
        cout << "========================================" << endl;
        cout << "          【恶魔轮盘赌】原版游戏          " << endl;
        cout << "========================================" << endl;
        cout << "⚠️  重要提示:本游戏仅为虚拟娱乐," << endl;
        cout << "⚠️  现实中严禁模仿任何危险行为!" << endl;
        cout << "----------------------------------------" << endl;
        cout << "胜负规则:生命值降至0则失败,先耗尽HP者输!" << endl;
        cout << "初始生命值:玩家5点 | 恶魔5点" << endl;
        cout << "========================================" << endl;
        cout << "按任意键开始游戏..." << endl;
        cin.ignore();
        cin.get();
        clearScreen();

        string currentPlayer = "玩家";  // 当前开枪者
        int choice;                     // 玩家选择(1=朝自己,2=朝恶魔)
        int itemChoice;                 // 道具选择

        while (!isGameOver) {
            cout << "========================================" << endl;
            cout << "               回合开始                " << endl;
            cout << "========================================" << endl;
            cout << "当前枪膛:第" << (currentChamber + 1) << "膛" << endl;
            cout << "生命值:你 [" << playerHP << "/5] | 恶魔 [" << devilHP << "/5]" << endl;
            cout << "当前开枪者:" << currentPlayer << endl;

            if (currentPlayer == "玩家") {
                // 检查是否被手铐限制跳过回合
                if (playerSkipTurn) {
                    cout << "\n🔗 你被恶魔的手铐限制!本回合强制跳过!" << endl;
                    playerSkipTurn = false;
                    currentPlayer = "恶魔";
                    cout << "\n按任意键进入恶魔回合..." << endl;
                    cin.ignore();
                    cin.get();
                    clearScreen();
                    continue;
                }

                // 玩家回合:先选择是否使用道具
                showItems(playerItems, "玩家");
                cout << "请选择要使用的道具(输入序号):";
                cin >> itemChoice;

                // 验证道具输入
                int maxItemIdx = 0;
                for (auto& item : playerItems) {
                    if (item.count > 0 && !item.used) maxItemIdx++;
                }
                while (itemChoice < 0 || itemChoice > maxItemIdx) {
                    cout << "输入无效!请重新选择(0-" << maxItemIdx << "):";
                    cin >> itemChoice;
                }

                // 使用道具
                useItem(itemChoice, playerItems, devilItems, "玩家");

                // 检查使用道具后是否游戏结束
                if (isGameOver) break;

                // 选择开枪目标
                cout << "\n请选择开枪目标:" << endl;
                cout << "1. 朝自己开枪" << endl;
                cout << "2. 朝恶魔开枪" << endl;
                cout << "输入选择(1/2):";
                cin >> choice;

                // 验证输入
                while (choice != 1 && choice != 2) {
                    cout << "输入无效!请重新选择(1/2):";
                    cin >> choice;
                }

                cout << "\n你扣动了扳机...";

                // 执行开枪
                shoot("玩家", (choice == 1) ? "玩家" : "恶魔");
            } else {
                // 检查是否被手铐限制跳过回合
                if (devilSkipTurn) {
                    cout << "\n🔗 恶魔被你的手铐限制!本回合强制跳过!" << endl;
                    devilSkipTurn = false;
                    currentPlayer = "玩家";
                    cout << "\n按任意键进入你的回合..." << endl;
                    cin.ignore();
                    cin.get();
                    clearScreen();
                    continue;
                }

                // 恶魔回合
                cout << "\n😈 恶魔正在行动...";

                // 恶魔随机选择是否使用道具(30%概率)
                int useItemProb = rand() % 10;
                if (useItemProb < 3 && !devilItems.empty()) {
                    showItems(devilItems, "恶魔");
                    int devilItemChoice = rand() % devilItems.size() + 1;
                    useItem(devilItemChoice, devilItems, playerItems, "恶魔");
                    
                    // 检查恶魔使用道具后是否游戏结束
                    if (isGameOver) break;
                }

                // 恶魔随机选择开枪目标
                choice = rand() % 2 + 1;
                cout << "\n😈 恶魔选择朝" << (choice == 1 ? "自己" : "玩家") << "开枪!" << endl;
                cout << "恶魔扣动了扳机...";

                // 执行开枪
                shoot("恶魔", (choice == 1) ? "恶魔" : "玩家");
            }

            // 切换回合(游戏未结束时)
            if (!isGameOver) {
                currentPlayer = (currentPlayer == "玩家") ? "恶魔" : "玩家";
                cout << "\n按任意键进入下一回合..." << endl;
                cin.ignore();
                cin.get();
                clearScreen();
            }
        }

        // 游戏结算
        gameSettlement();
    }
};

int main() {
    char playAgain;
    do {
        DevilRoulette game;
        game.startGame();

        // 询问是否重来
        cout << "\n是否再来一局?(Y/N):";
        cin >> playAgain;
        while (playAgain != 'Y' && playAgain != 'y' && playAgain != 'N' && playAgain != 'n') {
            cout << "输入无效!请输入Y/N:";
            cin >> playAgain;
        }
    } while (playAgain == 'Y' || playAgain == 'y');

    cout << "\n感谢游玩【恶魔轮盘赌】,再见!" << endl;
    return 0;
}

0 条评论

目前还没有评论...