#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include
#include
using namespace std;
const int MAX_HP = 100;
const string SAVE_FILE = "delta_force_save.dat";
struct Character {
string name;
int hp;
bool unlocked;
bool injured;
Character(string n = "", int h = MAX_HP, bool u = false)
: name(n), hp(h), unlocked(u), injured(false) {}
};
struct Skill {
string name;
double cd;
double currentCd;
int damage;
string desc;
};
struct ShopItem {
string name;
int price;
int maxBuy;
string type;
int value;
};
struct GameState {
vector players;
int activePlayerIdx;
long long coin;
int cdReduction;
int bonusDmg;
vector purchaseHistory;
int buyCount[15];
int currentStage;
GameState() : activePlayerIdx(0), coin(0), cdReduction(0), bonusDmg(0), currentStage(1) {
players.push_back(Character("红狼", MAX_HP, true));
players.push_back(Character("骇爪", MAX_HP, false));
players.push_back(Character("威龙", MAX_HP, false));
players.push_back(Character("夜枭", MAX_HP, false));
fill(buyCount, buyCount + 15, 0);
}
};
GameState gs;
const vector SHOP_ITEMS = {
{"止痛药(10血)", 100, 5, "heal", 10},
{"简易注射剂(20血)", 180, 2, "heal", 20},
{"强效注射剂(30血)", 270, 2, "heal", 30},
{"战地医疗箱(50血)", 450, 1, "heal", 50},
{"缩短CD 1秒", 350, 3, "cd", 1},
{"缩短CD 2秒", 500, 2, "cd", 2},
{"伤害强化(+1)", 400, 3, "dmg", 1},
{"伤害强化(+2)", 500, 2, "dmg", 2},
{"招募角色(骇爪)", 5500, 1, "char", 1},
{"招募角色(威龙)", 10000, 1, "char", 2},
{"招募角色(夜枭)", 7500, 1, "char", 3}
};
void setColor(int color) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void cls() {
system("cls");
}
void pause(const string& msg = "按任意键继续...") {
cout << msg;
_getch();
cout << endl;
}
bool isKeyPressed(int key) {
return (GetAsyncKeyState(key) & 0x8000) != 0;
}
void drawHpBar(const string& label, int current, int max) {
cout << label << ": " << current << "/" << max << " [";
int barLen = 20;
int filled = max > 0 ? (current * barLen / max) : 0;
for (int i = 0; i < barLen; i++) {
if (i < filled)
cout << "#";
else
cout << "-";
}
cout << "]" << endl;
}
bool saveGame() {
ofstream file(SAVE_FILE);
if (!file.is_open()) return false;
file << gs.coin << " " << gs.cdReduction << " " << gs.bonusDmg << " " << gs.currentStage << "\n";
file << gs.players.size() << "\n";
for (auto& p : gs.players) {
file << p.name << " " << p.hp << " " << p.unlocked << " " << p.injured << "\n";
}
file << gs.purchaseHistory.size() << "\n";
for (int id : gs.purchaseHistory) file << id << " ";
file.close();
return true;
}
bool loadGame() {
ifstream file(SAVE_FILE);
if (!file.is_open()) return false;
try {
file >> gs.coin >> gs.cdReduction >> gs.bonusDmg >> gs.currentStage;
size_t playerCnt;
file >> playerCnt;
gs.players.clear();
for(size_t i=0;i<playerCnt;i++){
string name;
int hp;
bool unlocked,injured;
file >> name >> hp >> unlocked >> injured;
gs.players.push_back(Character(name,hp,unlocked));
gs.players.back().injured = injured;
}
size_t histSize;
file >> histSize;
gs.purchaseHistory.clear();
fill(gs.buyCount, gs.buyCount + 15, 0);
for (size_t i = 0; i < histSize && i < 1000; i++) {
int id;
file >> id;
if (id >= 0 && id < (int)SHOP_ITEMS.size()) {
gs.purchaseHistory.push_back(id);
gs.buyCount[id]++;
if(SHOP_ITEMS[id].type=="char"){
int idx=SHOP_ITEMS[id].value;
if(idx>=0 && idx<(int)gs.players.size()){
gs.players[idx].unlocked=true;
}
}
}
}
file.close();
return true;
} catch (...) {
file.close();
return false;
}
}
//通用战斗函数,enemyHp传入敌人血量,返回true胜利 false失败
bool battle(int enemyHp) {
cls();
Character& player = gs.players[gs.activePlayerIdx];
int playerHp = player.hp;
int enemyMaxHp = enemyHp;
vector skills(4);
if(gs.activePlayerIdx == 0){
skills[0] = {"北极星", 0.7, 0, 37, "普通攻击"};
skills[1] = {"三联装手炮", max(0.1,5.0 - gs.cdReduction), 0, 50, "一技能"};
skills[2] = {"烟幕弹", max(0.1,8.0 - gs.cdReduction), 0, 0, "眩晕敌方5秒"};
skills[3] = {"花来+G18", max(0.1,12.0 - gs.cdReduction), 0, 64, "大招"};
}else if(gs.activePlayerIdx ==1){
skills[0] = {"北极星", 0.7, 0, 37, "普通攻击"};
skills[1] = {"数据飞刀", max(0.1,5.0 - gs.cdReduction), 0, 40, "眩晕3秒+伤害"};
skills[2] = {"闪光巡飞器", max(0.1,8.0 - gs.cdReduction), 0, 0, "眩晕敌方3秒"};
skills[3] = {"信号破译器", max(0.1,12.0 - gs.cdReduction), 0, 0, "下次攻击+10伤害"};
}else if(gs.activePlayerIdx ==2){
skills[0] = {"北极星", 0.7, 0, 37, "普通攻击"};
skills[1] = {"C4炸弹", max(0.1,5.0 - gs.cdReduction), 0, 60, "一技能"};
skills[2] = {"喷气", max(0.1,8.0 - gs.cdReduction), 0, 25, "精神伤害"};
skills[3] = {"虎蹲炮", max(0.1,12.0 - gs.cdReduction), 0, 45, "闪击效果"};
}else{
skills[0] = {"暗影射击",0.7,0,32,"普通攻击"};
skills[1] = {"暗影突袭",max(0.1,5.0-gs.cdReduction),0,45,"高额单体伤害"};
skills[2] = {"迷雾",max(0.1,9.0-gs.cdReduction),0,0,"眩晕敌人4秒"};
skills[3] = {"暗夜爆发",max(0.1,13.0-gs.cdReduction),0,70,"大招高额伤害"};
}
bool buffNextAttack = false;
bool doubleAttack = false;
double enemyStunTimer = 0.0;
double enemyAttackTimer = 0.0;
const double TICK = 0.1;
while (playerHp > 0 && enemyHp > 0) {
cls();
setColor(playerHp <= 20 ? 0x40 : 0x0F);
drawHpBar("我方 " + player.name, playerHp, MAX_HP);
setColor(0x0F);
drawHpBar("敌方怪物", enemyHp, enemyMaxHp);
cout << "\n";
for (int i = 0; i < 4; i++) {
bool ready = skills[i].currentCd <= 0;
setColor(ready ? 0x0A : 0x08);
cout << "[" << (i + 1) << "] " << skills[i].name
<< (ready ? " [就绪]" : (" [" + to_string((int)skills[i].currentCd) + "s]"))
<< " " << skills[i].desc << "\n";
}
setColor(0x0F);
if (enemyStunTimer > 0)
cout << "\n【敌方被眩晕中! " << enemyStunTimer << "s】\n";
cout << "\n按 1-4 释放技能: ";
int action = -1;
clock_t start = clock();
while (((double)(clock() - start)) / CLOCKS_PER_SEC < TICK) {
if (_kbhit()) {
char ch = _getch();
if (ch >= '1' && ch <= '4') {
action = ch - '1';
break;
}
}
}
if (action >= 0 && action < 4) {
if (skills[action].currentCd <= 0) {
int dmg = skills[action].damage + gs.bonusDmg;
if (action == 0) {
if (doubleAttack) { dmg *= 2; doubleAttack = false; }
if (buffNextAttack) { dmg += 10; buffNextAttack = false; }
cout << "\n>> " << skills[action].name << " 造成 " << dmg << " 点伤害!\n";
}
else if (action == 1) {
if (gs.activePlayerIdx == 1) { enemyStunTimer = 3.0; if(buffNextAttack){dmg+=10;buffNextAttack=false;}}
cout << "\n>> " << skills[action].name << " 造成 " << dmg << " 点伤害!\n";
}
else if (action == 2) {
if (gs.activePlayerIdx == 0) enemyStunTimer = 5.0;
else if (gs.activePlayerIdx ==1) enemyStunTimer = 3.0;
else if(gs.activePlayerIdx ==3) enemyStunTimer =4.0;
cout << "\n>> " << skills[action].name << " 生效!\n";
}
else if (action == 3) {
if (gs.activePlayerIdx ==1) { buffNextAttack = true; dmg = 0; }
if (gs.activePlayerIdx ==2) { doubleAttack = true; }
cout << "\n>> " << skills[action].name << " 释放!\n";
}
enemyHp -= dmg;
skills[action].currentCd = skills[action].cd;
Sleep(300);
} else {
cout << "\n>> 技能冷却中!\n";
Sleep(200);
}
}
if (enemyStunTimer > 0) {
enemyStunTimer -= TICK;
} else {
enemyAttackTimer += TICK;
if (enemyAttackTimer >= 5.0) {
int eDmg = rand() % 20 + 5;
playerHp -= eDmg;
cout << "\n>> 敌方攻击! 受到 " << eDmg << " 点伤害!\n";
enemyAttackTimer = 0.0;
Sleep(300);
}
}
for (auto& s : skills) {
if (s.currentCd > 0) s.currentCd -= TICK;
}
}
player.hp = playerHp;
if(enemyHp <=0){
cls();
setColor(0x0A);
cout << ">>> 胜利!\n";
setColor(0x0F);
pause();
return true;
}else{
cls();
setColor(0x40);
cout << ">>> 战败!\n";
setColor(0x0F);
player.injured = true;
pause();
return false;
}
}
void playMode() {
cls();
cout << "=== 选择出战角色 ===\n";
for (int i = 0; i < (int)gs.players.size(); i++) {
auto& p = gs.players[i];
cout << (i + 1) << ". " << p.name << " [HP:" << p.hp << "/" << MAX_HP << "]"
<< (p.unlocked ? "" : " 【未解锁】")
<< (p.injured ? " 【负伤】" : "") << "\n";
}
int choice = -1;
while (true) {
cout << "请选择: ";
cin >> choice;
choice--;
if (choice < 0 || choice >= (int)gs.players.size()) {
cout << "无效选择!\n";
continue;
}
if (!gs.players[choice].unlocked) {
cout << "该角色未解锁!\n";
continue;
}
if (gs.players[choice].injured) {
cout << "该角色处于负伤状态,无法出战!\n";
continue;
}
break;
}
gs.activePlayerIdx = choice;
Character& player = gs.players[choice];
string enemyNames[] = {"阿萨拉小兵", "哈夫克小兵", "阿萨拉盾兵"};
int enemyHp = 80 + rand() % 40;
int enemyMaxHp = enemyHp;
string enemyName = enemyNames[rand() % 3];
cls();
cout << "你的角色: " << player.name << "\n";
cout << "敌方角色: " << enemyName << "\n";
pause("准备战斗...");
bool win = battle(enemyHp);
if(win){
cout << "获得 100 哈夫币\n";
gs.coin += 100;
player.hp = min(player.hp + 50, MAX_HP);
}
pause();
}
void stageMode(){
cls();
cout << "===== 闯关模式 =====\n";
cout << "当前关卡:"<< gs.currentStage << "/5\n";
cout << "请先选择出战英雄\n";
cout << "=== 选择出战角色 ===\n";
for (int i = 0; i < (int)gs.players.size(); i++) {
auto& p = gs.players[i];
cout << (i + 1) << ". " << p.name << " [HP:" << p.hp << "/" << MAX_HP << "]"
<< (p.unlocked ? "" : " 【未解锁】")
<< (p.injured ? " 【负伤】" : "") << "\n";
}
int choice = -1;
while (true) {
cout << "请选择英雄编号: ";
cin >> choice;
choice--;
if (choice < 0 || choice >= (int)gs.players.size()) {
cout << "无效选择!\n";
continue;
}
if (!gs.players[choice].unlocked) {
cout << "该角色未解锁!\n";
continue;
}
if (gs.players[choice].injured) {
cout << "该角色处于负伤状态,无法出战!\n";
continue;
}
break;
}
gs.activePlayerIdx = choice;
int stageHp[]={120,180,260,350,500};
int reward[]={300,600,1000,1800,3000};
int hp = stageHp[gs.currentStage-1];
cout << "第"<<gs.currentStage<<"关,敌人血量:"<<hp<<"\n";
pause("开始闯关!");
bool ok = battle(hp);
if(ok){
cout << "闯关成功!获得 "<<reward[gs.currentStage-1]<<" 哈夫币\n";
gs.coin += reward[gs.currentStage-1];
gs.players[gs.activePlayerIdx].hp = min(gs.players[gs.activePlayerIdx].hp+40,MAX_HP);
if(gs.currentStage <5){
gs.currentStage++;
cout << "解锁下一关!\n";
}else{
cout << "恭喜!全部关卡通关!\n";
}
}else{
cout << "闯关失败,回到主菜单\n";
}
pause();
}
void shopMode() {
while (true) {
cls();
setColor(0x0E);
cout << "=== 黑市 ===\n";
setColor(0x0F);
cout << ">> 当前哈夫币: " << gs.coin << "\n\n";
for (int i = 0; i < (int)SHOP_ITEMS.size(); i++) {
auto& item = SHOP_ITEMS[i];
bool canBuy = gs.buyCount[i] < item.maxBuy;
setColor(canBuy ? 0x0F : 0x08);
cout << (i + 1) << ". " << item.name
<< " | " << item.price << "币"
<< " | 已购:" << gs.buyCount[i] << "/" << item.maxBuy
<< (canBuy ? "" : " 【已满】") << "\n";
}
setColor(0x0F);
cout << "\n0. 返回主页\n请选择: ";
int choice;
cin >> choice;
if (choice == 0) return;
choice--;
if (choice < 0 || choice >= (int)SHOP_ITEMS.size()) {
cout << "无效输入!\n";
Sleep(500);
continue;
}
int idx = choice;
auto& item = SHOP_ITEMS[idx];
if (gs.buyCount[idx] >= item.maxBuy) {
cout << "已达购买上限!\n";
Sleep(500);
continue;
}
if (gs.coin < item.price) {
cout << "哈夫币不足!\n";
Sleep(500);
continue;
}
gs.coin -= item.price;
gs.buyCount[idx]++;
gs.purchaseHistory.push_back(idx);
if (item.type == "heal") {
if(gs.activePlayerIdx <0 || gs.activePlayerIdx >= (int)gs.players.size()){
cout << "请先出战一名角色!退款\n";
gs.coin += item.price;
gs.buyCount[idx]--;
gs.purchaseHistory.pop_back();
}else{
auto& p = gs.players[gs.activePlayerIdx];
if (p.hp >= MAX_HP) {
cout << "你没有受伤,退款!\n";
gs.coin += item.price;
gs.buyCount[idx]--;
gs.purchaseHistory.pop_back();
} else {
p.hp = min(p.hp + item.value, MAX_HP);
p.injured = false;
cout << ">> 恢复了 " << item.value << " 点生命!\n";
}
}
} else if (item.type == "cd") {
gs.cdReduction += item.value;
cout << ">> CD减少 " << item.value << " 秒!\n";
} else if (item.type == "dmg") {
gs.bonusDmg += item.value;
cout << ">> 伤害+" << item.value << "!\n";
} else if (item.type == "char") {
gs.players[item.value].unlocked = true;
cout << ">> 成功招募 " << gs.players[item.value].name << "!\n";
}
pause("购买成功!");
}
}
void home() {
while (true) {
cls();
setColor(0x0B);
cout << "╔══════════════════════╗\n";
cout << "║ 三角洲对战 Delta ║\n";
cout << "╚══════════════════════╝\n";
setColor(0x0F);
cout << "1. >> 普通对战\n";
cout << "2. >> 闯关模式\n";
cout << "3. >> 黑市商店\n";
cout << "4. >> 购买记录\n";
cout << "5. >> 读档\n";
cout << "6. >> 退出并存档\n";
cout << "\n请选择: ";
int n;
cin >> n;
switch (n) {
case 1: playMode(); break;
case 2: stageMode(); break;
case 3: shopMode(); break;
case 4: {
cls();
cout << "=== 购买记录 ===\n";
if (gs.purchaseHistory.empty()) {
cout << "暂无购买记录\n";
} else {
for (int i = 0; i < (int)gs.purchaseHistory.size(); i++) {
cout << (i + 1) << ". " << SHOP_ITEMS[gs.purchaseHistory[i]].name << "\n";
}
}
pause();
break;
}
case 5: {
if (loadGame()) {
cout << ">> 读档成功!\n";
} else {
cout << ">> 读档失败,无有效存档\n";
}
pause();
break;
}
case 6: {
if (saveGame()) {
cout << ">> 存档成功! 感谢游玩!\n";
} else {
cout << ">> 存档失败!\n";
}
pause("再见!");
exit(0);
}
default:
cout << "无效输入,请重新选择\n";
Sleep(500);
}
}
}
int main() {
srand(static_cast(time(nullptr)));
SetConsoleOutputCP(936);
home();
return 0;
}

粤公网安备44010602015266号
共 6 条回复
V2.0.1正式版本
那期待你的游戏升级
包括武器系统,药品效果系统,激发系统
其实我已经做出V1.8 ALPHA版本了,只是目前还在测试可靠性
帖有点问题,头文件按照 “leo1009” 的代码就好