三角洲行动V3.0.1 正式版本(介于leo1009的升级版本)

lizexu 2026-08-28 8:40:56 2026-08-30 10:55:25

//本代码由AI生成和本人的调试

#include

#include

#include

#include

#include

#include

#include <conio.h>

#include <windows.h>

using namespace std;

// ================= 数据结构定义 =================

struct Character {

string name;

int hp;

int max_hp;

bool unlocked;

bool injured; // 是否处于负伤状态

};

struct Weapon {

string name;

int base_damage;

};

// ================= 全局游戏状态 =================

int coin = 100;

int cd_reduction = 0; // 缩减的CD秒数

int extra_damage = 0; // 额外伤害

int buy_time = 0;

vector buy_history;

// 角色池 (0:红狼, 1:骇爪, 2:威龙, 3:蝶)

Character characters[4] = {

{"红狼", 100, 100, true, false},

{"骇爪", 100, 100, false, false},

{"威龙", 100, 100, false, false},

{"蝶",   100, 100, false, false}

};

// 武器池 (索引1-7)

Weapon weapons[8] = {

{"", 0},

{"G18", 13}, {"AKM", 28}, {"MP5", 18}, {"AWM", 75},

{"Barrett M82A1", 90}, {"MP7A1", 20}, {"HK416", 24}

};

string enemy_guns[] = {"M16", "pp-19", "G18", "AKS74U"};

string enemy_names[] = {"阿萨拉士兵", "哈夫克士兵", "阿萨拉盾兵"};

// 商店物品购买次数限制与已购次数

int buy_limits[10] = {5, 2, 2, 1, 3, 2, 3, 2, 1, 1};

int buy_counts[10] = {0};

// ================= 辅助函数 =================

void setColor(int color) {

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);

}

void clearInputBuffer() {

cin.clear();

cin.ignore(1024, '\n');

}

int getIntInput() {

int val;

while (!(cin >> val)) {

    clearInputBuffer();

    cout << "输入无效,请输入数字: \n\n";

}

clearInputBuffer(); // 清除回车符

return val;

}

// ================= 核心游戏逻辑 =================

