Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

make sure you read the question: Can somebody help me create stand-alone function as follow: Write a stand-alone function called battleArena you are given the

make sure you read the question: Can somebody help me create stand-alone function as follow: Write a stand-alone function called battleArena you are given the header of it: battleArena(Creature &creature1, Creature &creature2), This function takes two Creature objects as input. The function should calculate the damage done by creature1, subtract that amount from creature2s hit points, and vice versa. At the end of each round, if one creature has positive hit points but the other does not then the battle is over. This means that the function has a loop until the battle is either a tie or over. If both creatures end up with zero or less hit points then the battle is a tie. Otherwise, whoever has hit points less than zero loses. thanks in advance! please do as follow or i'll go through the trouble and report you!

here is the sample run of what the output should look like after adding the above:

Human attacks for 12 points! Elf attacks for 4 points! Balrog attacks for 27 points! Balrog speed attack inflicts 49 additional damage points! Cyberdemon attacks for 2 points! Elf attacks for 42 points! Creature 2 has 8 hit points. Balrog attacks for 19 points! Balrog speed attack inflicts 41 additional damage points! Creature 1 has -10 hit points. Creature 2 wins! Press any key to continue . . .

here is my code:

#include #include #include #include using namespace std;

class Creature { private: int strength; int hitpoints; string getSpecies(); public: Creature( ) { strength = 10; hitpoints = 10; }

Creature(int newStrength, int newHit) { strength = newStrength; hitpoints = newHit; } int setStrength(int newStrength); int setHit(int newHit); int getStrength(); int getHit(); int getDamage();

};

class Human : public Creature { public: Human(); //Initializes to Creature() defaults Human(int newStrength, int newHit); int getDamage();

private: string getSpecies( );

};

class Elf : public Creature { public: Elf(); //Initializes to Creature defaults Elf(int newStrength, int newHit); int getDamage();

private: string getSpecies( );

};

class Demon : public Creature { public: Demon(); //Initializes to Creature defaults Demon(int newStrength, int newHit); int getDamage(); int getStrength(); //Accesses strength from base class

private: //empty };

class Cyberdemon : public Demon { public: Cyberdemon(); //Initializes to Demon default then to Creature default Cyberdemon(int newStrength, int newHit); int getDamage();

private: string getSpecies( ); };

class Balrog : public Demon { public: Balrog(); //Initializes to Demon default then to Creature default Balrog(int newStrength, int newHit); int getDamage();

private: string getSpecies( ); };

int main () { srand(static_cast(time(NULL))); Human human1(30, 10); human1.getDamage(); cout << endl; Elf elf1; elf1.getDamage(); cout << endl; Balrog balrog1(50, 50);; balrog1.getDamage(); cout << endl; Cyberdemon cdemon(30, 40); cdemon.getDamage(); cout << endl; Elf elf2(50, 50); Balrog balrog2(50, 50); cout << endl; battleArena(elf2, balrog2); } int Creature::setStrength(int newStrength) { strength = newStrength; }

int Creature::setHit(int newHit) { hitpoints = newHit; }

int Creature::getStrength() { return strength; }

int Creature::getHit() { return hitpoints; }

int Creature::getDamage() { int damage; // All creatures inflict damage, which is a // random number up to their strength

damage = (rand( ) % strength) + 1; return damage; }

Human::Human( ) : Creature( ) { //empty }

Human::Human(int newStrength, int newHit) : Creature(newStrength, newHit) { //empty }

int Human::getDamage() { int damage = Creature::getDamage(); cout << getSpecies() << " attacks for " << damage << " points! "; }

string Human::getSpecies() { return "Human"; }

Elf::Elf() : Creature( ) { //empty }

Elf::Elf(int newStrength, int newHit) : Creature(newStrength, newHit) { //empty }

string Elf::getSpecies() { return "Elf"; }

int Elf::getDamage() { int damage = Creature::getDamage(); cout << getSpecies() << " attacks for " << damage << " points!" << endl;

if ((rand( ) % 10) == 0) { cout << "Magical attack inflicts " << damage << " additional damage points!" << endl; damage = damage * 2; } return damage; }

Demon::Demon() : Creature( ) { //empty }

Demon::Demon(int newStrength, int newHit) : Creature(newStrength, newHit) { //empty }

int Demon::getDamage() { int damage = Creature::getDamage(); cout << " attacks for " << damage << " points!" << endl;

if ((rand( ) % 100) < 5) { damage = damage + 50; cout << "Demonic attack inflicts 50" << " additional damage points!" << endl; } return damage; }

int Demon::getStrength() { Creature::getStrength(); }

Cyberdemon::Cyberdemon() : Demon() { //empty }

Cyberdemon::Cyberdemon(int newStrength, int newHit) : Demon(newStrength, newHit) { //empty }

string Cyberdemon::getSpecies() { return "Cyberdemon"; }

int Cyberdemon::getDamage() { cout << getSpecies(); Demon::getDamage(); }

Balrog::Balrog() : Demon() { //empty }

Balrog::Balrog(int newStrength, int newHit) : Demon(newStrength, newHit) { //empty }

string Balrog::getSpecies() { return "Balrog"; }

int Balrog::getDamage() { cout << getSpecies(); Demon::getDamage(); int damage2 = (rand() % Demon::getStrength()) + 1; cout << "Balrog speed attack inflicts " << damage2 << " additional damage points!" << endl; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Explain the market segmentation.

Answered: 1 week ago

Question

Mention the bases on which consumer market can be segmented.

Answered: 1 week ago

Question

7. Discuss the key features of the learning organization.

Answered: 1 week ago