问题标题: 创新公社:名字竞技场4.0

0
0
已解决
张帆
张帆
中级天翼
中级天翼

name-computation:

更新刹不住脚,到了3.0:

进来领代码

更新五个Boss:

1.dragon

2.king

3.coder

4.covid

5.student

都有固定技能

张帆在2021-02-10 16:59:14追加了内容

张帆在2021-02-11 11:05:26追加了内容

发布贴

张帆在2021-02-11 11:17:14追加了内容
#include<iostream>
#include<windows.h>
#include<bits/stdc++.h>

using namespace std;

struct j{
	string fire;//技能名字
	string fine;//对敌人造成的伤害 
}; 

struct chacracter{
	string name;
	int HP,G,Z;
	j ay;
	int idx,num;
	string turn_num="";
	string wy_num="";
	int go_upper=0;
	string kill;
	int times;
}; /*
	HP:血量
	G:攻击力
	Z:智力 
	ay:特技 
	idx:所在队伍 
	num:人物编号 
	*/

int n=1;

chacracter c[110]; 
j how[30];//技能 

void color(int corcorcor){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),corcorcor);
}

void give_num_to_how_a_fine_work(){
	how[1].fire="火球术",how[1].fine="100";
	how[2].fire="心灵控制",how[2].fine="10+turn";
	how[3].fire="地裂术",how[3].fine="25+every";
	//how[4].fire="铁壁",how[4].fine="0+fend";//fend防守
	how[4].fire="瘟疫",how[6].fine="20+wy";//wy感染
	how[5].fire="懒癌",how[6].fine="20+wy";//wy感染 
	//how[7].fire="回避攻击",how[8].fine="0+fend"; 
	how[6].fire="终极一击",how[8].fine="200+every+wy";
	how[7].fire="皇天冲击",how[7].fine="230+every+wy";
	how[8].fire="新冠病毒",how[8].fine="280+wy";
	how[9].fire="代码冲击",how[9].fine="290+turn"; 
	how[10].fire="文理双翼",how[10].fine="666"; 
	return ; 
}

void out(string said){
	for(int i=0;i<said.length();i++){
		cout<<said[i];
		Sleep(50);
	}
	return ;
}//输入一个字符串,每5毫秒输出一个字符 

void ano(){
	cout<<"\n";
	return ;
}//换行简写 

void begin(){
	out("欢迎来到NC 4.0");
	//ano();
	//ano();
	Sleep(1000);
	system("cls");
	out("下面请输入名字,按enter+enter分队,禁止外挂,若系统发现外挂,自动退游,最多支持100个名字对战,超出可能会报错。");
	ano();
	out("按enter+(ctrl+z)+enter(注:分开按)结束输入,开始对战");
	Sleep(5000);
	//cout<"\n";
	system("cls");
	return ; 
}//开始对白

void give_num_to_people(int id){
	int x=rand()%5+1;
	c[id].ay.fire=how[x].fire;
	c[id].ay.fine=how[x].fine;
	if(c[id].name.find("king",0)!=-1){
		c[id].ay.fire=how[6].fire;
		c[id].ay.fine=how[6].fine;
	} 
	if(c[id].name.find("dragon",0)!=-1){
		c[id].ay.fire=how[7].fire;
		c[id].ay.fine=how[7].fine;
	} 
	if(c[id].name.find("covid",0)!=-1){
		c[id].ay.fire=how[8].fire;
		c[id].ay.fine=how[8].fine;
	}
	if(c[id].name.find("coder",0)!=-1){
		c[id].ay.fire=how[9].fire;
		c[id].ay.fine=how[9].fine;
	}
	if(c[id].name.find("student",0)!=-1){
		c[id].ay.fire=how[10].fire;
		c[id].ay.fine=how[10].fine;
	}
	c[id].HP=rand()%201+200;
	c[id].G=rand()%41+10;
	c[id].Z=rand()%100+1; 
	return ;
}//对于每一个人物,生成属性。 

