提个建议
  • 板块灌水区
  • 楼主2013wu
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/10/19 16:31
  • 上次更新2024/10/19 18:31:14
查看原帖
提个建议
988267
2013wu楼主2024/10/19 16:31

请各位大佬提供一下改进建议

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
string a,b;
int maxa=0,maxb=0;
int maxxa=0,maxxb=0;
int maa=0,mab=0; 
int ax,bx;
int ans=0;
void wait(int x){
	Sleep(x);
	return;
}
void fight(string x,string y,int t){
	cout<<x<<"向"<<y<<"发出了威力值为"<<t<<"的攻击"<<endl;
	return;
}
void hide(string x,int op,int t){
	if(op){
		cout<<x<<"使出了闪躲"<<endl;
		if(x==a){
			maxb=0;
			mab=0;
		}else{
			maxa=0;
			maa=0;
		}
	}else{
		cout<<x<<"被击中,损失"<<t<<"滴血"<<endl;
		if(x==a){
			ax-=t;
			maxb++;
			mab++;
			maxxb=max(maxxb,mab);
		}else{
			bx-=t;
			maxa++;
			maa++;
			maxxa=max(maxxa,maa);
		}
	}
	
	return;
}
signed main(){
	    //freopen(".in","r",stdin);
	    //freopen(".out","w",stdout);
	    srand(time(NULL));
	    cout<<"名字竞技场"<<endl;
	    cout<<endl<<"注意:每人最多1000血!!!\n";
	    wait(500);
	    cout<<endl<<"A的姓名?"<<endl;
	    cin>>a;
	    cout<<endl<<"B的姓名?"<<endl;
	    cin>>b;
	    wait(300);
	    cout<<"-----------------------------------------------"<<endl;
	    wait(500);
	    ax=rand()%100+900;
	    bx=rand()%100+900;
	    cout<<"A的血量:"<<ax<<"    B的血量:"<<bx<<endl;
	    wait(500);
	    while(true){
	    	ans++;
	    	cout<<"第"<<ans<<"轮"<<endl;
	    	if(ax<=0){
	    		cout<<b<<"获得胜利!!!\n剩余血量:"<<bx;
				if(maxxb>=3)cout<<"    最大连击"<<maxxb<<"次";
				cout<<endl;
	    		cout<<"game over!";
	    		return 0;
			}
			if(bx<=0){
	    		cout<<a<<"获得胜利!!!\n剩余血量:"<<ax;
				if(maxxa>=3)cout<<"    最大连击"<<maxxa<<"次";
				cout<<endl;
	    		cout<<"game over!";
	    		return 0;
			}
			int t1=rand()%2,t2=rand()%2;
			int s=rand()%30+70; 
			if(t1){
				fight(a,b,s);
				hide(b,t2,s);
			}else{
				fight(b,a,s);
				hide(a,t2,s);
			}
			if(maxa>=3){
				cout<<a<<"连击3次,加150血!"<<endl;
				ax+=150;
				ax=min(ax,1000);
				maxa=0;
			}
			if(maxb>=3){
				cout<<b<<"连击3次,加150血!"<<endl;
				bx+=150;
				bx=min(bx,1000);
				maxb=0;
			}
			wait(700);
			cout<<endl;
		}
	    return 0;
 }
2024/10/19 16:31
加载中...