Suppose that you are creating a game. In this game we have four different types of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Suppose that you are creating a game. In this game we have four different types of creatures: humans, cyberdemons, balrogs, and elves. To represent one of these creatures we might define a Creature class as follows: class Creature. { private: } // 0 human, 1 cyberdemon, 2 balrog, 3 elf // How much damage we can inflict int hitpoints; // How much damage we can sustain string getSpecies (); // Returns type of species, for Creature class. // returns "unknown" public: int type; int strength; Creature ( ) ; // Initialize to human, 10 strength, 10 hit points Creature (int newType, int newStrength, int newHit); // Initialize creature to new type, strength, hit points. // inflicts in one round of combat }; Here is an initial implementation of the getSpecies () function: string Creature::getSpecies () { // Also add appropriate accessor and mutator functions // for type, strength, and hit points ● int getDamage (); // Returns amount of damage this creature. switch (type) { ● case 0: return "Human"; case 1: return "Cyberdemon"; case 2: return "Balrog"; case 3: return "Elf"; ● } return "Unknown"; The get Damage () function outputs and returns the damage this creature can inflict in one round of combat. The rules for calculating the damage are as follows: Every creature inflicts damage that is a random number r, where 0 < r <= strength. Demons have a 5% chance of inflicting a demonic attack which is an additional 50 damage points. Balrogs and Cyberdemons are demons. With a 10% chance elves inflict a magical attack that doubles the normal amount of damage. Balrogs are very fast, so they get to attack twice. An initial implementation of get Damage () is given below: int Creature::getDamage () { int damage; // All creatures inflict damage which is a // random number up to their strength (rand() damage strength) + 1; cout << get Species () << " attacks for " << damage << " points!" << endl; // Demons can inflict damage of 50 with a 5% chance if ((type = 2) || (type == 1)) if ((rand() %100) < 5) { } // Elves inflict double magical damage with a 10% chance if (type == 3) { damage damage + 50; cout << "Demonic attack inflicts 50 " << " additional damage points!" << endl; ● if ((rand() %10)==0) { } cout << "Magical attack inflicts " << damage << " additional damage points!" << endl; damage * 2; damage // Balrogs are so fast they get to attack twice if (type == 2) { int damage2 = (rand() % strength) + 1; cout << "Balrog speed attack inflicts " << damage2 << " additional damage points!" << endl; damage = damage + damage2; } return damage; Rewrite the class to use inheritance, which will eliminate the need for the variable type. The Creature class should be the base class. ● The classes Demon, Elf, and Human should be derived from Creature. The classes Cyberdemon and Balrog should be derived from Demon. You will need to rewrite the getSpecies () and get Damage () functions so they are appropriate for each class. For example, the get Damage () function in each class should only compute the damage appropriate for that object. The total damage is then calculated by combining the results of get Damage () at each level of the inheritance hierarchy. As an example, invoking get Damage ( ) for a Balrog object should invoke getDamage () for the Demon object which should invoke get Damage ( ) for the Creature object. This will compute the basic damage that all creatures inflict, followed by the random 5% damage that demons inflict, followed by the double damage that balrogs inflict. ● Also include mutator and accessor functions for the private variables. Notice that you need to implement getDamage() and getSpecies() functions as virtual functions. Write a stand-alone function called battleArena you are given the header of it: battleArena (Creature &creaturel, Creature &creature2), This function takes two Creature objects as input. The function should calculate the damage done by creaturel, subtract that amount from creature2's 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. Here is a sample main function: int main() { srand(static_cast<int>(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); sample run: 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... Suppose that you are creating a game. In this game we have four different types of creatures: humans, cyberdemons, balrogs, and elves. To represent one of these creatures we might define a Creature class as follows: class Creature. { private: } // 0 human, 1 cyberdemon, 2 balrog, 3 elf // How much damage we can inflict int hitpoints; // How much damage we can sustain string getSpecies (); // Returns type of species, for Creature class. // returns "unknown" public: int type; int strength; Creature ( ) ; // Initialize to human, 10 strength, 10 hit points Creature (int newType, int newStrength, int newHit); // Initialize creature to new type, strength, hit points. // inflicts in one round of combat }; Here is an initial implementation of the getSpecies () function: string Creature::getSpecies () { // Also add appropriate accessor and mutator functions // for type, strength, and hit points ● int getDamage (); // Returns amount of damage this creature. switch (type) { ● case 0: return "Human"; case 1: return "Cyberdemon"; case 2: return "Balrog"; case 3: return "Elf"; ● } return "Unknown"; The get Damage () function outputs and returns the damage this creature can inflict in one round of combat. The rules for calculating the damage are as follows: Every creature inflicts damage that is a random number r, where 0 < r <= strength. Demons have a 5% chance of inflicting a demonic attack which is an additional 50 damage points. Balrogs and Cyberdemons are demons. With a 10% chance elves inflict a magical attack that doubles the normal amount of damage. Balrogs are very fast, so they get to attack twice. An initial implementation of get Damage () is given below: int Creature::getDamage () { int damage; // All creatures inflict damage which is a // random number up to their strength (rand() damage strength) + 1; cout << get Species () << " attacks for " << damage << " points!" << endl; // Demons can inflict damage of 50 with a 5% chance if ((type = 2) || (type == 1)) if ((rand() %100) < 5) { } // Elves inflict double magical damage with a 10% chance if (type == 3) { damage damage + 50; cout << "Demonic attack inflicts 50 " << " additional damage points!" << endl; ● if ((rand() %10)==0) { } cout << "Magical attack inflicts " << damage << " additional damage points!" << endl; damage * 2; damage // Balrogs are so fast they get to attack twice if (type == 2) { int damage2 = (rand() % strength) + 1; cout << "Balrog speed attack inflicts " << damage2 << " additional damage points!" << endl; damage = damage + damage2; } return damage; Rewrite the class to use inheritance, which will eliminate the need for the variable type. The Creature class should be the base class. ● The classes Demon, Elf, and Human should be derived from Creature. The classes Cyberdemon and Balrog should be derived from Demon. You will need to rewrite the getSpecies () and get Damage () functions so they are appropriate for each class. For example, the get Damage () function in each class should only compute the damage appropriate for that object. The total damage is then calculated by combining the results of get Damage () at each level of the inheritance hierarchy. As an example, invoking get Damage ( ) for a Balrog object should invoke getDamage () for the Demon object which should invoke get Damage ( ) for the Creature object. This will compute the basic damage that all creatures inflict, followed by the random 5% damage that demons inflict, followed by the double damage that balrogs inflict. ● Also include mutator and accessor functions for the private variables. Notice that you need to implement getDamage() and getSpecies() functions as virtual functions. Write a stand-alone function called battleArena you are given the header of it: battleArena (Creature &creaturel, Creature &creature2), This function takes two Creature objects as input. The function should calculate the damage done by creaturel, subtract that amount from creature2's 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. Here is a sample main function: int main() { srand(static_cast<int>(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); sample run: 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...
Expert Answer:
Answer rating: 100% (QA)
class Creature protected int strength int hitpoints public Creatureint newStrength 10 int newHit 10 strengthnewStrength hitpointsnewHit virtual stdstr... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Four different types of solar energy collectors were tested. Each was tested at five randomly chosen times, and the power (in watts) was measured. The results were as follows. a. Construct an ANOVA...
-
Suppose that you are a monopolist who produces gizmos, Z, with the total cost function C(Z) = F + 50Z, where F represents the firm's fixed cost. Your marginal cost is MC = 50. Suppose also that there...
-
Suppose that you are measuring the time to receive a TPDU. When an interrupt occurs, you read out the system clock in milliseconds. When the TPDU is fully processed, you read out the clock again. You...
-
Comparative income statements are available for Johanna's Fine Furs: Required Perform horizontal and vertical analyses on each of the items in the above comparative income statements. Round...
-
The National Oceanic Research Institute is planning a research study on global warming in Antarctica. The 16-month network schedule is presented below. It is followed by budgets for each activity....
-
The shareholders of an older established company expect a 10% return, while the company itself reports that it expects to be able to invest in projects with a 12% return in the future.The board of...
-
What difficulties do you think would be encountered in developing a computer program to implement the DUPLEX algorithm? For example, how efficient is the procedure likely to be for large sample...
-
McNally Corporation reported various transactions in 20X2: a. Equipment with an original cost of $ 65,000 and accumulated depreciation of $ 52,000 was deemed unusable and was sold for $ 500 scrap...
-
- Let [121] A-03 1 4 12 If possible, find a matrix C such that 1 2 AC=01 41
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
In the final analysis, who is responsible for deciding which materials are biologically safe for use in dentistry. The in vivo effect of substances eluted from dental materials on the immune system...
-
North Carolina State University Poole College of Management BUS 420 Financial Management of Corporations Capital Structure 1. The Vacation Day Lawn Chair Company (VDLC) is an unleveraged firm with...
-
Part 2: Real and Nominal Risk-free Rates-Theory In Part 2, we are going to explore the concept of nominal and real risk-free rates. The nominal risk-free rate tells us how many additional pictures of...
-
QUESTION 1 A 5/1 adjustable rate mortgage has affixed rate period for five years and then the rate can adjust once every year. O True O False QUESTION 2 A mortgage loan is a loan secured by real...
-
I A 2 B 4 Investment A 5 Investment B 5 Investment C 7 B 3 _0 _1 2 3 Investment A B _0 1 2 Investment A 3 Investment B 4 Investment C 5 6 Formulas 7 Growth Rate (Expected) Year 0 11% $3,000 6%...
-
GameWorld Co. Game World Co. was one of the largest chains of video game rental stores in the greater Boston area, operating 17 wholly owned outlets. Begun in 1998 as a small store in Coolidge Corner...
-
Let (an)neN) CR be a sequence. (a) Show that lim supn an suPnen an. (b) Find a sequence (an) for which the inequality above is strict. (c) Show that lim infn an lim supn an. (d) Show that the...
-
What impact has the Internet had on the globalization of small firms? How do you think small companies will use the Internet for business in the future?
-
Consider an industry with the following structure. There are 50 firms that behave in a competitive manner and have identical cost functions given by c(y) = y2/2. There is one monopolist that has 0...
-
The demand function for drangles is q(p) = (p + 1)2. (a) What is the price elasticity of demand at price p? 2p/(p+1). (b) At what price is the price elasticity of demand for drangles equal to 1? (c)...
-
In Gas Pump, South Dakota, there are two kinds of consumers, Buick owners and Dodge owners. Every Buick owner has a demand function for gasoline DB (p) = 20 5p for p 4 and DB (p) = 0 if p > 4....
-
Henry Ford, founder of Ford Motor Company, is quoted as saying that customers could choose a car in any color as long as it was black. Things have come a long way since that timewhen customization...
-
Not long ago, New England Confectionery Company, or Necco for short, marked the production of its one trillionth candy wafer. The humble roots of Necco, the country's oldest continuously operating...
-
What is utility?
Study smarter with the SolutionInn App