void play_mode() {

srand(static_cast<unsigned int>(time(0)));

int player_id = -1;

int gun_id = -1;


// 1. 选择角色

while (true) {

    system("cls");

    cout << "=== 请选择出战角色 ===\n\n";

    for (int i = 0; i < 4; i++) {

        cout << i + 1 << ". " << characters[i].name

             << (characters[i].unlocked ? "" : "(未解锁)")

             << (characters[i].injured ? " [负伤]" : "")

             << " (HP: " << characters[i].hp << ")\n\n";

    }

    cout << "0. 返回主页\n\n";


    int choice = getIntInput();

    if (choice == 0) return;


    if (choice >= 1 && choice <= 4) {

        int idx = choice - 1;

        if (!characters[idx].unlocked) {

            cout << "你还没有解锁该角色!\n\n";

        } else if (characters[idx].injured) {

            cout << "该角色处于负伤状态,无法出战!\n\n";

        } else {

            player_id = idx;

            break;

        }

    } else {

        cout << "无效的选择!\n\n";

    }

    system("pause");

}


// 2. 选择武器

while (true) {

    system("cls");

    cout << "=== 请选择武器 ===\n\n";

    for (int i = 1; i <= 7; i++) {

        cout << i << ". " << weapons[i].name << " (基础伤害: " << weapons[i].base_damage << ")\n\n";

    }

    int g_choice = getIntInput();

    if (g_choice >= 1 && g_choice <= 7) {

        gun_id = g_choice;

        break;

    }

    cout << "无效的选择!\n\n";

    system("pause");

}


// 3. 生成敌人

int enemy_choice = rand() % 3;

string enemy_name = enemy_names[enemy_choice];

int enemy_hp = 100;


system("cls");

cout << "你的角色: " << characters[player_id].name << " | 武器: " << weapons[gun_id].name << "\n\n";

cout << "遭遇敌方: " << enemy_name << "\n\n";

system("pause");


// 4. 战斗循环

double cd_p = 0, cd_1 = 0, cd_2 = 0, cd_3 = 0, cd_4 = 0;

int enemy_attack_timer = 0;

bool buff_next_attack = false; // 骇爪/威龙/蝶的大招Buff

bool dodge_next_attack = false; // 蝶的大招免伤


while (characters[player_id].hp > 0 && enemy_hp > 0) {

    system("cls");

    if (characters[player_id].hp <= 20) setColor(12); // 血量低时变红

    else setColor(15);


    cout << "【我方 " << characters[player_id].name << "】 HP: " << characters[player_id].hp << "/" << characters[player_id].max_hp << "\n\n";

    cout << "【敌方 " << enemy_name << "】 HP: " << enemy_hp << "/100\n\n";

    cout << "-----------------------------------\n\n";

    cout << "[1] 普攻(北极星) CD:" << (cd_p > 0 ? cd_p : 0.0) << "s\n\n";

    cout << "[2] 一技能       CD:" << (cd_1 > 0 ? cd_1 : 0.0) << "s\n\n";

    cout << "[3] 二技能       CD:" << (cd_2 > 0 ? cd_2 : 0.0) << "s\n\n";

    cout << "[4] 大招         CD:" << (cd_3 > 0 ? cd_3 : 0.0) << "s\n\n";

    cout << "[5] 武器射击     CD:" << (cd_4 > 0 ? cd_4 : 0.0) << "s\n\n";

    cout << "-----------------------------------\n\n";


    // 处理按键输入

    if (_kbhit()) {

        char key = _getch();

        int damage = 0;

        string action = "";


        if (key == '1' && cd_p <= 0) {

            damage = buff_next_attack ? 75 : 37;

            action = "使用北极星";

            cd_p = 0.7;

            buff_next_attack = false;

        }

        else if (key == '2' && cd_1 <= 0) {

            cd_1 = 5.0 - cd_reduction;

            if (player_id == 0) { // 红狼

                damage = 25 + rand() % 10;

                action = "三联装手炮";

            } else if (player_id == 1) { // 骇爪

                damage = buff_next_attack ? 50 : 40;

                action = "数据飞刀";

                buff_next_attack = false;

            } else if (player_id == 2) { // 威龙

                damage = 60;

                action = "C4炸弹";

            } else if (player_id == 3) { // 蝶

                int heal = 20;

                characters[player_id].hp = min(100, characters[player_id].hp + heal);

                action = "纳米医疗粉尘 (恢复20HP)";

            }

        }

        else if (key == '3' && cd_2 <= 0) {

            cd_2 = 8.0 - cd_reduction;

            if (player_id == 0) { action = "烟幕弹 (敌方眩晕2秒)"; enemy_attack_timer -= 2; }

            else if (player_id == 1) { action = "闪光巡飞器 (敌方眩晕3秒)"; enemy_attack_timer -= 3; }

            else if (player_id == 2) { damage = 12; action = "喷气 (精神伤害)"; }

            else if (player_id == 3) { action = "遥控烟雾 (敌方眩晕3秒)"; enemy_attack_timer -= 3; }

        }

        else if (key == '4' && cd_3 <= 0) {

            cd_3 = 12.0 - cd_reduction;

            if (player_id == 0) { damage = 80; action = "花来+G18"; }

            else if (player_id == 1) { buff_next_attack = true; action = "信号破译器 (下次攻击+10伤害)"; }

            else if (player_id == 2) { damage = 8; buff_next_attack = true; action = "虎蹲炮 (获得闪击效果)"; }

            else if (player_id == 3) { dodge_next_attack = true; buff_next_attack = true; action = "蝶式救援无人机 (免伤+闪击)"; }

        }

        else if (key == '5' && cd_4 <= 0) {

            cd_4 = 10.0 - cd_reduction;

            damage = weapons[gun_id].base_damage + rand() % 5 + extra_damage;

            action = "武器射击 (" + weapons[gun_id].name + ")";

        }


        if (!action.empty()) {

            cout << ">> 我方 " << action;

            if (damage > 0) {

                cout << ",造成 " << damage << " 点伤害!\n\n";

                enemy_hp -= damage;

            } else {

                cout << "!\n\n";

            }

            Sleep(600);

        }

    }


    // 敌方行动逻辑

    enemy_attack_timer++;

    if (enemy_attack_timer >= 5) {

        enemy_attack_timer = 0;

        int e_dmg = rand() % 20 + 5;

        if (dodge_next_attack) {

            cout << ">> 敌方攻击被【免疫】!\n\n";

            dodge_next_attack = false;

        } else {

            cout << ">> 敌方使用 " << enemy_guns[rand() % 4] << ",造成 " << e_dmg << " 点伤害!\n\n";

            characters[player_id].hp -= e_dmg;

        }

        Sleep(600);

    }


    // 更新CD

    Sleep(100);

    if (cd_p > 0) cd_p -= 0.1;

    if (cd_1 > 0) cd_1 -= 0.1;

    if (cd_2 > 0) cd_2 -= 0.1;

    if (cd_3 > 0) cd_3 -= 0.1;

    if (cd_4 > 0) cd_4 -= 0.1;

}


// 5. 战斗结算

system("cls");

setColor(15);

if (enemy_hp <= 0) {

    setColor(10); // 绿色

    cout << "=== 战斗胜利! ===\n\n";

    int reward = rand() % 800 + 100;

    coin += reward;

    cout << "你获得了 " << reward << " 哈夫币!\n\n";

} else {

    setColor(12); // 红色

    cout << "=== 撤离失败! ===\n\n";

    cout << characters[player_id].name << " 倒在了血泊之中...\n\n";

    characters[player_id].injured = true;

    characters[player_id].hp = 10; // 复活保底血量

    int loss = rand() % 500 + 100;

    coin = max(0, coin - loss);

    cout << "你失去了 " << loss << " 哈夫币!\n\n";

}

setColor(15);

system("pause");

}