void in(){
	int ans=1;
	while(getline(cin,c[n].name)){
		if(c[n].name.empty()){
			ans++;
		} else {
			c[n].idx=ans;
			c[n].num=n; 
			c[n].kill="none_people_kill_him";
			give_num_to_people(n); 
			n++;
		}
	
		//give_num_to_people(n); 
		//cout<<n<<" "<<c[n].HP<<" "<<c[n].G<<" "<<c[n].Z<<" "<<c[n].idx<<"\n";
	}
	n--;
	if(n<2){
		out("wrong");
		exit(0);
	} 
	if(ans==1){//单斗模式 
		//int poster=1;
		for(int i=1;i<=n;i++){
			c[i].idx=i;
		} 
	}
	return ;
}//输入 

void fight_begin_out(){
	system("cls");
	for(int i=1;i<=n;i++){
		color(c[i].idx+240); 
		cout<<(char)(c[i].idx+'A'-1)<<":";
		cout<<c[i].name<<"  ";
		cout<<"HP:"<<c[i].HP<<" ";
		cout<<"攻:"<<c[i].G<<" ";
		cout<<"智:"<<c[i].Z<<" ";
		//cout<<"队伍:"<<c[i].idx<<" "; 
		ano();
		//if(c[i].idx!=c[i-1].idx) ano(); 
	}
	color(0+240);
	cout<<"_____________________________________________________\n";
	return ;
}//开始输出属性 

bool check(){
	int pos=0,cnt=0;
	for(int i=1;i<=n;i++){
		if(c[i].HP>0){
			if(c[i].idx!=pos){
				pos=c[i].idx;
				cnt++;
			}
		}
	}
	return cnt>1;
}

int turn(string s){
	int sum=0;
	for(int i=0;i<s.length();i++){
		if(!(s[i]>='0'&&s[i]<='9')) break;
		sum=sum*10+(int)(s[i]-'0');
	}
	return sum;
}

