Пример #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;
			}
		}	
	}		
Пример #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());
			
		}
	}