コード例 #1
0
ファイル: hw05.cpp プロジェクト: kristinmoser/CS1124
	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
ファイル: hw05.cpp プロジェクト: kristinmoser/CS1124
	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);
		}
	}