void fight(){
	int now_turn=0;
	while(check()){
		//cout<<"yes\n";
		now_turn=now_turn%n+1;
		if(c[now_turn].HP==0) continue;
		if(c[now_turn].times==3){
			c[now_turn].turn_num="";
			c[now_turn].wy_num="";
		}
		int pos=rand()%3+1;//出招与否
		//if(c[now_turn].ay.fire=="铁壁"||c[now_turn].ay.fire=="回避攻击"){
		//	pos=2;
		//} 
		int names_you_go=rand()%n+1;
		while(c[names_you_go].idx==c[now_turn].idx||c[names_you_go].HP<=0) names_you_go=rand()%n+1;
		int yes=rand()%10+1; 
		if(c[now_turn].turn_num=="yes")  names_you_go=now_turn;
		switch(pos){
			case 3:{//出技能 
				cout<<c[now_turn].name<<" 使用了 "<<c[now_turn].ay.fire<<",\n";
				int flag=c[now_turn].ay.fine.find("every",0);
				if(flag==-1){
					if(yes==1){
						cout<<c[names_you_go].name<<" 回避了攻击 。\n"; 
					} else {
						int fight_num=turn(c[now_turn].ay.fine);
						//if(!c[now_turn].ay.fire) 
						cout<<c[names_you_go].name<<" 受到了 "<<fight_num<<"点伤害";
						c[names_you_go].HP-=fight_num;
						if(c[names_you_go].HP<0) c[names_you_go].HP=0;
						if(c[names_you_go].HP==0){
							cout<<"	  "<<c[names_you_go].name<<"被击倒了"; 
							c[now_turn].go_upper++;
							c[names_you_go].kill=c[now_turn].name;
							break;
						}
						if(c[now_turn].ay.fine.find("turn",0)!=-1){
							cout<<","<<c[names_you_go].name<<" 被鬼魅了 ";
							c[names_you_go].turn_num="yes";
						}
						if(c[now_turn].ay.fine.find("wy",0)!=-1){
							cout<<","<<c[names_you_go].name<<" 被感染了 ";
							c[names_you_go].wy_num="yes";
						}
					}
					ano();
				} else {
					int fight_num=turn(c[now_turn].ay.fine);
					for(int i=1;i<=n;i++){
						if(c[i].HP<=0) continue;
						if(c[i].idx==c[names_you_go].idx){
							cout<<"   "<<c[i].name<<" 受到了 "<<fight_num<<"点伤害";
							c[i].HP-=fight_num;
							if(c[i].HP<=0){
								c[i].HP=0;
								cout<<","<<c[i].name<<"被击倒了;\n";
								c[now_turn].go_upper++;
								c[i].kill=c[now_turn].name;
								continue; 
							} 
							if(c[now_turn].ay.fine.find("turn",0)!=-1){
								cout<<","<<c[i].name<<" 被鬼魅了 ";
								c[i].turn_num="yes";
							}
							if(c[now_turn].ay.fine.find("wy",0)!=-1){
								cout<<","<<c[i].name<<" 被感染了 ";
								c[i].wy_num="yes";
							}
							cout<<"\n";
						}
					}
				}
				break;
			}
			default:{//出普通攻击 
				cout<<c[now_turn].name<<"发起攻击,"; 
				if(yes==1){
					cout<<c[names_you_go].name<<" 回避了攻击 。\n"; 
				} else {
					int fight_num=c[now_turn].G;
					//if(!c[now_turn].ay.fire) 
					cout<<c[names_you_go].name<<" 受到了 "<<fight_num<<"点伤害";
					c[names_you_go].HP-=fight_num;
					if(c[names_you_go].HP<0) c[names_you_go].HP=0;
					if(c[names_you_go].HP==0){
						cout<<"	  "<<c[names_you_go].name<<"被击倒了\n";
						c[now_turn].go_upper++; 
						c[names_you_go].kill=c[now_turn].name;
					}
					//if(c[now_turn].ay.fine.find("turn",0)!=-1){
					//	cout<<","<<c[names_you_go].name<<" 被鬼魅了 ";
					//	c[names_you_go].turn_num="yes";
					//}
					//if(c[now_turn].ay.fine.find("wy",0)!=-1){
					//	cout<<","<<c[names_you_go].name<<" 被感染了 ";
					//	c[names_you_go].wy_num="yes";
					//}
					ano();
				}
				break;
			} 
		} 
		if(c[now_turn].wy_num=="yes"){
			cout<<"   "<<c[now_turn].name<<"病毒发作,收到了50点伤害,";
			c[now_turn].HP-=50;
			if(c[names_you_go].HP==0){
				cout<<c[now_turn].name<<"被击倒了\n";
				//c[now_turn].go_upper++; 
			}
			ano(); 
		}
		c[now_turn].times++;
		Sleep(500);
		cout<<endl;
	}
	return ;
}

void last_out(){
	//cout<<turn("100");
	ano();
	ano();
	cout<<"输出格式为名字,杀得人数,他被谁杀。";
	ano();
	ano(); 
	cout<<"胜者:";
	int pos=-1;
	ano();
	for(int i=1;i<=n;i++){
		if(c[i].HP>0){
			pos=c[i].idx;
			break;
		}	
	} 
	for(int i=1;i<=n;i++){
		if(c[i].idx==pos){
			color(c[i].idx+240);
			cout<<(char)(c[i].idx+'A'-1)<<":";
			cout<<c[i].name<<" "<<c[i].go_upper<<" "<<c[i].kill<<"\n";
		}
	}
	ano();
	ano();
	color(0+240);
	cout<<"败者:";
	ano();
	 for(int i=1;i<=n;i++){
		if(c[i].idx!=pos){
			color(c[i].idx+240);
			cout<<(char)(c[i].idx+'A'-1)<<":";
			cout<<c[i].name<<" "<<c[i].go_upper<<" "<<c[i].kill<<"\n";
		}
	}
	color(0+240);
	return ;
}

int main(){
	give_num_to_how_a_fine_work(); 
	begin();
	in();
	fight_begin_out();
	fight();
	last_out();
	return 0;
}

4.0染色版本

张帆在2021-02-11 11:18:40追加了内容

4.0隆重来袭。


0
已采纳
汪恺恒
汪恺恒
中级启示者
中级启示者

你确定可以攻击自己???

0
0
沙宸安
沙宸安
高级启示者
高级启示者

