Пример #1
0
	void battle(Noble& noble){
		cout << getName() << " battles " << noble.getName() << endl;
		if (getStrength() == 0 && getLifeStatus() == false){
			cout << "He's dead, " << noble.getName() << endl;
		}
			if (noble.getStrength() > getStrength()){
				cout << getName() << " is defeated" << endl;
				float ratio = 1 - (float)getStrength() / noble.getStrength();
				noble.changeStrength((int)floor(noble.getStrength() * ratio));
			}
		if (noble.getStrength() < getStrength()){
			cout << noble.getName() << " is defeated." << endl;
			float ratio = 1 - (float)noble.getStrength() / getStrength();
			noble.changeStrength(ratio);
			changeStrength(ratio);
		}
		if (noble.getStrength() == getStrength()){
			cout << "Oh, NO!  They're both dead!  Yuck!" << endl;
			noble.changeStrength(0.0);
			noble.changeStrength(0.0);
		}
		if (protectors.size() != 0){
			for (size_t i = 0; i < protectors.size(); ++i){
				if (protectors[i]->getStrength() > 0){
					protectors[i]->battleCry();
				}
				if (protectors[i]->getStatus()){
					cout << protectors[i]->getName() << " says: Take that in the name of my lord, " << getName() << endl;
				}
			}
		}
	}
Пример #2
0
	void battle(Noble& noble){
		cout << getName() << " battles " << noble.getName() << endl;
		if (noble.getStrength() == 0 || getStrength() == 0){
			cout << "One of these nobles' army is already dead. No battle takes place." << endl;
		}
		else{
			if (noble.getStrength() > getStrength()){
				cout << getName() << " is defeated" << endl;
				float ratio = 1 - (float)getStrength() / noble.getStrength();
				noble.changeStrength((int)floor(noble.getStrength() * ratio));
			}
		}
		if (noble.getStrength() < getStrength()){
			cout << noble.getName() << " is defeated." << endl;
			float ratio = 1 - (float)noble.getStrength() / getStrength();
			noble.changeStrength(ratio);
			changeStrength(ratio);
		}
		if (noble.getStrength() == getStrength()){
			cout << "Oh, NO!  They're both dead!  Yuck!" << endl;
			noble.changeStrength(0.0);
			noble.changeStrength(0.0);
		}
	}
Пример #3
0
	void battle(Noble& otherNoble)
	{
		cout << name << " battles " << otherNoble.getName() << endl;

		if (checkDead() == true && otherNoble.checkDead() == true)
		{
			cout << "Oh, NO! They're both dead! Yuck!" << endl;
		}
		else if (checkDead())
		{
			cout << "He's dead, " << otherNoble.name << endl;
		}
		else if (otherNoble.checkDead())
		{
			cout << "He's dead, " << name << endl;
		}
		else if (getStrength() > otherNoble.getStrength())
		{
			this->display();
			otherNoble.display();

			cout << name << " defeats " << otherNoble.name << endl;
			double ratio = (double)(otherNoble.getStrength()) / (double)(this->getStrength());
			setStrength(ratio * getStrength());
			otherNoble.setStrength(0);
		}
		else if (getStrength() < otherNoble.getStrength())
		{
			this->display();
			otherNoble.display();
			cout << otherNoble.name << " defeats " << name << endl;
			double ratio = (double)(getStrength()) / (double)(otherNoble.getStrength());
			otherNoble.setStrength(ratio * otherNoble.getStrength());
			setStrength(0);
		}
		else if (getStrength() == otherNoble.getStrength())
		{
			this->display();
			otherNoble.display();
			cout << "Mutual Annihalation : " << name << " and " << otherNoble.name;
			cout << " die at each other's hands" << endl;
			setStrength(0);
			otherNoble.setStrength(0);
		}
	}