013:魔兽世界之一:备战
#include <iostream>
#pragma warning(disable:4996)
using namespace std;
class Dragon {
int number;
int strength;
int attack;
public:
Dragon(int n) :strength(n), number(0) {}
int GetStrength() const{
return strength;
}
int GetNumber() const{
return number;
}
void addone() {
number++;
}
};
class Ninja {
int number;
int strength;
int attack;
public:
Ninja(int n) :strength(n), number(0) {}
int GetStrength() const {
return strength;
}
int GetNumber() const {
return number;
}
void addone() {
number++;
}
};
class Iceman {
int number;
int strength;
int attack;
public:
Iceman(int n) :strength(n), number(0) {}
int GetStrength() const {
return strength;
}
int GetNumber() const {
return number;
}
void addone() {
number++;
}
};
class Lion {
int number;
int strength;
int attack;
public:
Lion(int n) :strength(n), number(0) {}
int GetStrength() const {
return strength;
}
int GetNumber() const {
return number;
}
void addone() {
number++;
}
};
class Wolf {
int number;
int strength;
int attack;
public:
Wolf(int n) :strength(n), number(0) {}
int GetStrength() const {
return strength;
}
int GetNumber() const {
return number;
}
void addone() {
number++;
}
};
class Red {
int strength;
int TotalNumber;
Iceman iceman;
Lion lion;
Wolf wolf;
Ninja ninja;
Dragon dragon;
bool can_create;
int create_number;
int time;
public:
Red(int red_strength,int ice_s,int lion_s,int wolf_s,int ninja_s,int dragon_s)
:strength(red_strength), TotalNumber(0),iceman(ice_s),lion(lion_s),wolf(wolf_s),ninja(ninja_s),dragon(dragon_s),
can_create(true), create_number(0),time(0){}
bool CreateLion() {
if (lion.GetStrength() <= strength) {
strength -= lion.GetStrength();
lion.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateIceman() {
if (iceman.GetStrength() <= strength) {
strength -= iceman.GetStrength();
iceman.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateWolf() {
if (wolf.GetStrength() <= strength) {
strength -= wolf.GetStrength();
wolf.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateNinja() {
if (ninja.GetStrength() <= strength) {
strength -= ninja.GetStrength();
ninja.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateDragon() {
if (dragon.GetStrength() <= strength) {
strength -= dragon.GetStrength();
dragon.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateOne();
};
class Blue {
int strength;
int TotalNumber;
Iceman iceman;
Lion lion;
Wolf wolf;
Ninja ninja;
Dragon dragon;
bool can_create;
int create_number;
int time;
public:
Blue(int red_strength, int ice_s, int lion_s, int wolf_s, int ninja_s, int dragon_s)
:strength(red_strength), TotalNumber(0), iceman(ice_s), lion(lion_s), wolf(wolf_s), ninja(ninja_s), dragon(dragon_s),
can_create(true), create_number(0),time(0) {}
bool CreateLion() {
if (lion.GetStrength() <= strength) {
strength -= lion.GetStrength();
lion.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateIceman() {
if (iceman.GetStrength() <= strength) {
strength -= iceman.GetStrength();
iceman.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateWolf() {
if (wolf.GetStrength() <= strength) {
strength -= wolf.GetStrength();
wolf.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateNinja() {
if (ninja.GetStrength() <= strength) {
strength -= ninja.GetStrength();
ninja.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateDragon() {
if (dragon.GetStrength() <= strength) {
strength -= dragon.GetStrength();
dragon.addone();
TotalNumber++;
create_number++;
create_number = create_number % 5;
return true;
}
return false;
}
bool CreateOne();
};
bool Red::CreateOne() {
if (can_create == false)
return false;
int temp = 0;
while (temp++ < 5) {
switch (create_number)
{
case 0:
if (CreateIceman()) {
printf("%03d ", time++);
cout << "red iceman " << TotalNumber << " born with strength " << iceman.GetStrength() << ","
<< iceman.GetNumber() << " iceman in red headquarter" << endl;
return true;
}
break;
case 1:
if (CreateLion()) {
printf("%03d ", time++);
cout << "red lion " << TotalNumber << " born with strength " << lion.GetStrength() << ","
<< lion.GetNumber() << " lion in red headquarter" << endl;
return true;
}
break;
case 2:
if (CreateWolf()) {
printf("%03d ", time++);
cout << "red wolf " << TotalNumber << " born with strength " << wolf.GetStrength() << ","
<< wolf.GetNumber() << " wolf in red headquarter" << endl;
return true;
}
break;
case 3:
if (CreateNinja()) {
printf("%03d ", time++);
cout << "red ninja " << TotalNumber << " born with strength " << ninja.GetStrength() << ","
<< ninja.GetNumber() << " ninja in red headquarter" << endl;
return true;
}
break;
case 4:
if (CreateDragon()) {
printf("%03d ", time++);
cout << "red dragon " << TotalNumber << " born with strength " << dragon.GetStrength() << ","
<< dragon.GetNumber() << " dragon in red headquarter" << endl;
return true;
}
}
create_number++;
create_number = create_number % 5;
}
printf("%03d ", time++);
cout << "red headquarter stops making warriors" << endl;
can_create = false;
return false;
}
bool Blue::CreateOne() {
if (can_create == false)
return false;
int temp = 0;
while (temp++ < 5) {
switch (create_number)
{
case 0:
if (CreateLion()) {
printf("%03d ", time++);
cout << "blue lion " << TotalNumber << " born with strength " << lion.GetStrength() << ","
<< lion.GetNumber() << " lion in blue headquarter" << endl;
return true;
}
break;
case 1:
if (CreateDragon()) {
printf("%03d ", time++);
cout << "blue dragon " << TotalNumber << " born with strength " << dragon.GetStrength() << ","
<< dragon.GetNumber() << " dragon in blue headquarter" << endl;
return true;
}
break;
case 2:
if (CreateNinja()) {
printf("%03d ", time++);
cout << "blue ninja " << TotalNumber << " born with strength " << ninja.GetStrength() << ","
<< ninja.GetNumber() << " ninja in blue headquarter" << endl;
return true;
}
break;
case 3:
if (CreateIceman()) {
printf("%03d ", time++);
cout << "blue iceman " << TotalNumber << " born with strength " << iceman.GetStrength() << ","
<< iceman.GetNumber() << " iceman in blue headquarter" << endl;
return true;
}
break;
case 4:
if (CreateWolf()) {
printf("%03d ", time++);
cout << "blue wolf " << TotalNumber << " born with strength " << wolf.GetStrength() << ","
<< wolf.GetNumber() << " wolf in blue headquarter" << endl;
return true;
}
break;
}
create_number++;
create_number = create_number % 5;
}
printf("%03d ", time++);
cout << "blue headquarter stops making warriors" << endl;
can_create = false;
return false;
}
int main()
{
//freopen("C:\\Users\\czh\\Desktop\\2.txt", "r", stdin);
int case_number,strength, dragon, ninja, iceman, lion, wolf;
cin >> case_number;
for (int i = 1;i <= case_number;i++) {
cout << "Case:" << i << endl;
cin >> strength >> dragon >> ninja >> iceman >> lion >> wolf;
Red r(strength, iceman, lion, wolf, ninja, dragon);
Blue b(strength, iceman, lion, wolf, ninja, dragon);
while (r.CreateOne() && b.CreateOne()) {}
while (r.CreateOne() || b.CreateOne()) {}
}
return 0;
}