我现在在想,我跟王子逸天天思路重,他会不会打我哟

0
李致远
李致远
高级光能
高级光能
//更新了两个boss 您觉得怎么样
#include<iostream>
#include<windows.h>
#include<bits/stdc++.h>

using namespace std;

struct j {
    string fire;//技能名字
    string fine;//对敌人造成的伤害
};

struct chacracter {
    string name;
    int HP,G,Z;
    j ay;
    int idx,num;
    string turn_num="";
    string wy_num="";
    int go_upper=0;
    string kill;
    int times;
}; /*
    HP:血量
    G:攻击力
    Z:智力
    ay:特技
    idx:所在队伍
    num:人物编号
    */

int n=1;

chacracter c[110];
j how[30];//技能

void color(int corcorcor) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),corcorcor);
}

void give_num_to_how_a_fine_work() {
    how[1].fire="火球术",how[1].fine="100";
    how[2].fire="心灵控制",how[2].fine="10+turn";
    how[3].fire="地裂术",how[3].fine="25+every";
    how[12].fire="一击必杀",how[12].fine="300+every+fend";//fend防守
    how[4].fire="瘟疫",how[6].fine="20+wy";//wy感染
    how[5].fire="懒癌",how[6].fine="20+wy";//wy感染
    //how[7].fire="回避攻击",how[8].fine="0+fend";
    how[6].fire="终极一击",how[8].fine="200+every";
    how[7].fire="皇天冲击",how[7].fine="230+every";
    how[8].fire="新冠病毒",how[8].fine="280+wy";
    how[9].fire="代码冲击",how[9].fine="290+turn";
    how[10].fire="文理双翼",how[10].fine="300";
    how[11].fire="蔑视群雄",how[11].fine="500+every";
    return ;
}

void out(string said) {
    for(int i=0; i<said.length(); i++) {
        cout<<said[i];
        Sleep(20);
    }
    return ;
}//输入一个字符串,每5毫秒输出一个字符

void ano() {
    cout<<"\n";
    return ;
}//换行简写

void begin() {
    out("欢迎来到NC 4.0");
    //ano();
    //ano();
    Sleep(1000);
    system("cls");
    out("下面请输入名字,按enter+enter分队,禁止外挂,若系统发现外挂,自动退游,最多支持100个名字对战,超出可能会报错。");
    ano();
    out("按enter+(ctrl+z)+enter(注:分开按)结束输入,开始对战");
    Sleep(1000);
    //cout<"\n";
    system("cls");
    return ;
}//开始对白

void give_num_to_people(int id) {
    int x=rand()%5+1;
    c[id].ay.fire=how[x].fire;
    c[id].ay.fine=how[x].fine;
    if(c[id].name.find("king",0)!=-1) {
        c[id].ay.fire=how[6].fire;
        c[id].ay.fine=how[6].fine;
    }
    if(c[id].name.find("dragon",0)!=-1) {
        c[id].ay.fire=how[7].fire;
        c[id].ay.fine=how[7].fine;
    }
    if(c[id].name.find("covid",0)!=-1) {
        c[id].ay.fire=how[8].fire;
        c[id].ay.fine=how[8].fine;
    }
    if(c[id].name.find("coder",0)!=-1) {
        c[id].ay.fire=how[9].fire;
        c[id].ay.fine=how[9].fine;
    }
    if(c[id].name.find("student",0)!=-1) {
        c[id].ay.fire=how[10].fire;
        c[id].ay.fine=how[10].fine;
    }
    if(c[id].name.find("ghost",0)!=-1) {
        c[id].ay.fire=how[12].fire;
        c[id].ay.fine=how[12].fine;
    }
    if(c[id].name.find("God of war",0)!=-1) {
        c[id].ay.fire=how[11].fire;
        c[id].ay.fine=how[11].fine;
    }
    c[id].HP=rand()%201+200;
    c[id].G=rand()%41+10;
    c[id].Z=rand()%100+1;
    return ;
}//对于每一个人物,生成属性。

