双人恶魔轮盘赌(注释版)(已完结)
2025-07-12 19:59:21
发布于:香港
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
#define endl '\n'
void clear() {
system("cls");
} // 清屏
string prop_randomlist[4] = {"烟盒", "放大镜", "放大镜", "酒"}; // 道具随机列表
int choose; // 每轮使用的道具
int shoot; // 开枪对象
int times; // 进行轮数
bool isreal; // 发射子弹是否为真弹
bool flag; // 是否有人胜利
struct Player {
vector <string> prop; // 道具
queue <bool> gun; // 枪
string name; // 姓名
int hp; // 血量
} player[3]; // 共两名玩家,player[0]废弃
void read_name() { // 名字输入
cout << "玩家 1, 请输入您的名字" << endl;
cin >> player[1].name;
clear();
cout << "玩家 2, 请输入您的名字" << endl;
cin >> player[2].name;
clear();
}
void prop_random() {
// 清空道具槽
if (times > 1) for (int i = 0; i < 4; i++) {
player[1].prop.pop_back();
player[2].prop.pop_back();
} for (int i = 0; i < 4; i++) { // 压入 4 个随机道具
int p1_prop = rand() % 4;
int p2_prop = rand() % 4;
player[1].prop.push_back(prop_randomlist[p1_prop]);
player[2].prop.push_back(prop_randomlist[p2_prop]);
}
}
void gun_random() {
// 清空弹夹
while (!player[1].gun.empty()) player[1].gun.pop();
while (!player[2].gun.empty()) player[2].gun.pop();
for (int i = 0; i < 5; i++) { // 压入随机子弹(最多退 4 发,压入 5 颗)
int p1_gun = rand() % 3;
int p2_gun = rand() % 3;
if (!p1_gun) player[1].gun.push(1);
else player[1].gun.push(0);
if (!p2_gun) player[2].gun.push(1);
else player[2].gun.push(0);
}
}
bool isvictory() {
if (player[1].hp > 0 && player[2].hp > 0) return 0; // 均存活
if (player[1].hp == 0) { // 玩家 1 阵亡
clear();
cout << player[2].name << "胜利!!!";
Sleep(5000);
clear;
return 1;
} else { // 玩家 2 阵亡
clear();
cout << player[1].name << "胜利!!!";
Sleep(5000);
clear;
return 1;
}
}
void init() { // 游戏介绍
int read;
player[1].hp = player[2].hp = 5;
do {
clear();
cout << "俄罗斯轮盘赌" << endl;
cout << "游戏规则" << endl;
cout << "每轮可开 1 次枪,使用至多 4 次道具" << endl;
cout << "开枪实空随机,实枪概率 1/3 , 空枪概率 2/3" << endl;
cout << "道具介绍:" << endl;
cout << "烟盒:可增加 1 hp" << endl;
cout << "放大镜:可查看即将发射的子弹为实弹或空弹" << endl;
cout << "酒:退一发即将发射的子弹,并知晓子弹为实弹或空弹" << endl;
cout << "知晓完成请输入 1" << endl;
cin >> read;
} while (read != 1);
}
void player_print(int i) { // 道具使用的前置输出
clear();
cout << "第 " << times << " 轮次" << endl;
cout << player[i].name << endl;
cout << "血量为" << player[1].name << " : " << player[1].hp << "点血量" << " / " << player[2].name << " : " << player[2].hp << "点血量" << endl;
cout << endl;
cout << "道具:" << endl;
for (int ind = 0; ind < 4; ind++) cout << player[i].prop[ind] << " ";
cout << endl;
cout << "使用哪个道具? (1 ~ 4, 开枪请输入 0)" << endl;
}
void prop_1(int i) { // 使用 放大镜
cout << "该子弹为" << (player[i].gun.front() ? "实弹" : "空弹");
player[i].prop[choose] = "无";
Sleep(1000);
player_print(i);
}
void prop_2(int i) { // 使用 烟盒
player[i].hp++;
cout << "血量加 1" << endl;
player[i].prop[choose] = "无";
Sleep(1000);
player_print(i);
}
void prop_3(int i) { // 使用 酒
cout << "退下的子弹为" << (player[i].gun.front() ? "实弹" : "空弹");
player[i].gun.pop();
player[i].prop[choose] = "无";
Sleep(1000);
player_print(i);
}
int rev(int i) { // 反转(然并卵
if (i == 1) return 2;
else return 1;
}
void gun_shoot(int i) { // 开枪 + 胜利判定
clear();
cout << "第 " << times << " 轮次" << endl;
cout << player[i].name << " ";
cout << "对谁开枪? (自己选 0, 对方选 1)" << endl;
cin >> shoot; // 获取开枪对象
cout << "该子弹为" << (player[i].gun.front() ? "实弹" : "空弹");
isreal = player[i].gun.front();
player[i].gun.pop();
if (!shoot) player[i].hp -= isreal;
else player[rev(i)].hp -= isreal;
// 射击 + 造成伤害
Sleep(1000);
flag = isvictory(); // 胜利判定
clear();
}
void play(int i) { // 每轮游戏
player_print(i); // 前置输出
cin >> choose;
while (choose != 0) {
choose--; // 处理(变为下标)
string choose_prop = player[i].prop[choose]; // 使用道具
if (choose_prop == "放大镜") prop_1(i);
else if (choose_prop == "烟盒") prop_2(i);
else if (choose_prop == "酒") prop_3(i);
cin >> choose;
} gun_shoot(i);
}
void every_init() { // 每轮初始化
times++;
cout << "第 " << times << " 轮次" << endl;
cout << "分配道具和子弹中......" << endl;
prop_random(); gun_random(); // 分配
Sleep(2000);
}
void game() { // 正经游戏
init(); clear(); read_name();
while (1) {
every_init();
play(1);
if (flag) return ;
play(2);
if (flag) return ;
}
}
int main() {
srand(time(0));
game();
return 0;
}
/*
完结撒花!!!
完结撒花!!!
*/
这里空空如也
有帮助,赞一个