// ================= 商店逻辑 =================

void shop_mode() {

while (true) {

    system("cls");

    cout << "=== 黑市商店 === (当前哈夫币: " << coin << ")\n\n";

    cout << "1. 止痛药(10血) [100币] (限5次)\n\n";

    cout << "2. 简易注射剂(20血) [180币] (限2次)\n\n";

    cout << "3. 强效注射剂(30血) [270币] (限2次)\n\n";

    cout << "4. 战地医疗箱(50血) [450币] (限1次)\n\n";

    cout << "5. 缩短CD 1秒 [350币] (限3次)\n\n";

    cout << "6. 缩短CD 2秒 [500币] (限2次)\n\n";

    cout << "7. 伤害+1 [400币] (限3次)\n\n";

    cout << "8. 伤害+2 [500币] (限2次)\n\n";

    cout << "9. 招募角色(骇爪) [600币]\n\n";

    cout << "10. 招募角色(威龙) [1000币]\n\n";

    cout << "11. 招募角色(蝶) [2500币]\n\n";

    cout << "0. 返回主页\n\n";

    cout << "请选择: ";


    int choice = getIntInput();

    if (choice == 0) break;


    bool success = false;

    string msg = "";



    if (choice >= 1 && choice <= 4) {

        int heals[] = {10, 20, 30, 50};

        int costs[] = {100, 180, 270, 450};

        int idx = choice - 1;



        int target = -1;

        for(int i=0; i<4; i++) if(characters[i].unlocked && characters[i].hp < 100) { target = i; break; }


        if (target == -1) msg = "所有角色都是满血或未解锁!";

        else if (buy_counts[idx] >= buy_limits[idx]) msg = "已达到购买次数限制!";

        else if (coin < costs[idx]) msg = "哈夫币不足!";

        else {

            coin -= costs[idx];

            characters[target].hp = min(100, characters[target].hp + heals[idx]);

            if(characters[target].hp > 10) characters[target].injured = false; // 解除负伤

            buy_counts[idx]++;

            success = true;

            msg = "购买成功,已为 " + characters[target].name + " 恢复血量!";

        }

    }


    else if (choice >= 5 && choice <= 8) {

        int idx = choice - 1;

        int costs[] = {350, 500, 400, 500};

        if (buy_counts[idx] >= buy_limits[idx]) msg = "已达到购买次数限制!";

        else if (coin < costs[idx]) msg = "哈夫币不足!";

        else {

            coin -= costs[idx];

            if (idx == 4) cd_reduction += 1;

            else if (idx == 5) cd_reduction += 2;

            else if (idx == 6) extra_damage += 1;

            else if (idx == 7) extra_damage += 2;

            buy_counts[idx]++;

            success = true;

            msg = "购买成功,属性已提升!";

        }

    }


    else if (choice >= 9 && choice <= 11) {

        int char_idx = choice - 8; // 1->骇爪, 2->威龙, 3->蝶

        int costs[] = {600, 1000, 2500};

        if (characters[char_idx].unlocked) msg = "你已经拥有该角色!";

        else if (coin < costs[char_idx-1]) msg = "哈夫币不足!";

        else {

            coin -= costs[char_idx-1];

            characters[char_idx].unlocked = true;

            success = true;

            msg = "招募成功!新角色已加入小队!";

        }

    } else {

        msg = "无效的选择!";

    }


    if (success) setColor(10); // 绿色

    else setColor(12); // 红色

    cout << msg << "\n\n";

    setColor(15);

    system("pause");

}

}