void in() {
    int ans=1;
    while(getline(cin,c[n].name)) {
        if(c[n].name.empty()) {
            ans++;
        } else {
            c[n].idx=ans;
            c[n].num=n;
            c[n].kill="none_people_kill_him";
            give_num_to_people(n);
            n++;
        }

        //give_num_to_people(n);
        //cout<<n<<" "<<c[n].HP<<" "<<c[n].G<<" "<<c[n].Z<<" "<<c[n].idx<<"\n";
    }
    n--;
    if(n<2) {
        out("wrong");
        exit(0);
    }
    if(ans==1) { //单斗模式
        //int poster=1;
        for(int i=1; i<=n; i++) {
            c[i].idx=i;
        }
    }
    return ;
}//输入

void fight_begin_out() {
    system("cls");
    for(int i=1; i<=n; i++) {
        color(c[i].idx+240);
        cout<<(char)(c[i].idx+'A'-1)<<":";
        cout<<c[i].name<<"  ";
        cout<<"HP:"<<c[i].HP<<" ";
        cout<<"攻:"<<c[i].G<<" ";
        cout<<"智:"<<c[i].Z<<" ";
        //cout<<"队伍:"<<c[i].idx<<" ";
        ano();
        //if(c[i].idx!=c[i-1].idx) ano();
    }
    color(0+240);
    cout<<"_____________________________________________________\n";
    return ;
}//开始输出属性

bool check() {
    int pos=0,cnt=0;
    for(int i=1; i<=n; i++) {
        if(c[i].HP>0) {
            if(c[i].idx!=pos) {
                pos=c[i].idx;
                cnt++;
            }
        }
    }
    return cnt>1;
}

int turn(string s) {
    int sum=0;
    for(int i=0; i<s.length(); i++) {
        if(!(s[i]>='0'&&s[i]<='9')) break;
        sum=sum*10+(int)(s[i]-'0');
    }
    return sum;
}

