Goals

  • Identify requirements for a program using polymorphism
  • Create a program to demonstrate your class hierarchy

Assignment

In this assignment, you will create a simple class hierarchy as the basis for a fantasy combat game. Your universe contains Vampires, Barbarians, Blue Men, Medusa and Harry Potter. Each has characteristics for attack, defense, armor, and strength points as follows.

Type Attack Defense Armor Strength Points
Vampire 1 1d12 1d6 * Charm 1 18
Barbarian 2 2d6 2d6 0 12
Blue Men 3 2d10 3d6 3 12 *Mob
Medusa 4 2d6 * Glare 1d6 3 8
Harry Potter 5 2d6 2d6 0 10/20 *Hogwarts

1. Suave, debonair, but vicious and surprisingly resilient!

2. Think Conan or Hercules from the movies. Big sword, big muscles, bare torso.

3. They are small (6" tall), fast and tough. So they are hard to hit and can take some damage. As for the attack value, you can do a LOT of damage when you can crawl inside the armor or clothing of your opponent.

4. Scrawny lady with snakes for hair. They help with fighting. Just dont look at her!

5. Why are you reading this? How can you not know who Harry Potter is?

3d6 is rolling three 6-sided dice, 2d10 is rolling two 10-sided dice, etc.

*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.

*Glare: If a Medusa rolls a 12 in attack, then the target has looked her in the eyes and is turned to stone. The Medusa wins!

*Mob: The Blue Men are actually a swarm of small individuals. For every 4 points of damage (round down), they lose one defense die. For example, when they reach strength of 8 they only have 2d6 for defense.

*Hogwarts: If Harry dies (i.e. strength <=0), he immediately recovers and his total strength becomes 20. If he were to die again, then hes dead.

NOTE: The sample creatures are unbalanced intentionally. This will help you in debugging your program! Some will win a lot, and others will lose a lot.

To resolve an attack, you will need to generate 2 dice rolls. The attacker rolls the appropriate number and type of dice under Attack. The defender rolls the appropriate number and type of dice under Defense. You will subtract the Defense roll from the Attack roll. That is the damage to the defender.

Each class only has its own information or data. When O1 is fighting O2, your program should call O1s attack function. It will return the damage inflicted. Then O2s defense function will take the damage inflicted, roll the specified dice and subtract the damage points from the defense. To apply the damage, you subtract the Armor value. The result is then subtracted from the Strength Points. That value becomes the new Strength Points for the next round. If Strength Points goes to 0 or less, then the character is out of the combat. For example, if one object receives 9 points of damage and rolls 3 for its defense, and has an armor of 4 and strength point of 8, it would take 9 subtract 3, and then 4 for the armor, to receive 2 points of damage, and its new strength point will be 8-2=6.

You need to create a Creature base class. Then you will have a subclass for each of these characters. Note that the Creature class will be an abstract class. For our purposes right now, each subclass will vary only in the values in the table. Since each starts with the same data elements, you will only need one constructor. It is part of your design task to determine what functions you will need. The only value that can change is the Strength Points.

This is the first stage of a larger project. Please do not add any creatures of your own.

You must include your design in your reflections document. In that document, you must discuss what the original design is, and how it changes as you worked through the problem. You must also include a test plan in that document. The test plan should cover all logic paths (you should have each character type have combat with all character types, including another of its own). The program has a random element. You will need to address that in your test plan. It will also affect debugging. Your design should address this (potential) problem as well. Also, you need to show your test results with a brief discussion. Remember to submit this document as PDF file.

It is not hard, just a lot to think about. The TAs will be asked to grade your project against your design. So please do not just throw together some random stuff. If you give us a random design, you will need to explain each step in how you got to the code submitted. In other words, that will make it much more difficult. So, learn a good habit and think about it before you start coding.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.