void save_game() {

ofstream file("save.dat");

if (file.is_open()) {

    file << coin << " " << cd_reduction << " " << extra_damage << "\n";

    for (int i = 0; i < 4; i++) {

        file << characters[i].hp << " " << characters[i].unlocked << " " << characters[i].injured << "\n";

    }

    for (int i = 0; i < 10; i++) {

        file << buy_counts[i] << " ";

    }

    file.close();

    cout << "存档成功!\n\n";

} else {

    cout << "存档失败,请检查文件权限!\n\n";

}

}

void load_game() {

ifstream file("save.dat");

if (file.is_open()) {

    file >> coin >> cd_reduction >> extra_damage;

    for (int i = 0; i < 4; i++) {

        file >> characters[i].hp >> characters[i].unlocked >> characters[i].injured;

    }

    for (int i = 0; i < 10; i++) {

        file >> buy_counts[i];

    }

    file.close();

    cout << "读档成功!\n\n";

} else {

    cout << "未找到存档文件,将开始新游戏!\n\n";

}

}

void home() {

system("cls");

cout << "========================\n\n";

cout << "    欢迎参加 航天之战\n\n";

cout << "========================\n\n";

cout << "1. 竞技模式 (战斗)\n\n";

cout << "2. 黑市 (商店)\n\n";

cout << "3. 保存并退出\n\n";

cout << "4. 读取存档\n\n";

cout << "请输入选择: ";


int n = getIntInput();

switch (n) {

    case 1: play_mode(); break;

    case 2: shop_mode(); break;

    case 3:

        save_game();

        cout << "感谢游玩!\n\n";

        exit(0);

        break;

    case 4:

        load_game();

        system("pause");

        break;

    default:

        cout << "请重新输入!\n\n";

        system("pause");

}

}

int main() {

SetConsoleTitle("航天之战 - 控制台版");

while (true) {

    home();

}

return 0;

}

共 4 条回复

lizexu

对不起,我现在就标

leo1009

借助AI帮助可以,但请标注“AI辅助制作“

leo1009

我观察了一下你的代码,这应该不是你做出来的吧?

leo1009

你是不是用了AI?