当前位置: 首页 > 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.lryc.cn/news/610703.html

相关文章:

  • Java Date类介绍
  • 前端保持和服务器时间同步的方法【使用vue3举例】
  • 利用m0改造循迹模块处理笔记00
  • 强光干扰下误报率↓82%!陌讯多模态融合算法在火焰识别的落地优化
  • 服务器数据恢复—坏道致Raid5阵列硬盘离线如何让数据重生?
  • Linux 系统启动原理2
  • 2025年服务器漏洞生存指南:从应急响应到长效免疫的实战框架
  • Pandas query() 方法详解
  • 防水防尘防摔性能很好的智能三防手机,还有22000mAh大电池
  • 手机通话检测数据集介绍-3,100 张图片 智能监控系统 驾驶安全监控
  • 联发科芯片组曝高危漏洞:越界写入缺陷危及智能手机与物联网设备安全
  • Tasks and Deadlines(Sorting and Searching)
  • 云手机和实体手机之间的区别
  • 【springcloud的配置文件不生效】
  • AI的第一次亲密接触——你的手机相册如何认出你的猫?
  • 深入浅出 RabbitMQ-交换机详解与发布订阅模型实战
  • 华为云云产品的发展趋势:技术创新驱动数字化未来
  • 查看部署在K8S服务的资源使用情况
  • 蓝桥杯----DS1302实时时钟
  • Could not load the Qt platform plugin “xcb“ in “无法调试与显示Opencv
  • 【升级打怪实录】uniapp - android 静态声明权限和动态请求权限的区别
  • AI+OA原生应用 麦当秀AIPPT
  • 用 PyTorch 实现一个简单的神经网络:从数据到预测
  • lesson32:Pygame模块详解:从入门到实战的2D游戏开发指南
  • 阿里云招Java研发咯
  • day 46 神经网络-简版
  • 从零用java实现小红书springboot_vue_uniapp(15)评论和im添加图片
  • vue和react的框架原理
  • Elasticsearch向量库
  • React18 严格模式下的双重渲染之谜