Question: Write a program that uses class, inheritance, and polymorphism to have three different kinds of characters battle in a simple game. There are three different

Write a program that uses class, inheritance, and polymorphism to have three different kinds of characters battle in a simple game. There are three different types of characters but they have some common characteristic that will be in an abstract base class called Character:

Character has the following data:

? Name

? Health points (HP)

? Experience points (XP) everyone starts at 0.

? Points to next level

? MaxHP (same as starting HP)

You will derive three new classes from this base class:

? Novice: has the additional attribute of luck (int).

? Knight: has the additional attribute of weapon name, weapon power(int), armor(int).

? Wizard: has the additional attribute of magic poiwer source (divine or arcane) (int)

Attribute Values

Attribute Values
Novice Knight Wizard

HP starts at 80

XP starts at 0

Points to Next Level starts at 10

Luck starts at (0 or 1)

HP starts at 120

XP starts at 0

Points to Next Level starts at 10

Armor starts at 1

HP starts at 100

XP starts at 0

Points to Next Level starts at 10

When fighting during the game, a character generates attack (damage) points as described below. Compare the attack points to the strength (AC) of the monster.

? If players attack is greater than AC then you win. You gain experience points. UpdateXP based on the monsters level points. When XP reaches a certain amount (points to next level) you level up and gain some increase in all stats.

? Otherwise you lose. You lose hit/health points. UpdateHP with the monsters AC.

This way you are not keeping up with the HP of the monster.

Novice Knight Wizard
Attack Points A random number from 1 10 + luck value A random number from 10 20 + weapon power A random number from 5 15 + magic bonus (2 points if arcane, 5 points if divine)

XP

Plus monster level points Plus (monster level 1) Plus (monster level 2)
HP Loses enemy damage Loses (enemy damage armor) Loses (enemy damage magic/enemy damage)
Points to Level Up

Level Up every 10 XP points.

Every 12 points HP increases by 10. Luck increases by a random number from (3 5)

Level Up every 15 XP points.

HP increases by 15. Armor +1

Level Up every 12 XP points.

HP increases by 8.

Magic +3

Behaviors

print() Prints all the data specific to that character

getAttack() Generates and returns attack points as specified above

updateHP(int) Takes damage as a parameter. Reduce HP as indicated above

updateXP(int) Takes monsters level points as a parameter. Adjust XP as indicated above. Then check for level up. If there is level up then adjust stats, and increment next level points by 10

heal() Restores HP to maxHP value.

Create abstract methods shown above that will be defined in each of the classes to implement the correct behavior.

Then derive the three classes from that base class. Create and test each of these 3 classes one at a time! Each derived class MUST have a parameterized constructor, and definitions for all virtual functions specific to that class. NOTE THAT YOU MUST USE PARAMETERIZED CONSTRUCTORS in order to create and initialize your objects. You will create a vector of base class pointers. As players are created, use your parameterized constructor to create the appropriate object. This vector will store all the data. Polymorphism and your abstract functions will process the data correctly for each type of player.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!