三角洲游戏v1.5 Beta版(持续更新,欢迎提议!)

leo1009 2026-08-24 14:49:21 2026-08-25 8:46:04

#include<iostream>
#include<ctime>
#include<string>
#include<windows.h>
#include<cstdio>
#include<cmath> 
#include<fstream> 
using namespace std;
bool flag1=false,flag2=false; 
int gid=0;
int kill[110]={};
string losename;
int id=rand()%4;
int hp[10]={0,100,100,100};
string gun_name[110]={"M16","pp-19","G18","mp5"};
int coin=1e9,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;
	system("cls");
	system("cls");
	while(true){
		cout<<"请选择出战角色:\n1.红狼   2.骇爪   3.威龙\n"; 
		cin>>choice;
		gid=choice;
		if(choice==1){
			cout<<"角色剩余血量: "<<hp[choice]<<"\n";
			if(losename=="红狼"){
				cout<<"负伤状态无法选择!\n";
				continue;
			}else{
			gname="红狼";
			player=0;
			break; 
		}
		}
		else if(choice==2&&name[1]=="骇爪"){
			cout<<"角色剩余血量: "<<hp[choice]<<"\n";
			if(losename=="骇爪"){
				cout<<"负伤状态无法选择!\n";
				continue;
			}else{
			gname="骇爪";
			player=1;
			break; 
		}
		}
		else if(choice==3&&name[2]=="威龙"){
			cout<<"角色剩余血量: "<<hp[choice]<<"\n";
			if(losename=="威龙"){
				cout<<"负伤状态无法选择!\n";
				continue;
			}else{ 
			gname="威龙";
			player=2; 
			break;
		}
		}
		cout<<"你没有这个角色...\n"; 
	}
	cout<<"你的角色为:"<<gname<<endl;
	choice=rand()%3;
	cout<<"敌方的角色为:"; 
	if(choice==0){
		cout<<"阿萨拉小兵\n"; 
	}
	else if(choice==1){
		cout<<"哈夫克小兵\n"; 
	}
	else if(choice==2){
		cout<<"阿萨拉盾兵\n"; 
	}
	system("pause");
	while(true){
		if(hp[gid]<=10){
			system("color 40");
			cout<<"呃...也许我受了重伤...\n";
			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; 
		if (isKeyPressed('1')) {
			if(p<=0){
				if(flag2){
					cout<<"我方使用北极星,造成了敌方75点伤害"<<endl;
					p=0.7;
					ox-=75;
					flag2=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-=25*(a+b+c);
				}
				else if(player==1){
					if(flag){
						cout<<"我方使用一技能 数据飞刀,使敌方眩晕3秒并扣除50滴血"<<endl;
						f-=30;
						ox-=50;
						flag=false;
					}else{
	    			cout<<"我方使用一技能 数据飞刀,使敌方眩晕3秒并扣除40滴血"<<endl;
	    			f-=30;
	    			ox-=40; 
	    		}
				}
				else if(player==2){
	    			cout<<"我方使用一技能 C4炸弹,造成了敌方"<<60<<"点伤害"<<endl;
	    			ox-=60;
				}
	        	p1=5-cd_;
	    	}
	    }
	    else if (isKeyPressed('3')) {
	    	if(p2<=0){
	    		if(player==0){
		        	cout<<"我方使用二技能 烟幕弹,使敌方眩晕5秒"<<endl;
	    			f-=50;
				}
				else if(player==1){
	    			cout<<"我方使用二技能 闪光巡飞器,使敌方眩晕3秒"<<endl;
	    			f-=30; 
				}
				else if(player==2){
	    			cout<<"我方使用二技能 喷气,对敌方造成"<<1<<"精神伤害"<<endl;
	    			ox-=1;
				}
	        	p2=8-cd_;
	    	}
	    }
	    else if (isKeyPressed('4')) {
	    	if(p3<=0){
	    		if(player==0){
		        	cout<<"我方使用大招 花来+G18,造成了敌方"<<80<<"点伤害"<<endl;
	    			ox-=(80*0.8);
				}
				else if(player==1){
	    			cout<<"我方使用大招 信号破译器,下一次攻击会多造成10点伤害"<<endl;
	    			flag=true; 
				}
				else if(player==2){
	    			cout<<"我方使用大招 虎蹲炮,对敌方造成"<<8<<"点伤害,自己获得闪击效果(普攻可以攻击两次)"<<endl;
					flag2=true;
	    			ox-=8;
				}
	        	p3=12-cd_;
	    	}
	    }
	    if(ox<=0){
	    	cout<<"胜利!";
	    	losename="";
	    	cout<<"\n你获得了100哈夫币\n"; 
	    	coin+=100;
	    	system("color 0F");
	    	if(hp[gid]+50<=100){
	    		hp[gid]+=50;
				system("pause");
				return;
			}else{
				hp[gid]=100;
			}
		}
		else if(hp[gid]<=0){
	    	cout<<"失败!\n";
	    	Sleep(1000); 
	    	cout<<"干员名: "<<gname<<" 倒在了血泊之中...";
	    	system("pause");
	    	losename=gname;
	    	system("color 0F");
	    	cout<<"\n你失去了100哈夫币用于医药费\n"; 
	    	coin-=100;
	    	hp[gid]=100;
			system("pause");
			return;
		}
	    if(f==5){
	    	kill[1]=rand()%15+5; 
	    	kill[2]=rand()%20+5;
	    	kill[3]=rand()%13+6;
	    	kill[4]=rand()%30+2;
	    	cout<<"敌方使用 "<<gun_name[int(id)]<<",造成了"<<kill[int(id)]<<"点伤害"; 
	    	hp[gid]-=kill[int(id)];
	    	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;
		}
	}
}
void look_mode(){
	char n;
	bool flag=true;
	system("cls");
	cout<<"已购买:\n";
	for(int i=0;i<buy_time;i++){
		cout<<i+1<<"."<<shop[buy[i]]<<endl;
		flag=false;
	}
	if(flag){
		cout<<"空\n"; 
	}
	system("pause");
	return;
}
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<<"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.返回主页面\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){
			coin-=100;
			hp[gid]+=10;
			bt[0]++;
			buy[buy_time]=0;
			buy_time++;
			shop_mode(0);
		}
		else shop_mode(1);
	}
	else if(choice==2){
		if(bt[1]>2) shop_mode(3);
		else if(coin>=180){
			coin-=180;
			hp[gid]+=20;
			bt[1]++;
			buy[buy_time]=1;
			buy_time++;
			shop_mode(0);
		}
		else shop_mode(1);
	}
	else if(choice==3){
		if(bt[2]>2) shop_mode(3);
		else if(coin>=270){
			coin-=270;
			hp[gid]+=30;
			bt[2]++;
			buy[buy_time]=2;
			buy_time++;
			shop_mode(0);
		}
		else shop_mode(1);
	}
	else if(choice==4){
		if(bt[3]>1) shop_mode(3);
		else if(coin>=450){
			coin-=450;
			hp[gid]+=50;
			bt[3]++;
			buy[buy_time]=3;
			buy_time++;
			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;
			buy_time++;
			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;
			buy_time++;
			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;
			buy_time++;
			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;
			buy_time++;
			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;
			buy_time++;
			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;
			buy_time++;
			shop_mode(0);
		}
		else shop_mode(1);
	}
	else if(choice==11){
		return;
	}
	else{
		shop_mode(2);
	}
}
void load_mode(){
	ofstream file("存档.code");  
    if(file.is_open()) {  
        file<<name[1]<<" "<<name[2]<<" "<<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]>>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.购买记录 5.读档\n请输入选择:"; 
	cin>>n;
	switch(n){
		case 1:
			play_mode();
			break;
		case 2:
			shop_mode(0);
			break;
		case 3:
			out_mode();
			break;    
		case 4:
			look_mode();
			break;
		case 5:
			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();
	}
}