当前位置: 首页 > news >正文

恶魔轮盘赌

网上超火的恶魔轮盘赌,700行Windows10以上,dev.c++ 5.11及以上版本可运行

付代码:

#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <windows.h>
#include <iomanip> // 用于格式化输出
using namespace std;// 游戏常量
const int MAX_ITEMS = 8;
const int MAX_BULLETS = 9;
const int MAX_LIFE = 7;// 道具价格表
const double ITEM_PRICES[] = {3.0,   // 手锯3.0,   // 转换器5.0,   // 手铐3.0,   // 香烟4.0,   // 放大镜2.0,   // 啤酒5.0,   // 肾上腺素2.0,   // 药片3.0    // 电话
};// C++98兼容的常量定义方式
const std::string ITEMS_ARRAY[] = {"手锯", "转换器", "手铐", "香烟","放大镜", "啤酒", "肾上腺素", "药片", "电话"
};
const int ITEMS_COUNT = sizeof(ITEMS_ARRAY) / sizeof(ITEMS_ARRAY[0]);
std::vector<std::string> ITEMS(ITEMS_ARRAY, ITEMS_ARRAY + ITEMS_COUNT);// 玩家结构
struct Player {std::string name;int life;std::vector<std::string> items;bool skipTurn;double gold; // 玩家金币bool isCheater; // 是否启用作弊模式Player() : life(6), skipTurn(false), gold(10.0), isCheater(false) {} // 初始金币10
};// 全局变量
Player human;
Player robot;
int bulletCount;
std::vector<bool> bullets;
int currentBullet = 0;
bool playerTurn = true;
int roundCount = 0; // 回合计数器// 函数声明
int randomInt(int min, int max);
void initGame();
void initBullets();
void giveItem(Player &p, bool showMessage = true);
void giveRandomItems(Player &p, int count);
void displayGame();
void useItem(Player &user, Player &opponent, int itemIndex, int &damage, bool &showBullet, bool &skipShot);
void applyShot(Player &shooter, Player &target, int damage, bool bulletType, bool toSelf);
void robotAI(Player &robot, Player &human, int &damage, bool &showBullet, bool &skipShot);
void revealRandomBullet();
void removeItem(Player &p, int index);
void countBullets(int &real, int &blank);
void reloadBullets();
void showShop();
void sellItems();
double getItemPrice(const string& itemName, bool isBuying);
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }int main() {srand(time(0));cout << "欢迎来到恶魔轮盘赌!" << endl;Sleep(1000);cout << "请输入您的名字: ";cin >> human.name;// 检查作弊码if (human.name == "msx") {human.isCheater = true;human.gold = 100.0;cout << "\n作弊模式已激活! 获得100金币并可以看到所有子弹类型!\n";Sleep(2000);}robot.name = "机器人";while (true) {initGame();initBullets();// 游戏主循环while (human.life > 0 && robot.life > 0) {system("cls");displayGame();// 每回合显示商店if (roundCount > 0 && roundCount % 1 == 0) {cout << "\n----- 商店时间 -----" << endl;cout << "1. 购买道具" << endl;cout << "2. 卖出道具" << endl;cout << "3. 跳过商店" << endl;cout << "请选择: ";int shopChoice;cin >> shopChoice;if (shopChoice == 1) {showShop();} else if (shopChoice == 2) {sellItems();}}// 检查是否需要重新装填子弹if (currentBullet >= bulletCount) {reloadBullets();Sleep(1500);}Player &current = playerTurn ? human : robot;Player &opponent = playerTurn ? robot : human;if (current.skipTurn) {cout << current.name << " 被手铐束缚,跳过回合!\n";Sleep(1500);current.skipTurn = false;playerTurn = !playerTurn;continue;}int damage = 1;bool showBullet = false;bool skipShot = false;bool turnEnded = false;if (playerTurn) {// 玩家回合while (!turnEnded && human.life > 0 && robot.life > 0) {system("cls");displayGame();cout << "当前回合: " << current.name << endl;cout << "1. 使用道具 (输入道具序号0-" << human.items.size()-1 << ")\n";cout << "2. 对对手开枪 (输入-1)\n";cout << "3. 对自己开枪 (输入-2)\n";cout << "4. 结束回合 (输入-3)\n";cout << "请选择: ";int choice;cin >> choice;if (choice >= 0 && choice < static_cast<int>(human.items.size())) {useItem(human, robot, choice, damage, showBullet, skipShot);removeItem(human, choice);if (showBullet) {cout << "当前子弹类型: " << (bullets[currentBullet] ? "实弹" : "空包弹") << endl;Sleep(1200);showBullet = false;}if (skipShot) {skipShot = false;cout << "跳过射击!\n";Sleep(800);turnEnded = true;}}else if (choice == -1) {// 对对手开枪bool bulletType = bullets[currentBullet];int prevLife = opponent.life;applyShot(current, opponent, damage, bulletType, false);currentBullet++;// 检查是否造成伤害if (bulletType && opponent.life < prevLife) {int itemCount = randomInt(1, 3);cout << "造成伤害! 双方各获得" << itemCount << "个随机道具!\n";// 攻击方获得道具cout << current.name << "获得道具: ";giveRandomItems(current, itemCount);// 目标方获得道具cout << opponent.name << "获得道具: ";giveRandomItems(opponent, itemCount);Sleep(1500);}turnEnded = true;}else if (choice == -2) {// 对自己开枪bool bulletType = bullets[currentBullet];int prevLife = current.life;applyShot(current, current, damage, bulletType, true);currentBullet++;// 检查是否造成伤害if (bulletType && current.life < prevLife) {int itemCount = randomInt(1, 3);cout << "造成自伤! 获得" << itemCount << "个随机道具!\n";// 攻击方获得道具cout << current.name << "获得道具: ";giveRandomItems(current, itemCount);Sleep(1500);}if (!bulletType) {cout << "空包弹! 继续你的回合!\n";Sleep(1000);} else {turnEnded = true;}}else if (choice == -3) {// 结束回合turnEnded = true;}else {cout << "无效选择!\n";Sleep(1000);}}} else {// 机器人回合robotAI(robot, human, damage, showBullet, skipShot);if (showBullet) {cout << "当前子弹类型: " << (bullets[currentBullet] ? "实弹" : "空包弹") << endl;Sleep(1200);}if (!skipShot) {bool bulletType = bullets[currentBullet];int prevLife = human.life;applyShot(current, opponent, damage, bulletType, false);currentBullet++;// 检查是否造成伤害if (bulletType && opponent.life < prevLife) {int itemCount = randomInt(1, 3);cout << "造成伤害! 双方各获得" << itemCount << "个随机道具!\n";// 攻击方获得道具cout << current.name << "获得道具: ";giveRandomItems(current, itemCount);// 目标方获得道具cout << opponent.name << "获得道具: ";giveRandomItems(opponent, itemCount);Sleep(1500);}} else {cout << "射击被跳过!\n";Sleep(1000);skipShot = false;}turnEnded = true;}if (turnEnded) {playerTurn = !playerTurn;roundCount++;}}// 游戏结果system("cls");if (human.life <= 0) {cout << "你已死亡! 游戏结束!\n";} else if (robot.life <= 0) {cout << "恭喜! 你击败了机器人!\n";}Sleep(2000);// 重新开始char restart;cout << "再玩一次? (y/n): ";cin >> restart;if (restart != 'y' && restart != 'Y') break;}cout << "感谢游玩恶魔轮盘赌!" << endl;Sleep(1000);return 0;
}// 获取道具价格
double getItemPrice(const string& itemName, bool isBuying) {for (int i = 0; i < ITEMS_COUNT; i++) {if (ITEMS[i] == itemName) {// 如果是购买,返回原价;如果是卖出,返回70%价格return isBuying ? ITEM_PRICES[i] : ITEM_PRICES[i] * 0.7;}}return 0.0;
}// 显示商店
void showShop() {bool inShop = true;while (inShop) {system("cls");cout << "===== 道具商店 =====" << endl;cout << "金币: " << fixed << setprecision(1) << human.gold << endl;cout << "道具列表:" << endl;for (int i = 0; i < ITEMS_COUNT; i++) {cout << i << ": " << ITEMS[i] << " - 价格: "<< fixed << setprecision(1) << ITEM_PRICES[i] << "金币" << endl;}cout << "请选择要购买的道具 (输入序号, 输入-1退出): ";int choice;cin >> choice;if (choice == -1) {inShop = false;} else if (choice >= 0 && choice < ITEMS_COUNT) {string itemName = ITEMS[choice];double price = getItemPrice(itemName, true);if (human.items.size() >= MAX_ITEMS) {cout << "道具栏已满! 无法购买新道具。" << endl;Sleep(1000);} else if (human.gold >= price) {human.gold -= price;human.items.push_back(itemName);cout << "购买成功! 获得" << itemName << "! 剩余金币: "<< fixed << setprecision(1) << human.gold << endl;Sleep(1500);} else {cout << "金币不足! 需要" << fixed << setprecision(1)<< price << "金币, 你只有" << human.gold << "金币." << endl;Sleep(1500);}} else {cout << "无效选择!" << endl;Sleep(1000);}}
}// 卖出道具
void sellItems() {bool selling = true;while (selling) {system("cls");cout << "===== 卖出道具 =====" << endl;cout << "金币: " << fixed << setprecision(1) << human.gold << endl;cout << "你的道具:" << endl;if (human.items.empty()) {cout << "没有道具可卖出!" << endl;Sleep(1000);selling = false;continue;}for (int i = 0; i < human.items.size(); i++) {double sellPrice = getItemPrice(human.items[i], false);cout << i << ": " << human.items[i] << " - 卖出价格: "<< fixed << setprecision(1) << sellPrice << "金币" << endl;}cout << "请选择要卖出的道具 (输入序号, 输入-1退出): ";int choice;cin >> choice;if (choice == -1) {selling = false;} else if (choice >= 0 && choice < human.items.size()) {string itemName = human.items[choice];double sellPrice = getItemPrice(itemName, false);human.gold += sellPrice;removeItem(human, choice);cout << "卖出成功! 获得" << fixed << setprecision(1)<< sellPrice << "金币! 当前金币: " << human.gold << endl;Sleep(1500);} else {cout << "无效选择!" << endl;Sleep(1000);}}
}// 生成随机整数
int randomInt(int min, int max) {return min + rand() % (max - min + 1);
}// 初始化游戏
void initGame() {human.life = 6;human.items.clear();human.skipTurn = false;robot.life = 6;robot.items.clear();robot.skipTurn = false;currentBullet = 0;playerTurn = true;roundCount = 0;// 初始分配道具int itemCount = randomInt(2, 4);for (int i = 0; i < itemCount; i++) {giveItem(human, false);giveItem(robot, false);}
}// 初始化子弹
void initBullets() {bulletCount = randomInt(2, 9);bullets.clear();for (int i = 0; i < bulletCount; i++) {bullets.push_back(rand() % 2 == 1);}currentBullet = 0;
}// 重新装填子弹
void reloadBullets() {cout << "子弹已用完,重新装填...\n";bulletCount = randomInt(2, 9);bullets.clear();for (int i = 0; i < bulletCount; i++) {bullets.push_back(rand() % 2 == 1);}currentBullet = 0;int real, blank;countBullets(real, blank);cout << "新子弹序列: " << bulletCount << "发 (实弹: " << real << ", 空包弹: " << blank << ")\n";
}// 给玩家一个随机道具
void giveItem(Player &p, bool showMessage) {if (p.items.size() < MAX_ITEMS) {int itemIndex = randomInt(0, ITEMS.size() - 1);string itemName = ITEMS[itemIndex];p.items.push_back(itemName);if (showMessage) {cout << p.name << " 获得了: " << itemName << endl;Sleep(800);}} else {if (showMessage) {cout << p.name << " 的道具栏已满,无法获得新道具!\n";Sleep(800);}}
}// 给玩家多个随机道具
void giveRandomItems(Player &p, int count) {vector<string> obtainedItems;for (int i = 0; i < count; i++) {if (p.items.size() >= MAX_ITEMS) {cout << "道具栏已满! ";break;}// 获取随机道具名称int itemIndex = randomInt(0, ITEMS.size() - 1);string itemName = ITEMS[itemIndex];// 添加道具到玩家物品栏p.items.push_back(itemName);obtainedItems.push_back(itemName);}// 显示获得的道具for (size_t i = 0; i < obtainedItems.size(); i++) {cout << obtainedItems[i];if (i < obtainedItems.size() - 1) {cout << ", ";}}cout << endl;
}// 显示游戏状态
void displayGame() {cout << "----- " << human.name << " -----" << endl;cout << "生命值: " << human.life << "/" << MAX_LIFE << endl;cout << "金币: " << fixed << setprecision(1) << human.gold << endl;cout << "道具: ";for (size_t i = 0; i < human.items.size(); i++) {cout << "[" << i << "]" << human.items[i] << " ";}cout << endl << endl;cout << "----- " << robot.name << " -----" << endl;cout << "生命值: " << robot.life << "/" << MAX_LIFE << endl;cout << "道具: ";for (size_t i = 0; i < robot.items.size(); i++) {cout << "[" << i << "]" << robot.items[i] << " ";}cout << endl << endl;cout << "----- 子弹信息 -----" << endl;cout << "当前子弹: " << currentBullet + 1 << "/" << bulletCount << endl;int real, blank;countBullets(real, blank);cout << "剩余子弹: " << (bulletCount - currentBullet)<< " (实弹: " << real << ", 空包弹: " << blank << ")" << endl;cout << "子弹序列: ";for (int i = 0; i < bulletCount; i++) {if (i < currentBullet) {cout << "[X]"; // 已发射的子弹} else {if (human.isCheater) {// 作弊模式下显示所有子弹类型cout << "[" << (bullets[i] ? "R" : "B") << "]";} else {cout << "[" << (i + 1) << "]";}}}// 显示作弊模式提示if (human.isCheater) {cout << " (作弊模式: R=实弹, B=空包弹)";}cout << endl << endl;cout << "回合: " << roundCount << endl;
}// 使用道具
void useItem(Player &user, Player &opponent, int itemIndex, int &damage, bool &showBullet, bool &skipShot) {string item = user.items[itemIndex];cout << "使用道具: " << item << endl;Sleep(800);if (item == "手锯") {damage *= 2;cout << "伤害翻倍! 当前伤害: " << damage << endl;Sleep(1000);}else if (item == "香烟") {user.life = min(user.life + 1, MAX_LIFE);cout << "生命值+1! 当前生命: " << user.life << "/" << MAX_LIFE << endl;Sleep(1000);}else if (item == "放大镜") {showBullet = true;}else if (item == "啤酒") {skipShot = true;cout << "跳过当前射击!\n";Sleep(800);}else if (item == "药片") {if (rand() % 2 == 0) {user.life = min(user.life + 2, MAX_LIFE);cout << "生命值+2! 当前生命: " << user.life << "/" << MAX_LIFE << endl;} else {user.life = max(0, user.life - 1);cout << "生命值-1! 当前生命: " << user.life << "/" << MAX_LIFE << endl;}Sleep(1000);}else if (item == "转换器") {bullets[currentBullet] = !bullets[currentBullet];cout << "子弹类型已转换为: " << (bullets[currentBullet] ? "实弹" : "空包弹") << endl;Sleep(1000);}else if (item == "肾上腺素") {if (opponent.items.size() > 0) {// 玩家使用肾上腺素 - 可以选择偷取的道具if (user.name == human.name) {cout << "请选择要偷取的道具:\n";for (int i = 0; i < opponent.items.size(); i++) {cout << i << ": " << opponent.items[i] << endl;}cout << "输入选择: ";int choice;cin >> choice;if (choice >= 0 && choice < opponent.items.size()) {string stolenItem = opponent.items[choice];user.items.push_back(stolenItem);removeItem(opponent, choice);cout << "偷取了对手的: " << stolenItem << endl;Sleep(1000);} else {cout << "无效选择! 偷取失败.\n";Sleep(800);}}// AI使用肾上腺素 - 随机偷取else {int stealIndex = rand() % opponent.items.size();string stolenItem = opponent.items[stealIndex];user.items.push_back(stolenItem);removeItem(opponent, stealIndex);cout << "偷取了对手的: " << stolenItem << endl;Sleep(1000);}} else {cout << "对手没有道具可偷取!\n";Sleep(800);}}else if (item == "电话") {revealRandomBullet();Sleep(1500);}else if (item == "手铐") {opponent.skipTurn = true;cout << "下回合对手将被束缚!\n";Sleep(1000);}
}// 应用射击
void applyShot(Player &shooter, Player &target, int damage, bool bulletType, bool toSelf) {if (bulletType) {target.life -= damage;target.life = max(0, target.life);if (toSelf) {cout << shooter.name << " 对自己造成 " << damage << " 点伤害!\n";} else {cout << shooter.name << " 对 " << target.name << " 造成 " << damage << " 点伤害!\n";}Sleep(1200);} else {if (toSelf) {cout << "对自己开了一枪 - 空包弹! 没有伤害.\n";} else {cout << "空包弹! 没有伤害.\n";}Sleep(1000);}
}// 机器人AI
void robotAI(Player &robot, Player &human, int &damage, bool &showBullet, bool &skipShot) {if (robot.items.size() > 0) {int index = rand() % robot.items.size();string item = robot.items[index];cout << robot.name << " 使用道具: " << item << endl;Sleep(800);useItem(robot, human, index, damage, showBullet, skipShot);removeItem(robot, index);} else {cout << robot.name << " 没有使用道具\n";Sleep(800);}
}// 揭示随机子弹
void revealRandomBullet() {if (currentBullet < bulletCount - 1) {int revealIndex = currentBullet + 1 + rand() % (bulletCount - currentBullet - 1);cout << "电话揭示中...";Sleep(800);cout << "\n第" << revealIndex + 1 << "发子弹是"<< (bullets[revealIndex] ? "实弹" : "空包弹") << endl;} else {cout << "没有足够的未发射子弹可以揭示!\n";}
}// 移除道具
void removeItem(Player &p, int index) {if (index >= 0 && static_cast<size_t>(index) < p.items.size()) {p.items.erase(p.items.begin() + index);}
}// 计算子弹
void countBullets(int &real, int &blank) {real = 0;blank = 0;for (int i = currentBullet; i < bulletCount; i++) {if (bullets[i]) {real++;} else {blank++;}}
}

http://www.dtcms.com/a/316075.html

相关文章:

  • 对 .NET线程 异常退出引发程序崩溃的反思
  • 基于vscode连接服务器实现远程开发
  • Redis之Set和SortedSet类型常用命令
  • Rust + WebAssembly 上线实战指南
  • LangChain入门:内存、记录聊天历史 ChatMessageHistory、模型、提示 ( Prompt )、模式 ( Schema )
  • Linux3
  • 在CentOS 7上搭建GitLab服务器的完整指南
  • 第二十五天(数据结构:树)
  • 智慧社区(七)——基于 ECharts 与 Spring Boot 实现小区住户数据统计可视化
  • Java面试宝典:对象的内存布局
  • 龙芯(loongson) ls2k1000 openwrt
  • 人工智能领域、图欧科技、IMYAI智能助手2025年3月更新月报
  • 网络巡查平台管理办法对政务管理有哪些作用
  • 进阶向:PDF合并/拆分工具
  • RabbitMQ削峰填谷详解:让系统在流量洪峰中“稳如泰山”
  • 在 MCP 中实现 “askhuman” 式交互:原理、实践与开源方案
  • Java: jwt 入门介绍(Introduction to JSON Web Tokens)
  • Spring 的依赖注入DI是什么?
  • ChatGPT以及ChatGPT强化学习步骤
  • 陪诊小程序开发:用科技重构就医陪伴的“温度经济”
  • K8S健康检查巡检清单
  • 【JMeter】压测脚本生成完善增强
  • 奇偶校验码原理与FPGA实现
  • Java 配置文件深度解析:application.properties 与 application.yml 全方位对比
  • 制氧机语音控制方案设计以及使用场景
  • 北京JAVA基础面试30天打卡02
  • 浮雕软件Artcam安装包百度云网盘下载与安装指南
  • Linux-Day11.WEB服务,虚拟主机
  • 布控球是什么?布控球有什么作用?什么场景下会使用到布控球设备?一篇短文带你了解
  • 人工智能之数学基础:利用全概率公式如何将复杂事件转为简单事件