三角洲游戏升级版(改编自leo1009)(代码有点小问题,请先看评论)

lizexu 2026-08-25 13:31:40 2026-08-26 9:30:42

#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;

}

共 6 条回复

leo1009

V2.0.1正式版本

leo1009
	#include<bits/stdc++.h>
	#include<ctime>
	#include<string>
	#include<conio.h>
	#include<windows.h>
	#include<cstdio>
	#include<cmath> 
	#include<fstream> 
	using namespace std;
	bool fang=false,kai=false;
	string oname="";
	bool flag=false; 
	int loseplayer=0;
	string have;
	int lv=0;
	int cnt=0;
	bool lose=false;
	int gid=0;
	int gun=0;
	string lastlose;
	bool buy_it=false;
	string bullet="";
	string ourname[10]={"","G18","AKM","MP5","AWM","Barrett M82A1","MP7A1","HK416"};
	int gun_kill[10]={0,13,28,18,75,90,20,24};
	int kill[110]={};
	string losename;
	string my_name[5]={"","红狼","骇爪","威龙","蝶"};
	int id=rand()%4;
	int hp[10]={0,100,100,100,100};
	string gun_name[110]={"M16","pp-19","G18","AKS74U"};
	int coin=100000,buy_time,bt[1010],cd_=0,buy[1010],kill_=0,player=0,game=0;
	string name[5]={"花似雪","N","N"},gname,shop[10]={"止痛药(10血)","简易注射剂(20血)","强效注射剂(30血)","战地医疗箱(50血)","缩短CD 1秒","缩短CD 2秒","伤害(1血)","伤害(2血)","角色(一只姜)","角色(Macw07)"};
	bool isKeyPressed(int key) {
	    return (GetAsyncKeyState(key)&0x8000)!=0;
	}
	void play_mode(){
		srand(static_cast<unsigned int>(time(0)));
		int n,ox=100,choice,f=0,m_kill=0,f2=0;
		string g;
		double p=0,p1=0,p2=0,p3=0,p4=0;
		system("cls");
		system("cls");
		while(true){
			label2: 
			cout<<"请选择出战角色:\n1.红狼	2.骇爪	3.威龙	4.蝶\n"; 
			cin>>choice;
			gid=choice;
			if(choice==1){
				if(losename=="红狼"){
					cout<<"负伤状态无法选择!\n";
					continue;
				}else{
				cout<<"角色剩余血量: "<<hp[choice]<<"\n";
				cout<<"你要使用什么武器? 1.G18 2.AKM 3.MP5 4.AWM 5.Barrett M82A1 6.MP7A1 7.HK416\n";
				cin>>gun;
				gname="红狼";
				player=0;
				break; 
			}
			}
			else if(choice==2&&name[1]=="骇爪"){
				if(losename=="骇爪"){
					cout<<"负伤状态无法选择!\n";
					continue;
				}else{
				cout<<"角色剩余血量: "<<hp[choice]<<"\n";
				cout<<"你要使用什么武器? 1.G18 2.AKM 3.MP5 4.AWM 5.Barrett M82A1 6.MP7A1 7.HK416\n";
				cin>>gun;
				gname="骇爪";
				player=1;
				break; 
			}
			}
			else if(choice==3&&name[2]=="威龙"){
				if(losename=="威龙"){
					cout<<"负伤状态无法选择!\n";
					continue;
				}else{
				cout<<"角色剩余血量: "<<hp[choice]<<"\n";
				cout<<"你要使用什么武器? 1.G18 2.AKM 3.MP5 4.AWM 5.Barrett M82A1 6.MP7A1 7.HK416\n";
				cin>>gun;
				gname="威龙";
				player=2; 
				break;
			}
			}else if(choice==4 && name[3]=="蝶"){
				if(losename=="蝶"){
					cout<<"负伤状态无法选择!\n";
					continue;
				}else{
				cout<<"角色剩余血量: "<<hp[choice]<<"\n";
				cout<<"你要使用什么武器? 1.G18 2.AKM 3.MP5 4.AWM 5.Barrett M82A1 6.MP7A1 7.HK416\n";
				cin>>gun;
				gname="蝶";
				player=3; 
				break;
			}
			cout<<"你没有这个角色...\n"; 
		}
	}
		cout<<"你的角色为:"<<gname<<endl;
		choice=rand()%2;
		cout<<"敌方的角色为:"; 
		if(choice==0){
			cout<<"阿萨拉士兵\n"; 
			oname="阿萨拉士兵";
		}
		else if(choice==1){
			cout<<"哈夫克士兵\n"; 
			oname="哈夫克士兵";
		}
		else if(choice==2){
			cout<<"阿萨拉盾兵\n"; 
			oname="阿萨拉盾兵";
		}
		system("pause");
		while(true){
			label1:
			if(hp[gid]<=10){
				system("color 40");
				Sleep(1000);
			} 
			Sleep(1000); 
			f++;
			f2++; 
			system("cls");
			cout<<"我方血量:"<<hp[gid]<<endl; 
	    	cout<<"敌方血量:"<<ox<<endl;
	    	cout<<"普攻CD:"<<p<<endl;
	    	cout<<"1技能CD:"<<p1<<endl; 
	    	cout<<"2技能CD:"<<p2<<endl; 
	    	cout<<"大招CD:"<<p3<<endl;
			cout<<"武器CD:"<<p4<<endl; 
			if (isKeyPressed('1')) {
				if(p<=0){
					if(flag){
						cout<<"我方使用北极星,造成了敌方75点伤害"<<endl;
						p=0.7;
						ox-=75;
						flag=false; 
					}else{
			        cout<<"我方使用北极星,造成了敌方37点伤害"<<endl;
			        p=0.7;
					ox-=37;
				}
		    	}
		    }
		    else if (isKeyPressed('2')) {
		    	if(p1<=0){
		    		if(player==0){
		    			int a=1;
						int b=1;
						int c=abs(rand()%1);
		    			cout<<"我方使用一技能 三联装手炮,造成了敌方"<<25*(a+b+c)<<"点伤害"<<endl;
		    			ox-=10*(a+b+c);
					}
					else if(player==1){
						if(flag){
							cout<<"我方使用一技能 数据飞刀,使敌方扣除50滴血"<<endl;
							ox-=50;
							flag=false;
						}else{
		    			cout<<"我方使用一技能 数据飞刀,使敌方扣除40滴血"<<endl;
		    			ox-=40; 
		    		}
					}
					else if(player==2){
		    			cout<<"我方使用一技能 C4炸弹,造成了敌方"<<60<<"点伤害"<<endl;
		    			ox-=60;
					}else if(player==3){
						cout<<"我方使用一技能 纳米医疗粉尘为自己加"<<20<<"点血量"<<endl;
						if(hp[gid]+20>100){
							hp[gid]=100;
						}else{
							hp[gid]+=20; 
						}
					}
		        	p1=5-cd_;
		    	}
		    }
		    else if (isKeyPressed('3')) {
		    	if(p2<=0){
		    		if(player==0){
			        	cout<<"我方使用二技能 烟幕弹,使敌方眩晕2秒"<<endl;
		    			f-=2;
					}
					else if(player==1){
		    			cout<<"我方使用二技能 闪光巡飞器,使敌方眩晕3秒"<<endl;
		    			f-=3; 
					}
					else if(player==2){
		    			cout<<"我方使用二技能 喷气,对敌方造成"<<12<<"精神伤害"<<endl;
		    			ox-=12;
					}else{
						cout<<"我方使用二技能 遥控烟雾,使敌方眩晕3秒"<<endl;
						f-=3; 
					}
		        	p2=8-cd_;
		    	}
		    }
		    else if (isKeyPressed('4')) {
		    	if(p3<=0){
		    		if(player==0){
			        	cout<<"我方使用大招 花来+G18,造成了敌方"<<80<<"点伤害"<<endl;
		    			ox-=80;
					}
					else if(player==1){
		    			cout<<"我方使用大招 信号破译器,下一次攻击会多造成10点伤害"<<endl;
		    			flag=true; 
					}
					else if(player==2){
		    			cout<<"我方使用大招 虎蹲炮,对敌方造成"<<8<<"点伤害,自己获得闪击效果(普攻可以攻击两次)"<<endl;
						flag=true;
		    			ox-=8;
					}else{
						cout<<"我方使用大招 蝶式救援无人机,免疫一次伤害,自己获得向死而生效果(普攻可以攻击两次)"<<endl;
						flag=true;
						fang=true;
						kai=true;
					}
		        	p3=12-cd_;
		    	}
		    }else if(isKeyPressed('5')){
		    	int more=rand()%5;
		    	cout<<"我方使用武器: "<<ourname[gun]<<"造成了 "<<gun_kill[gun]+more<<"点伤害\n";
		    	ox-=gun_kill[gun]+more;
				p4=10-cd_;
			}
		    if(ox<=0){
		    	Sleep(800);
		    	cout<<"胜利!";
		    	have="";
		    	fang=false;
				system("cls");
		    	losename="";
		    	int in=rand()%800;
		    	if(in<150){
		    		in+=100;
				}
		    	cout<<"\n你获得了"<<in<<"哈夫币\n"; 
		    	coin+=in;
		    	system("color 0F");
					return; 
			}
			else if(hp[gid]<=0){
				cnt++;
				if(cnt>=3){
					return ;
				}
				Sleep(700);
				cout<<"呃啊......\n";
				Sleep(2500);
				if(kai){
					kai=false;
					cout<<"滴滴...\n";
					cout<<"正在注射血浆...\n";
					Sleep(3500);
					hp[gid]=10;
					Sleep(500);
					goto label1;
				}
		    	cout<<"撤离失败!\n";
		    	Sleep(1000); 
		    	fang=false; 
		    	cout<<"干员名: "<<gname<<" 倒在了血泊之中...\n击败者: "<<oname<<"\n";
		    	loseplayer=gid;
		    	Sleep(1000);
		    	system("pause");
		    	losename=gname;
		    	lastlose=gname;
		    	system("color 0F");
		    	have="";
		    	int out=rand()%500;
		    	if(out<100){
		    		out+=100;
				}
		    	cout<<"\n你失去了"<<out<<"哈夫币\n"; 
		    	coin-=out;
		    	hp[gid]=10;
				system("pause");
				goto label2;
				return;
			}
		    if(f==5){
		    	kill[1]=rand()%15+5; 
		    	kill[2]=rand()%20+5;
		    	kill[3]=rand()%13+6;
		    	kill[4]=rand()%25+2;
		    	if(fang){
		    		cout<<"成功免疫此次伤害!\n";
		    		f=0;
				}else{
		    	cout<<"敌方使用 "<<gun_name[int(id)]<<",造成了"<<kill[int(id)]<<"点伤害\n"; 
		    	hp[gid]-=kill[int(id)];
		    	Sleep(800); 
		    	cout<<"呃...\n";
		    	f=0;
			}
		}
		    Sleep(100);
		    if(p>0){
		    	p-=0.1;
			}
			if(p1>0){
				p1-=0.1;
			}
			if(p2>0){
				p2-=0.1;
			}
			if(p3>0){
				p3-=0.1;
			}
			if(p4>0){
				p4-=0.1;
			}
}
}
	void shop_mode(int sign){
		int choice;
		system("cls");
		if(sign==1){
			cout<<"哈夫币不够,请重新购买\n";
		}
		else if(sign==2){
			cout<<"输入错误,请重新输入\n";
		}
		else if(sign==3){
			cout<<"已达到购买次数限制,请重新输入\n";
		}
		cout<<"你现在有"<<coin<<"哈夫币\n"; 
		cout<<"当前角色: "<<my_name[gid]<<" "<<"剩余血量: "<<hp[gid]<<"\n";
		cout<<"1.止痛药(10血)    100哈夫币\n2.简易注射剂(20血)180哈夫币\n3.强效注射剂(30血)270哈夫币\n4.战地医疗箱(50血)450哈夫币\n5.缩短CD 1秒        350哈夫币\n6.缩短CD 2秒        500哈夫币\n7.伤害(1血)       400哈夫币\n8.伤害(2血)       500哈夫币\n9.招募角色(骇爪)  600哈夫币\n10.招募角色(威龙) 1000哈夫币\n11.返回主页面\n12.招募角色(蝶)   2500哈夫币\n请问你要购买哪个?";	
		cin>>choice;
		if((choice<=4 && hp[gid]==100)){
			cout<<"你没有受伤!\n";
			return ;
		} 
		if(choice==1){
			if(bt[0]>5) shop_mode(3);
			else if(coin>=100){
				if(hp[gid]+10>100){
					hp[gid]=100;
					coin-=100;
					shop_mode(0);
				}
				coin-=100;
				hp[gid]+=10;
				bt[0]++;
				buy[buy_time]=0;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==2){
			if(hp[gid]+20>100){
					hp[gid]=100;
					coin-=180;
					shop_mode(0);
				}
			if(bt[1]>2) shop_mode(3);
			else if(coin>=180){
				coin-=180;
				hp[gid]+=20;
				bt[1]++;
				buy[buy_time]=1;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==3){
			if(hp[gid]+30>100){
					hp[gid]=100;
					coin-=270;
					shop_mode(0);
				}
			if(bt[2]>2) shop_mode(3);
			else if(coin>=270){
				coin-=270;
				hp[gid]+=30;
				bt[2]++;
				buy[buy_time]=2;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==4){
			if(hp[gid]+50>100){
					hp[gid]=100;
					coin-=450;
					shop_mode(0);
				}
			if(bt[3]>1) shop_mode(3);
			else if(coin>=450){
				coin-=450;
				hp[gid]+=50;
				bt[3]++;
				buy[buy_time]=3;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==5){
			if(bt[4]>3) shop_mode(3);
			else if(coin>=350){
				coin-=350;
				cd_+=1;
				bt[4]++;
				buy[buy_time]=4;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==6){
			if(bt[5]>2) shop_mode(3);
			else if(coin>=500){
				coin-=500;
				cd_+=2;
				bt[5]++;
				buy[buy_time]=5;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==7){
			if(bt[6]>3) shop_mode(3);
			if(coin>=400){
				coin-=400;
				kill_+=1;
				bt[6]++;
				buy[buy_time]=6;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==8){
			if(bt[7]>2) shop_mode(3);
			else if(coin>=500){
				coin-=500;
				kill_+=2;
				bt[7]++;
				buy[buy_time]=7;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==9){
			if(bt[8]>1) shop_mode(3);
			else if(coin>=600){
				coin-=600;
				name[1]="骇爪"; 
				bt[8]++;
				buy[buy_time]=8;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==10){
			if(bt[9]>1) shop_mode(3);
			else if(coin>=1000){
				coin-=1000;
				name[2]="威龙"; 
				bt[9]++;
				buy[buy_time]=9;
				shop_mode(0);
			}
			else shop_mode(1);
		}
		else if(choice==11){
			return;
		}else if(choice==12){
			if(coin>=2500){
				coin-=2500;
			name[3]="蝶";
			shop_mode(0);
		}else{
			shop_mode(1);
		}
		}else{
			shop_mode(2);
		}
	}
	void load_mode(){
		ofstream file("存档.code");  
	    if(file.is_open()) {  
	        file<<name[1]<<" "<<name[2]<<" "<<name[3]<<" "<<coin<<" "<<hp[gid]<<" "<<cd_<<" "<<buy_time<<" "<<kill_; 
			for(int i=0;i<buy_time;i++){
				file<<" "<<buy[i];
			}
	        file.close();  
		}
		return;
	}
	void out_mode(){
		system("cls");
		cout<<"感谢游玩!"; 
	    load_mode();
		exit(0);
	}
	void read_load_mode(){
	    ifstream file("存档.code");  
	    if(file.is_open()) {  
	        file>>name[1]>>name[2]>>name[3]>>coin>>hp[gid]>>cd_>>buy_time>>kill_;
			for(int i=0;i<buy_time;i++){
				file>>buy[i];
			}
	        file.close();  
	    } 
	    for(int i=0;i<buy_time;i++)bt[buy[i]]++;
	}
	void home(){ 
		int n;
		cout<<"欢迎参加 航天之战\n1.竞技模式 2.黑市 3.退出并存档 4.读档\n请输入选择:"; 
		cin>>n;
		switch(n){
			case 1:
				play_mode();
				break;
			case 2:
				shop_mode(0);
				break;
			case 3:
				out_mode();
				break;    
			case 4:
				read_load_mode();
				break;
			default:
				system("cls");
				cout<<"请重新输入\n";
				home();
		}
	}
	int main(){
		for(int i=0;i<1010;i++)bt[i]=0;
		while(true){
			system("cls");
			home();
		}
	}
lizexu

那期待你的游戏升级

leo1009

包括武器系统,药品效果系统,激发系统

leo1009

其实我已经做出V1.8 ALPHA版本了,只是目前还在测试可靠性

lizexu

帖有点问题,头文件按照 “leo1009” 的代码就好