魔兽世界之二:装备

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
 
class HeadQuarter
{
public:
	string weapons[3];
	char ctime[10];//时间
	string strHQName;//司令部名称
	int id;//司令部标志 0 red,1 blue
	int gid[5];//该司令部制造武士的顺序
	int ipos;//存储司令部当前需要制造哪个武士
	int itime;//时间,如果不能直接用武士总数量,则可以单独记一下
	int strengthnum;//该司令部的初始元气值
	
	int icemannum;
	int lionnum;
	int wolfnum;
	int ninjanum;
	int dragonnum;
	
	int icemansgh;
	int lionsgh;
	int wolfsgh;
	int ninjasgh;
	int dragonsgh;
 
	bool blIsStop;
	//获取该司令部的所有武士数量,用于时间显示(比小时数多1)
	int GetWarriorsNum()
	{
		return icemannum+lionnum+wolfnum+ninjanum+dragonnum;
	}
	
	//司令部 构造函数,初始生命元数目和红蓝标志
	HeadQuarter(int strengthnum1,int id)
	{
		strengthnum=strengthnum1;itime=0;icemannum=0;lionnum=0;
		wolfnum=0;ninjanum=0;dragonnum=0;
		id=id;//0 red;1 blue;
		if(id==0)
		{
			gid[0]=3;gid[1]=4;gid[2]=5;gid[3]=2;gid[4]=1;strHQName="red";
		}
		else
		{
			gid[0]=4;gid[1]=1;gid[2]=2;gid[3]=3;gid[4]=5;strHQName="blue";
		}
		ipos=0;
		blIsStop=false;
		weapons[0]="sword";
		weapons[1]="bomb";
		weapons[2]="arrow";
	}
 
	//初始化,每类武士生命初始值
	void InitSamuraVal(int v1,int v2,int v3,int v4,int v5)
	{
		dragonsgh=v1;ninjasgh=v2;icemansgh=v3;lionsgh=v4;wolfsgh=v5;
	}
 
	//制造单个武士
	bool MakeOneWarrior(int id)
	{
		int arrownum=0;
		float fmorale=0.0;
		switch(id)
		{
		case 1:
			if(strengthnum<dragonsgh)
				return false;
			strengthnum-=dragonsgh;
			dragonnum++;
			sprintf(ctime,"%03d",(GetWarriorsNum()-1));
			cout<<ctime<<" "<<strHQName<<" dragon "<<GetWarriorsNum()<<" born with strength "
				<<dragonsgh<<","<<dragonnum<<" dragon in "<<strHQName<<" headquarter"<<endl;
			fmorale=strengthnum/(dragonsgh*1.0);
			cout<<"It has a "<<weapons[GetWarriorsNum()%3]<<",and it's morale is "<<setiosflags(ios::fixed)<<setprecision(2)<<fmorale<<endl;
			break;
		case 2:
			if(strengthnum<ninjasgh)
				return false;
			strengthnum-=ninjasgh;
			ninjanum++;
			sprintf(ctime,"%03d",(GetWarriorsNum()-1));
			cout<<ctime<<" "<<strHQName<<" ninja "<<GetWarriorsNum()<<" born with strength "
				<<ninjasgh<<","<<ninjanum<<" ninja in "<<strHQName<<" headquarter"<<endl;
			cout<<"It has a "<<weapons[GetWarriorsNum()%3]<<" and a "<<weapons[(GetWarriorsNum()+1)%3]<<endl;
			break;
		case 3:
			if(strengthnum<icemansgh)
				return false;
			strengthnum-=icemansgh;
			icemannum++;
			sprintf(ctime,"%03d",(GetWarriorsNum()-1));
			cout<<ctime<<" "<<strHQName<<" iceman "<<GetWarriorsNum()<<" born with strength "
				<<icemansgh<<","<<icemannum<<" iceman in "<<strHQName<<" headquarter"<<endl;
			cout<<"It has a "<<weapons[GetWarriorsNum()%3]<<endl;
			break;
		case 4:
			if(strengthnum<lionsgh)
				return false;
			strengthnum-=lionsgh;
			lionnum++;
			sprintf(ctime,"%03d",(GetWarriorsNum()-1));
			cout<<ctime<<" "<<strHQName<<" lion "<<GetWarriorsNum()<<" born with strength "
				<<lionsgh<<","<<lionnum<<" lion in "<<strHQName<<" headquarter"<<endl;
			cout<<"It's loyalty is "<<strengthnum<<endl;
			break;
		case 5:
			if(strengthnum<wolfsgh)
				return false;
			strengthnum-=wolfsgh;
			wolfnum++;
			sprintf(ctime,"%03d",(GetWarriorsNum()-1));
			cout<<ctime<<" "<<strHQName<<" wolf "<<GetWarriorsNum()<<" born with strength "
				<<wolfsgh<<","<<wolfnum<<" wolf in "<<strHQName<<" headquarter"<<endl;
			break;
		default:
			break;
		}
		return true;
	}
	
	//判断该司令部是否还能够继续制造武士
	bool IsMakeEnable()
	{
		if((strengthnum<icemansgh)&&(strengthnum<lionsgh)&&(strengthnum<wolfsgh)&&(strengthnum<ninjasgh)&&(strengthnum<dragonsgh))
		{
			if(!blIsStop)
			{
				sprintf(ctime,"%03d",GetWarriorsNum());
				cout<<ctime<<" "<<strHQName<<" headquarter stops making warriors"<<endl;
				blIsStop=true;
			}
			return false;
		}
		else
		{
			return true;
		}
	}
 
	//制造武士,判断当前需要制造哪一类武士
	bool MakeWarrior()
	{
		if(ipos==5) ipos=0;
		if(MakeOneWarrior(gid[ipos]))
		{	
			ipos++;
			return true;
		}
		else
		{
			ipos++;
			return false;
		}
	}
};
 
int main()
{
	//存储所有组的测试数据
	int linenum=0,icaseid=1;
	cin>>linenum;
	vector< vector<int> >vecwarriors;
	while((linenum--)>0)
	{
		vector<int> vectemp;
		for(int i=0;i<6;i++)
		{
			int a=0;
			cin>>a;
			vectemp.push_back(a);
		}
		vecwarriors.push_back(vectemp);
	}
	
	//对每组测试数据进行计算输出
	for(int j=0;j<vecwarriors.size();j++)
	{
		cout<<"Case:"<<icaseid<<endl;
		icaseid++;
		HeadQuarter red(vecwarriors[j][0],0),blue(vecwarriors[j][0],1);
		red.InitSamuraVal(vecwarriors[j][1],vecwarriors[j][2],vecwarriors[j][3],vecwarriors[j][4],vecwarriors[j][5]);
		blue.InitSamuraVal(vecwarriors[j][1],vecwarriors[j][2],vecwarriors[j][3],vecwarriors[j][4],vecwarriors[j][5]);
		
		while(red.IsMakeEnable()||blue.IsMakeEnable())
		{
			if(red.IsMakeEnable())
			{
				do
				{
					if(red.MakeWarrior()) break;
				}while(1);
			}
			
			if(blue.IsMakeEnable())
			{
				do
				{
					if(blue.MakeWarrior()) break;
				}while(1);
			}
		}
	}
	return 0;
}

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页