魔兽世界之二:装备
作者:互联网
#include<iostream>
#pragma warning(disable:4996)
using namespace std;
class CHeadQuarter;
class CWarrior {
int No;
int KindNo;
CHeadQuarter* pHeadQuarter;
public:
static int strength[5];
static const char* Weapon[3];
static const char* warrior[5];
CWarrior(int No_, int KindNo_, CHeadQuarter* p) :No(No_), KindNo(KindNo_), pHeadQuarter(p) {}
virtual void PrintResult(int Ntime);
};
class CDragon :public CWarrior {
private:
int WeaponNo;
double moral;
public:
CDragon(int No_, int KindNo_, CHeadQuarter* p, double moral_) :
CWarrior(No_, KindNo_, p), WeaponNo(No_ % 3), moral(moral_) {}
void PrintResult(int Ntime) {
CWarrior::PrintResult(Ntime);
printf("It has a %s,and it's morale is %.2f\n", CWarrior::Weapon[WeaponNo], moral);
}
};
class CNinja :public CWarrior {
private:
int WeaponNo[2];
public:
CNinja(int No_, int KindNo_, CHeadQuarter* p) :CWarrior(No_, KindNo_, p) {
WeaponNo[0] = (No_ % 3);
WeaponNo[1] = ((No_ + 1) % 3);
}
void PrintResult(int Ntime) {
CWarrior::PrintResult(Ntime);
printf("It has a %s and a %s\n", CWarrior::Weapon[WeaponNo[0]], CWarrior::Weapon[WeaponNo[1]]);
}
};
class CIceman :public CWarrior {
private:
int WeaponNo;
public:
CIceman(int No_, int KindNo_, CHeadQuarter* p) :
CWarrior(No_, KindNo_, p), WeaponNo(No_ % 3) {}
void PrintResult(int Ntime) {
CWarrior::PrintResult(Ntime);
printf("It has a %s\n", CWarrior::Weapon[WeaponNo]);
}
};
class CLion :public CWarrior {
int loyalty;
public:
CLion(int No_, int KindNo_, CHeadQuarter* p, int loyalty_) :
CWarrior(No_, KindNo_, p), loyalty(loyalty_){}
void PrintResult(int Ntime) {
CWarrior::PrintResult(Ntime);
printf("It's loyalty is %d\n", loyalty);
}
};
class CWolf :public CWarrior {
public:
CWolf(int No_, int KindNo_, CHeadQuarter* p) :
CWarrior(No_, KindNo_, p) {}
};
class CHeadQuarter {
int strength;
int TotalNum = 0;
int anWarriorNum[5];
int CurMakIdx = 0;
int color;
bool Stopped = false;
CWarrior* p[10000];
public:
static int MakSeq[2][5];
friend class CWarrior;
CHeadQuarter(int color_, int strength_) :color(color_), strength(strength_) {
for (auto& e : anWarriorNum)
e = 0;
}
~CHeadQuarter() {
for (int i = 0;i < TotalNum;i++)
delete p[i];
}
bool creat(int t);
const char* GetColor() {
return color ? "blue" : "red";
}
};
void CWarrior::PrintResult(int Ntime) {
printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n",
Ntime, pHeadQuarter->GetColor(), CWarrior::warrior[KindNo], No, CWarrior::strength[KindNo], pHeadQuarter->anWarriorNum[KindNo], CWarrior::warrior[KindNo], pHeadQuarter->GetColor());
}
bool CHeadQuarter::creat(int Ntime) {
if (Stopped)
return false;
int searchtimes = 0;
while (strength < CWarrior::strength[MakSeq[color][CurMakIdx]] && searchtimes < 5) {
++searchtimes;
CurMakIdx = (CurMakIdx + 1) % 5;
}
if (searchtimes == 5) {
Stopped = true;
printf("%03d %s headquarter stops making warriors\n", Ntime, GetColor());
return false;
}
int KindNo = MakSeq[color][CurMakIdx];
strength -= CWarrior::strength[KindNo];
CurMakIdx = (CurMakIdx + 1) % 5;
anWarriorNum[KindNo]++;
switch (KindNo)
{
case 0:
p[TotalNum] = new CDragon(TotalNum + 1, KindNo, this, static_cast<double>(strength) / CWarrior::strength[0]);
break;
case 1:
p[TotalNum] = new CNinja(TotalNum + 1, KindNo, this);
break;
case 2:
p[TotalNum] = new CIceman(TotalNum + 1, KindNo, this);
break;
case 3:
p[TotalNum] = new CLion(TotalNum + 1, KindNo, this, strength);
break;
case 4:
p[TotalNum] = new CWolf(TotalNum + 1, KindNo, this);
break;
}
p[TotalNum++]->PrintResult(Ntime);
return true;
}
int CWarrior::strength[5];
const char* CWarrior::warrior[5] = { "dragon","ninja","iceman","lion","wolf" };
const char* CWarrior::Weapon[3] = { "sword", "bomb","arrow" };
int CHeadQuarter:: MakSeq[2][5] = { {2,3,4,1,0},{3,0,1,2,4} };
int main() {
//freopen("C:\\Users\\czh\\Desktop\\2.txt", "r", stdin);
int CaseNum;
scanf("%d", &CaseNum);
for (int i = 1;i <= CaseNum;++i) {
printf("Case:%d\n", i);
int m;
scanf("%d", &m);
for (int j = 0;j < 5;j++)
scanf("%d", &CWarrior::strength[j]);
CHeadQuarter r(0, m), b(1, m);
int t = 0;
while (1) {
bool r_test, b_test;
r_test = r.creat(t);
b_test = b.creat(t);
++t;
if (r_test == 0 && b_test == 0)
break;
}
}
}
标签:魔兽,No,int,装备,CWarrior,strength,之二,Ntime,KindNo 来源: https://blog.csdn.net/qq_33941843/article/details/100834757