#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
using namespace std;
// 道具类型枚举
enum ItemType {
MEDKIT, // 医疗包:恢复1点生命
BULLET, // 子弹:使对方失去1点生命
INTERFERE, // 干扰器:改变对方概率
SHIELD // 护盾:抵挡下一次伤害
};
// 道具结构体
struct Item {
ItemType type;
string name;
string effect;
};
const Item ITEMS[] = {
{MEDKIT, "医疗包", "恢复1点生命"},
{BULLET, "子弹", "使对方失去1点生命"},
{INTERFERE, "干扰器", "改变对方下一轮的概率"},
{SHIELD, "能量护盾", "抵挡下一次伤害"}
};
void printItem(const Item& item) {
cout << "[" << item.name << "] " << item.effect;
}
int main() {
srand(time(0));
int playerLives = 3;
int computerLives = 3;
int currentRound = 1;
float computerProb = 1.0/6; // 电脑中弹概率
bool playerShield = false;
bool computerShield = false;
vector<ItemType> playerItems;
vector<ItemType> computerItems;
cout << "===== 文字轮盘赌 =====" << endl;
cout << "新增道具系统:" << endl;
cout << "1. 安全射击后30%概率获得随机道具" << endl;
cout << "2. 道具可以对自己或敌人使用" << endl;
cout << "3. 道具类型:" << endl;
cout << "===========================" << endl;
while (playerLives > 0 && computerLives > 0) {
cout << "\n=== 第 " << currentRound << " 回合 ===" << endl;
cout << "玩家生命: " << playerLives << " | 电脑生命: " << computerLives << endl;
// 玩家回合
cout << "\n[玩家回合]";
cout << "\n可用道具 (" << playerItems.size() << "/3):" << endl;
for(int i=0; i<playerItems.size(); ++i){
cout << i+1 << ". ";
printItem(ITEMS[playerItems[i]]);
cout << endl;
}
int choice;
while(true){
cout << "选择操作 (1-扣动扳机 2-使用道具): ";
cin >> choice;
if(choice ==1 || choice ==2) break;
cout << "无效输入!";
}
if(choice == 1){ // 扣动扳机
cout << "扣动扳机...按回车继续";
cin.ignore();
cin.get();
int result = rand()%6 +1;
if(result ==1){
if(computerShield){
cout << "电脑的护盾抵挡了伤害!" << endl;
computerShield = false;
}else{
cout << "砰!你击中了电脑!" << endl;
computerLives--;
}
}else{
cout << "咔嗒... 安全!" << endl;
// 30%概率获得道具
if(rand()%100 <30 && playerItems.size()<3){
ItemType newItem = static_cast<ItemType>(rand()%4);
playerItems.push_back(newItem);
cout << "获得道具: ";
printItem(ITEMS[newItem]);
cout << endl;
}
}
}
else { // 使用道具
if(playerItems.empty()){
cout << "没有可用道具!自动转为射击" << endl;
}
else{
int itemIndex;
while(true){
cout << "选择道具 (1-" << playerItems.size() << "): ";
cin >> itemIndex;
if(itemIndex>=1 && itemIndex<=playerItems.size()) break;
cout << "无效选择!";
}
int target;
while(true){
cout << "选择目标 (1-自己 2-对方): ";
cin >> target;
if(target==1 || target==2) break;
cout << "无效目标!";
}
ItemType usedItem = playerItems[itemIndex-1];
playerItems.erase(playerItems.begin()+itemIndex-1);
cout << "使用 ";
printItem(ITEMS[usedItem]);
cout << endl;
switch(usedItem){
case MEDKIT:
playerLives = min(3, playerLives+1);
break;
case BULLET:
if(target ==1) playerLives--;
else computerLives--;
break;
case INTERFERE:
computerProb = (rand()%3+1)/10.0; // 随机改为10%-30%
cout << "电脑中弹概率变为 " << computerProb*100 << "%" << endl;
break;
case SHIELD:
(target==1 ? playerShield : computerShield) = true;
break;
}
}
}
if (playerLives <=0 || computerLives <=0) break;
// 电脑回合
cout << "\n[电脑回合] 电脑正在行动...";
cin.ignore();
cin.get();
// 电脑AI:有道具时30%概率使用
if(!computerItems.empty() && rand()%100 <30){
int itemIndex = rand()%computerItems.size();
ItemType usedItem = computerItems[itemIndex];
computerItems.erase(computerItems.begin()+itemIndex);
int target = rand()%2+1; // 随机选择目标
if(usedItem == MEDKIT) target =1; // 医疗包只能对自己用
cout << "电脑使用 ";
printItem(ITEMS[usedItem]);
cout << endl;
switch(usedItem){
case MEDKIT:
computerLives = min(3, computerLives+1);
break;
case BULLET:
if(target ==1) computerLives--;
else playerLives--;
break;
case INTERFERE:
computerProb = 1.0/6; // 重置概率
cout << "概率恢复正常" << endl;
break;
case SHIELD:
(target==1 ? computerShield : playerShield) = true;
break;
}
}
else { // 正常射击
cout << "电脑扣动扳机..." << endl;
if((rand()%100) < computerProb*100){
if(playerShield){
cout << "你的护盾抵挡了伤害!" << endl;
playerShield = false;
}else{
cout << "砰!电脑击中了你!" << endl;
playerLives--;
}
}else{
cout << "咔嗒... 电脑安全" << endl;
// 电脑获得道具
if(rand()%100 <30 && computerItems.size()<3){
ItemType newItem = static_cast<ItemType>(rand()%4);
computerItems.push_back(newItem);
}
}
}
currentRound++;
}
// 游戏结果(保持不变)
cout << "\n=== 游戏结束 ===" << endl;
if (playerLives <=0 && computerLives <=0) {
cout << "平局!" << endl;
} else if (playerLives <=0) {
cout << "电脑获胜!" << endl;
} else {
cout << "玩家获胜!" << endl;
}
return 0;
}