问题标题: 保存一个代码(永不结贴)

0
1
已解决
吴梓杰
吴梓杰
高级守护
高级守护
#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;
}; /*
	HP:血量
	G:攻击力
	Z:智力 
	ay:特技 
	idx:所在队伍 
	num:人物编号 
	*/
 
int n=1;
 
chacracter c[110]; 
j how[20];//技能 
 
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[4].fine="10+wy";//wy感染
	how[5].fire="懒癌",how[5].fine="20+wy";//wy感染 
	//how[7].fire="回避攻击",how[8].fine="0+fend"; 
	how[6].fire="终极一击",how[6].fine="200+every+wy+turn";
	return ; 
}
 
void out(string said){
	for(int i=0;i<said.length();i++){
		cout<<said[i];
	}
	return ;
}//输入一个字符串,每5毫秒输出一个字符 
 
void ano(){
	cout<<"\n";
	return ;
}//换行简写 
 
void begin(){
	//ano();
	//ano();
	//cout<"\n";
	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("dragon",0)!=-1){
		c[id].ay.fire=how[6].fire;
		c[id].ay.fine=how[6].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; 
			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(ans==1){//单斗模式 
		//int poster=1;
		for(int i=1;i<=n;i++){
			c[i].idx=i;
		} 
	}
	return ;
}//输入 
 
void fight_begin_out(){
	for(int i=1;i<=n;i++){
		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(); 
	}
	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;
		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; 
		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++;
						}
						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++;
								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<<" 回避了攻击 。"; 
				} 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<<"被击倒了";
						c[now_turn].go_upper++; 
					}
					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;
			} 
		} 
		cout<<endl;
	}
	return ;
}
 
void last_out(){
	//cout<<turn("100");
	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){
			cout<<(char)(c[i].idx+'A'-1)<<":";
			cout<<c[i].name<<" "<<c[i].go_upper<<"\n";
		}
	}
	ano();
	ano();
	cout<<"败者:";
	ano();
	 for(int i=1;i<=n;i++){
		if(c[i].idx!=pos){
			cout<<(char)(c[i].idx+'A'-1)<<":";
			cout<<c[i].name<<" "<<c[i].go_upper<<"\n";
		}
	} 
	return ;
}
 
int main(){
	give_num_to_how_a_fine_work(); 
	begin();
	in();
	fight_begin_out();
	fight();
	last_out();
	return 0;
}

 

吴梓杰在2024-10-06 19:59:58追加了内容

由于版块错误,无法让大家复制,所以改为抽奖贴,前8名参与!!


0
已采纳
毕博雨
毕博雨
初级光能
初级光能

这个代码叫什么名字?

0
0
0
0
0
0
0
董安雅
董安雅
初级光能
初级光能

不是,你不无聊吗?

保存代码有很多的地方,又不是一定要保存在这里,

你接连发两个帖,明显有占用公共资源的嫌疑

0
0
李泽希
李泽希
中级守护
中级守护

大哥,你板块是不是错了

我要回答