void fight() {
    int now_turn=0;
    while(check()) {
        //cout<<"yes\n";
        now_turn=now_turn%n+1;
        if(c[now_turn].HP==0) continue;
        if(c[now_turn].times==3) {
            c[now_turn].turn_num="";
            c[now_turn].wy_num="";
        }
        int pos=rand()%3+1;//出招与否
        //if(c[now_turn].ay.fire=="铁壁"||c[now_turn].ay.fire=="回避攻击"){
        //  pos=2;
        //}
        int names_you_go=rand()%n+1;
        while(c[names_you_go].idx==c[now_turn].idx||c[names_you_go].HP<=0) names_you_go=rand()%n+1;
        int yes=rand()%10+1;
        if(c[now_turn].turn_num=="yes")  names_you_go=now_turn;
        switch(pos) {
            case 3: { //出技能
                cout<<c[now_turn].name<<" 使用了 "<<c[now_turn].ay.fire<<",\n";
                int flag=c[now_turn].ay.fine.find("every",0);
                if(flag==-1) {
                    if(yes==1) {
                        cout<<c[names_you_go].name<<" 回避了攻击 。\n";
                    } else {
                        int fight_num=turn(c[now_turn].ay.fine);
                        //if(!c[now_turn].ay.fire)
                        cout<<c[names_you_go].name<<" 受到了 "<<fight_num<<"点伤害";
                        c[names_you_go].HP-=fight_num;
                        if(c[names_you_go].HP<0) c[names_you_go].HP=0;
                        if(c[names_you_go].HP==0) {
                            cout<<"     "<<c[names_you_go].name<<"被击倒了";
                            c[now_turn].go_upper++;
                            c[names_you_go].kill=c[now_turn].name;
                            break;
                        }
                        if(c[now_turn].ay.fine.find("turn",0)!=-1) {
                            cout<<","<<c[names_you_go].name<<" 被鬼魅了 ";
                            c[names_you_go].turn_num="yes";
                        }
                        if(c[now_turn].ay.fine.find("wy",0)!=-1) {
                            cout<<","<<c[names_you_go].name<<" 被感染了 ";
                            c[names_you_go].wy_num="yes";
                        }
                    }
                    ano();
                } else {
                    int fight_num=turn(c[now_turn].ay.fine);
                    for(int i=1; i<=n; i++) {
                        if(c[i].HP<=0) continue;
                        if(c[i].idx==c[names_you_go].idx) {
                            cout<<"   "<<c[i].name<<" 受到了 "<<fight_num<<"点伤害";
                            c[i].HP-=fight_num;
                            if(c[i].HP<=0) {
                                c[i].HP=0;
                                cout<<","<<c[i].name<<"被击倒了;\n";
                                c[now_turn].go_upper++;
                                c[i].kill=c[now_turn].name;
                                continue;
                            }
                            if(c[now_turn].ay.fine.find("turn",0)!=-1) {
                                cout<<","<<c[i].name<<" 被鬼魅了 ";
                                c[i].turn_num="yes";
                            }
                            if(c[now_turn].ay.fine.find("wy",0)!=-1) {
                                cout<<","<<c[i].name<<" 被感染了 ";
                                c[i].wy_num="yes";
                            }
                            cout<<"\n";
                        }
                    }
                }
                break;
            }
            default: { //出普通攻击
                cout<<c[now_turn].name<<"发起攻击,";
                if(yes==1) {
                    cout<<c[names_you_go].name<<" 回避了攻击 。\n";
                } else {
                    int fight_num=c[now_turn].G;
                    //if(!c[now_turn].ay.fire)
                    cout<<c[names_you_go].name<<" 受到了 "<<fight_num<<"点伤害";
                    c[names_you_go].HP-=fight_num;
                    if(c[names_you_go].HP<0) c[names_you_go].HP=0;
                    if(c[names_you_go].HP==0) {
                        cout<<"     "<<c[names_you_go].name<<"被击倒了\n";
                        c[now_turn].go_upper++;
                        c[names_you_go].kill=c[now_turn].name;
                    }
                    //if(c[now_turn].ay.fine.find("turn",0)!=-1){
                    //  cout<<","<<c[names_you_go].name<<" 被鬼魅了 ";
                    //  c[names_you_go].turn_num="yes";
                    //}
                    //if(c[now_turn].ay.fine.find("wy",0)!=-1){
                    //  cout<<","<<c[names_you_go].name<<" 被感染了 ";
                    //  c[names_you_go].wy_num="yes";
                    //}
                    ano();
                }
                break;
            }
        }
        if(c[now_turn].wy_num=="yes") {
            cout<<"   "<<c[now_turn].name<<"病毒发作,收到了50点伤害,";
            c[now_turn].HP-=50;
            if(c[names_you_go].HP==0) {
                cout<<c[now_turn].name<<"被击倒了\n";
                //c[now_turn].go_upper++;
            }
            ano();
        }
        c[now_turn].times++;
        Sleep(500);
        cout<<endl;
    }
    return ;
}

void last_out() {
    //cout<<turn("100");
    ano();
    ano();
    cout<<"输出格式为名字,杀得人数,他被谁杀。";
    ano();
    ano();
    cout<<"胜者:";
    int pos=-1;
    ano();
    for(int i=1; i<=n; i++) {
        if(c[i].HP>0) {
            pos=c[i].idx;
            break;
        }
    }
    for(int i=1; i<=n; i++) {
        if(c[i].idx==pos) {
            color(c[i].idx+240);
            cout<<(char)(c[i].idx+'A'-1)<<":";
            cout<<c[i].name<<" "<<c[i].go_upper<<" "<<c[i].kill<<"\n";
        }
    }
    ano();
    ano();
    color(0+240);
    cout<<"败者:";
    ano();
    for(int i=1; i<=n; i++) {
        if(c[i].idx!=pos) {
            color(c[i].idx+240);
            cout<<(char)(c[i].idx+'A'-1)<<":";
            cout<<c[i].name<<" "<<c[i].go_upper<<" "<<c[i].kill<<"\n";
        }
    }
    color(0+240);
    return ;
}

int main() {
    while(1) {
        give_num_to_how_a_fine_work();
        begin();
        in();
        fight_begin_out();
        fight();
        last_out();
        ano();
    }

    return 0;
}

 

我要回答