Beispiel #1
0
	void battle(Noble& opponent) { 
		cout << get_name() << " battles " << opponent.get_name() << endl;
		if (is_alive() == true){ //checks if noble is alive
			if (opponent.is_alive() == true) { //checks if opponent is alive
				battle_cry();
				opponent.battle_cry();
				double noble_str = 0, opponent_str = 0;
				noble_str = get_str();
				opponent_str = opponent.get_str();
				if (get_str() < opponent.get_str()) { //noble is weaker than opponent
					cout << opponent.get_name() << " defeats " << get_name() << endl;
					double factor = get_str() / opponent.get_str();
					set_str(0);
					set_alive();
					opponent.set_str(factor);
				}	 
				else if (get_str() > opponent.get_str()) { //noble is stronger than opponent
					cout << get_name() << " defeats " << opponent.get_name() << endl;
					double factor = opponent.get_str() / get_str();
					opponent.set_str(0);
					opponent.set_alive();
					set_str(factor);
		 		}
		 		else if (get_str() == opponent.get_str()) {
				cout << "They both killed each other!" << endl;
				set_str(0);
				opponent.set_str(0);
				}
			}
			else {
				cout << opponent.get_name() << " is already dead!" << endl;
			}
		}
		else if (get_str() == 0 && opponent.get_str() == 0) {
				cout << "THEY'RE BOTH DEAD!!" << endl;
		}
		else {
			if (opponent.is_alive() == false) {
				cout << "They're both dead already!" << endl;
			}
			else {
				cout << get_name() << " is already dead!" << endl;
			}
		}	
	}		
Beispiel #2
0
	//pretty similar to the last hw's, with some mods
	void battle(Noble& opponent) {
		cout << noble_name << " battles " << opponent.get_name() << endl;
		if (get_army_strength() == 0 && opponent.get_army_strength() == 0) {
			cout << "THEY'RE BOTH DEAD!!" << endl;
		}
		else if (get_army_strength() == 0) {
			cout << get_name() << " is already dead!" << endl;
			}
		else if (opponent.get_army_strength() == 0) {
			cout << opponent.get_name() << " is already dead!" << endl;
			}
		else if (get_army_strength() == opponent.get_army_strength()) {
			cout << "They both killed each other!" << endl;
			set_army_hp(0);
			opponent.set_army_hp(0);
			}
		else if (get_army_strength() < opponent.get_army_strength()) {
			cout << opponent.get_name() << " defeats " << get_name() << endl;
			set_army_hp(0);
			int factor = get_army_strength() / opponent.get_army_strength();
			for (size_t i = 0; i < army.size(); i++) {
				int modified_hp = army[i] -> get_hp() * factor;
				army[i] -> set_hp(modified_hp);
			}
			//opponent.set_army_hp(get_army_strength() - opponent.get_army_strength());
			}	 
		else if (get_army_strength() > opponent.get_army_strength()) {
			cout << get_name() << " defeats " << opponent.get_name() << endl;
			opponent.set_army_hp(0);
			int factor = opponent.get_army_strength() / get_army_strength();
			for (size_t i = 0; i < army.size(); i++) {
				int modified_hp = army[i] -> get_hp() * factor;
				army[i] -> set_hp(modified_hp);
			}
			//set_warrior_hp(get_army_strength() - opponent.get_army_strength());
			
		}
	}
Beispiel #3
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;
				}
			}
		}
	}
Beispiel #4
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);
		}
	}
Beispiel #5
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);
		}
	}