#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <cstdlib>
#include <thread>
#include <chrono>
#include <iomanip>
using namespace std;
// --- 游戏配置 ---
const string MAP_NAME = "零号大坝";
const string FACTION = "G.T.I.特勤组";
// --- 物品结构体(增强:类型、重量、可使用) ---
struct Item {
string name;
int value;
string rarity;
string type; // 物资/医疗/武器/护甲
bool usable; // 是否可使用
};
// --- 干员类(大幅增强) ---
class Operator {
public:
string name;
int health;
int maxHealth;
int armorLevel; // 护甲等级 1~6
int weaponDamage; // 武器伤害
int energy; // 体力:奔跑、搜索、战斗都会消耗
int maxEnergy;
vector<Item> backpack;
int backpackCapacity;
int totalWealth;
int level; // 干员等级
int exp; // 经验值
int luck; // 幸运值:影响掉落品质
bool hasShield; // 是否持有临时护盾
// 构造函数
Operator(string n)
: name(n), health(110), maxHealth(110), armorLevel(3),
weaponDamage(28), energy(100), maxEnergy(100),
backpackCapacity(6), totalWealth(0), level(1), exp(0), luck(5), hasShield(false) {}
// 显示状态(更美观)
void showStatus() {
cout << "\n==================== 干员状态 ===================" << endl;
cout << left << setw(12) << "代号:" << name
<< " | 阵营:" << FACTION
<< " | Lv." << level << " 经验:" << exp << "/50" << endl;
cout << left << setw(12) << "生命:" << health << "/" << maxHealth
<< " | 护甲: Lv." << armorLevel
<< " | 体力:" << energy << "/" << maxEnergy << endl;
cout << left << setw(12) << "武器伤害:" << weaponDamage
<< " | 幸运值:" << luck
<< " | 护盾:" << (hasShield ? "已激活" : "无") << endl;
cout << left << setw(12) << "背包:" << backpack.size() << "/" << backpackCapacity
<< " | 总资产:" << totalWealth << " 哈夫克币" << endl;
cout << "=================================================" << endl;
}
// 拾取物品
bool lootItem(Item item) {
if (backpack.size() < backpackCapacity) {
backpack.push_back(item);
cout << "\n[拾取] " << "[" << item.rarity << "] " << item.name
<< " | 价值:" << item.value << endl;
return true;
} else {
cout << "\n[背包] 已满,无法拾取!" << endl;
return false;
}
}
// 使用物品(医疗包、护甲包、护盾电池)
void useItem(int index) {
if (index < 0 || index >= backpack.size()) {
cout << "[错误] 无效物品位置!" << endl;
return;
}
Item& item = backpack[index];
if (!item.usable) {
cout << "[使用] " << item.name << " 无法使用!" << endl;
return;
}
if (item.type == "医疗") {
int heal = 35;
health = min(maxHealth, health + heal);
cout << "[治疗] 使用 " << item.name << ",恢复 " << heal << " 点生命值!" << endl;
}
else if (item.type == "护甲") {
armorLevel = min(6, armorLevel + 1);
cout << "[强化] 护甲等级提升至 Lv." << armorLevel << "!" << endl;
}
else if (item.type == "护盾") {
hasShield = true;
cout << "[护盾] 临时护盾已激活!下次受伤免疫!" << endl;
}
backpack.erase(backpack.begin() + index);
}
// 丢弃物品
void dropItem(int index) {
if (index < 0 || index >= backpack.size()) {
cout << "[错误] 无效位置!" << endl;
return;
}
cout << "[丢弃] 丢失了 " << backpack[index].name << endl;
backpack.erase(backpack.begin() + index);
}
// 战斗系统(增强:护盾、等级、随机事件)
bool combat(vector<string> enemies) {
cout << "\n=====================================" << endl;
cout << "!!! 遭遇战斗 - 敌对势力入侵 !!!" << endl;
for (auto& e : enemies) cout << " - " << e << endl;
cout << "=====================================" << endl;
int enemyCount = enemies.size();
int enemyPower = enemyCount * (22 + rand() % 10);
int myPower = weaponDamage + (armorLevel * 6) + (level * 3);
this_thread::sleep_for(chrono::milliseconds(800));
int random = rand() % 25 - 12;
int result = myPower + random - enemyPower;
// 护盾免疫伤害
if (hasShield) {
cout << "\n[护盾] 成功抵挡本次所有伤害!" << endl;
hasShield = false;
addExp(15 * enemyCount);
return true;
}
if (result > 0) {
cout << "\n>>> 战斗胜利!成功清除威胁!" << endl;
int damage = max(5, (enemyPower - random) / 3);
health -= damage;
cout << "[受伤] 损失 " << damage << " 点生命值" << endl;
addExp(15 * enemyCount);
} else {
cout << "\n>>> 战斗失利!被迫撤退!" << endl;
health -= 40;
if (!backpack.empty()) {
int loseIdx = rand() % backpack.size();
cout << "[掉落] 丢失了 " << backpack[loseIdx].name << endl;
backpack.erase(backpack.begin() + loseIdx);
}
}
if (health <= 0) {
cout << "\n!!! 任务失败 - 你已被淘汰 !!!" << endl;
return false;
}
return true;
}
// 升级系统
void addExp(int value) {
exp += value;
cout << "[经验] +" << value << " EXP" << endl;
while (exp >= 50) {
exp -= 50;
level++;
maxHealth += 15;
health = maxHealth;
weaponDamage += 4;
luck += 2;
backpackCapacity += 1;
cout << "\n========================" << endl;
cout << "!!! 恭喜升级 Lv." << level << " !!!" << endl;
cout << "生命上限、伤害、背包容量提升!" << endl;
cout << "========================" << endl;
}
}
// 休息恢复体力
void rest() {
if (energy >= maxEnergy) {
cout << "\n[休息] 体力已满,无需休息" << endl;
return;
}
int recover = 40;
energy = min(maxEnergy, energy + recover);
cout << "\n[休息] 体力恢复 " << recover << " 点 | 当前:" << energy << endl;
}
// 消耗体力判断
bool costEnergy(int cost) {
if (energy < cost) {
cout << "\n[体力] 体力不足!请休息!" << endl;
return false;
}
energy -= cost;
return true;
}
// 计算总资产
void calcWealth() {
totalWealth = 0;
for (auto& i : backpack) totalWealth += i.value;
}
};
// 生成随机高品质物资
Item getRandomItem(int luck) {
int rate = rand() % 100 + luck;
if (rate >= 95) return {"黄金怀表", 18000, "SSR", "物资", false};
if (rate >= 85) return {"高级加密硬盘", 9500, "SR", "物资", false};
if (rate >= 75) return {"军用护甲包", 3200, "R", "护甲", true};
if (rate >= 65) return {"专业医疗包", 1600, "R", "医疗", true};
if (rate >= 55) return {"护盾电池", 1200, "R", "护盾", true};
if (rate >= 40) return {"显卡", 1800, "R", "物资", false};
if (rate >= 20) return {"手机", 260, "N", "物资", false};
return {"破损零件", 60, "N", "物资", false};
}
// 游戏主逻辑
void playGame() {
srand(time(0));
system("cls");
cout << "========================================================" << endl;
cout << " 《三角洲行动:文字版 · 零号大坝》增强版 " << endl;
cout << " 深入战区、搜刮物资、成功撤离 " << endl;
cout << "========================================================" << endl;
string name;
cout << "请输入你的干员代号:";
cin >> name;
Operator player(name);
int turn = 1;
bool alive = true;
while (alive) {
player.calcWealth();
cout << "\n\n==================== 第 " << turn << " 回合 ====================" << endl;
cout << "当前区域:" << MAP_NAME << " | 体力影响所有行动成功率" << endl;
player.showStatus();
cout << "\n【行动指令】" << endl;
cout << " 1 - 搜索保险箱(高风险高回报 | 体力-30)" << endl;
cout << " 2 - 搜索房间(低风险低回报 | 体力-15)" << endl;
cout << " 3 - 休息恢复体力(无风险)" << endl;
cout << " 4 - 使用物品(治疗/护甲/护盾)" << endl;
cout << " 5 - 丢弃物品(腾出背包空间)" << endl;
cout << " 6 - 呼叫直升机撤离" << endl;
cout << "=====================================================" << endl;
cout << "请输入指令:";
int choice;
cin >> choice;
bool actionSuccess = true;
if (choice == 1) {
if (!player.costEnergy(30)) { actionSuccess = false; }
else {
cout << "\n[行动] 正在破解保险箱..." << endl;
this_thread::sleep_for(chrono::milliseconds(900));
player.lootItem(getRandomItem(player.luck + 15));
if (rand() % 100 < 42) {
alive = player.combat({"哈夫克卫队", "战术无人机"});
}
}
}
else if (choice == 2) {
if (!player.costEnergy(15)) { actionSuccess = false; }
else {
cout << "\n[行动] 快速搜索房间..." << endl;
this_thread::sleep_for(chrono::milliseconds(500));
player.lootItem(getRandomItem(player.luck));
if (rand() % 100 < 15) {
alive = player.combat({"拾荒者"});
}
}
}
else if (choice == 3) {
player.rest();
}
else if (choice == 4) {
if (player.backpack.empty()) {
cout << "\n[背包] 没有可使用的物品!" << endl;
} else {
cout << "\n【可使用物品】" << endl;
for (int i = 0; i < player.backpack.size(); i++) {
auto& item = player.backpack[i];
if (item.usable) {
cout << i << " - " << item.name << " (" << item.type << ")" << endl;
}
}
cout << "输入要使用的物品序号:";
int idx; cin >> idx;
player.useItem(idx);
}
}
else if (choice == 5) {
if (player.backpack.empty()) {
cout << "\n[背包] 背包为空!" << endl;
} else {
cout << "\n【背包列表】" << endl;
for (int i = 0; i < player.backpack.size(); i++) {
cout << i << " - " << player.backpack[i].name << endl;
}
cout << "输入要丢弃的物品序号:";
int idx; cin >> idx;
player.dropItem(idx);
}
}
else if (choice == 6) {
cout << "\n[撤离] 正在呼叫直升机..." << endl;
this_thread::sleep_for(chrono::seconds(1));
int evacRate = 45 + (player.level * 3);
if (rand() % 100 < evacRate) {
cout << "\n========================================================" << endl;
cout << " ?? 撤离成功!任务完成 ??" << endl;
cout << " 干员:" << player.name << " | 等级:Lv." << player.level << endl;
cout << " 本次带回资产:" << player.totalWealth << " 哈夫克币" << endl;
cout << "========================================================" << endl;
break;
} else {
cout << "\n[撤离失败] 撤离点被封锁!立即进入战斗!" << endl;
alive = player.combat({"阿萨拉精英小队", "机枪手"});
}
}
else {
cout << "\n[错误] 无效指令!" << endl;
}
if (actionSuccess && alive) turn++;
}
}
int main() {
playGame();
cout << "\n游戏结束,按回车键退出...";
cin.ignore();
cin.get();
return 0;
}