Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* Game with 4 different types of creatures: humans, cyberdemons, balrogs, and elves. We will be simulating a match between them */ /* Rules */

/* Game with 4 different types of creatures: humans, cyberdemons, balrogs,

and elves. We will be simulating a match between them */

/* Rules */

/* 1 - Every creature inflicts damage that is a random number r, where 0 <

r <= strength */

/* 2 - Balrogs, and Cyberdemons have a 5% chance of inflicting a demonic

attack, which is an additional 50 damage points */

/* 3 - Elves have a 10% chance to inflict a magical attack that doubles

the normal amount of damange */

class Creature {

private:

string description;

int strength; // How much maximum damage can the creature inflict

int hitpoints; // How much damage can it sustain before dying

int damagesustained; // Records the damage sustained by the creature.

Starts out with zero. Creature dies when damagesustained >= hitpoints

public:

string getDescription() {return description;}

int getDamagesustained() {return damagesustained}

int setDamagesustained(int d) : damagesustained{d} {}

virtual void attack()=0; // Creature attacks. Each dervied class will

implement the appropriate attack

};

// To do - Code up Humans, Cyberdemons, Balrogs, and Elves classes all

derived from Creature class with appropriate attack() methods

// You can put all the code in this one file for this assignment.

int main()

{

Humans* hum = new Humans("human", 100, 100, 0); // Description,

strength, hitpoints

Cyberdemons* cyb = new Cyberdemons("cyberdemon", 200, 100, 0);

Balrogs* bal = new Balrogs("balrog", 50, 200, 0);

Elves* elv = new Elves("elves", 200, 200, 0);

cout << "And the winner between humans and cyberdemons is..." <<

match(hum, cyb) << endl;

cout << "And the winner between balrogs and elves is..." << match(bal,

elv) << endl;

cout << "And the winner between cyberdemons and balrogs is..." <<

match(cyb, bal) << endl;

return 0;

}

string match(Creature* c1, Creature* c2)

{

// Round 1

c1->attack();

c2->attack();

// Round 2

c1->attack();

c2->attack();

// Round 3

c1->attack();

c2->attack();

// Winner!

if (c1->getDamagesustained() >= c2->getDamagesustained())

return c1->getDescription();

else

return c2->getDescription(;)

}

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions