Character Class
Summary
This exercise will create a bare bones simulation of a fantasy fighting game.
Task
- Create a console application.
- Write a class to represent characters in a role-playing game. A character must have statistics for
- strength
- intelligence
- armour
- maximum health
- current health
The first three range from 3 to 18. You should implement the class in such a way as to prevent values outside this range. Full health is commonly around 50 hit points.
- A character must support the following behaviours (methods)
- Attack : Returns an integer reporting how much damage the character does. This is half the
character's strength rounded down.
- TakeDamage: Takes an integer parameter for how much damage the character takes,
returns a boolean, true if the character dies as a result (i.e. hit points < 0). The character's
current hit points are reduced by the damage minus one quarter of their armour (rounded
down).
- Now write a program that creates two characters with random statistics (in the valid range) and makes them fight each other. Each turn, for each character, the program will use the attack value
from one character to damage the other until one of the characters dies. The program should then
write out both characters' stats and declare the winner.
- Run and test this program.
Questions
- Can you extend this program to include a WizardCharacter class? The attack calculation for this character would be 3/4 Intelligence, rounded down, from casting a spell. The maximum armour value allowed by this class would be 10. Randomly select at the start of the 'battle' whether none, one or both of the combatants are wizards.
- Can you modify this example so that armour works differently against damage from spells than from normal attacks? Hint: Damage might need to be a more complex type than just a number.
- Can you change the Attack method to accept a character object as a parameter (you could name it target) and return void, but to still have the same effect in the end?