- Develop classes from program requirements
- Implement characters using polymorphism
- Implement a menu to allow the user to test the characters
Develop a two player fantasy combat game that contains an abstract class, Characters, and five different characters (Vampire, Harry Potter, Barbarian, Blue Men, and Medusa) that inherit attributes, such as strength and armor, and functions, such as attack and defense, from the abstract class.
Each character type has unique characteristics that include a different roll for attack and defense, a value for protective armor, and a starting value for strength. These characters also have a special ability which bolsters their attack or defense, with the exception of the hulky Barbarian who merely exudes brute strength.
The following revised class diagram depicts the necessary classes for this program and their relationships:
At the start of the program, the menu prints to invite users to play the game or quit and should they elect to battle, prompts them to select a character for each player from the options. Once the characters have been selected, the character descriptions are printed to the screen along with the character’s particular special ability.
After characters have been selected, the fantasy combat game begins. The following actions occur in each round of the game until one character runs out of strength and is thus defeated:
- Player 1 rolls their attack die
- Player 2 rolls their defense die
- Damage is calculated (damage = attack – defense – armor) and applied to player 2
- Player 2 rolls their attack die
- Player 1 rolls their defense die
- Damage is calculated (damage = attack – defense – armor) and applied to player 1
During each attack, there is a possibility of a character’s special ability being enacted. These abilities are as follows:
Medusa – Glare: If a Medusa rolls a 12 when attacking then the target instantly gets turned into stone and Medusa wins! If Medusa uses Glare on Harry Potter on his first life, then Harry Potter comes back to life.
Vampire – Charm: Vampires can charm an opponent into not attacking. For a given attack there is a 50% chance that their opponent does not actually attack them.
Blue Men – Mob: Blue Men are actually a swarm of small individuals and thus their defense roll is mighty (3 6-sided dice). For every 4 points of damage, they lose one defense die.
Harry Potter – Hogwarts: If Harry Potter’s strength reaches 0 or below, he immediately recovers and his total strength becomes 20. If he were to die again, then he’s dead.
Barbarian – none… : (
Below are a few example rounds of game play demonstrating the randomized attack and defense rolls between a Harry Potter and Vampire character:
Once a player’s character has reached a strength of zero or below, the game is over and the final results are printed to the screen, including the final strengths of each character and recognition of the winner. After the user hits enter at the end of a game, the original menu will print again for the user to either play the game again or quit.
To view the source code for this ghoulish combat game, visit my Fantasy Combat Github repository!