CS 116 Lab 04
Inlab Overview
During our inlab session we'll be working to motivate the new concepts of subclassing and inheritance. To that end, we'll be working on a new facet of our IF engine: monster battles!
You'll need these files (zipped) to work on in class.
Some ideas for enhancements
- Create different monster classes, where
- Each class has a unique name
- Attributes (strength, hit points, etc.) may be randomized
- The formulas for damage taken and caused are updated
- The anger / angerThreshold mechanism is altered
- Inspecting a monster causes it to get angrier
- Inspecting a monster gives us some clue as to whether it's about to attack
- If a monster attacks while the player defends, the monster heals itself for some fraction of the damage it deals
- The amount of anger generated on being attacked is randomized
- If a monster would become angry enough to retaliate during a player's attack, it becomes enraged and attacks during each of the subsequent three turns, dealing 3x damage
- Every few attacks, the monster deals a special attack that causes more damage (or heals itself)
- The monster can heal itself back to full health if it gets damaged to within 5% of its hit points
- Randomize monster encounters (i.e., random class encountered)
- Add a "defense" attribute to both player and monsters that will scale damage
- Update the REPL so as to implement "survival" mode — monster encounters keep happening in a loop until the player dies; a count of defeated monsters is then given
Exercises
1. Monsters!
For this lab, you need to implement 5 different monsters, each a subclass of the
provided Monster
class. Each monster should have a unique name and behavior
— you can choose from the suggested enhancements above or come up with your
own. At least one of the enhancements should be based on randomized values
(e.g., random HP and damage), and every monster should be realistically
"beatable". Simply varying the damage formula is not sufficient – there must
be some non-trivial difference in behavior in all your monsters!
Note: please be sure to describe, in a comment atop each monster subclass, what its intended unique behavior is (just in case it isn't entirely obvious from examining your source).
2. Survival mode
Having implemented so many monsters, your next step is to modify the REPL so that:
- a random monster (out of your roster of 5) is encountered when the game is started
- after defeating a monster, a new monster is encountered
- after the player is defeated, the total number of monsters defeated in this round is printed out
3. Monster roll call
Finally, to give the player the satisfaction of knowing what monsters were
vanquished, make the necessary additions to your REPL so that when the game is
over (i.e., the player is defeated), information on each monster is printed out,
in the order they were defeated. At a minimum, the name and strength (you should
create a new accessor for this) of each monster should be printed out. You may
assume some maximum cap on defeated monsters (e.g., 100). You should use an
array of Monster
s for this exercise.
4. Battle statistics
Update your game so that the number of hits taken and damage taken/inflicted by each monster is recorded and reported at the end of the session.
With all the changes discussed above, a game session might look something like this (with two monster classes):
You encounter a Pterodactyl Battle commands: i=inspect, a=attack, d=defend, h=help: [ 100.00 HP ] > i The Pterodactyl has 15.00 HP left. [ 100.00 HP ] > a You attack! You hit the Pterodactyl for 0.18 damage! [ 100.00 HP ] > a You attack! You hit the Pterodactyl for 0.34 damage! [ 100.00 HP ] > a You attack! You hit the Pterodactyl for 1.42 damage! [ 100.00 HP ] > a You attack! You hit the Pterodactyl for 0.31 damage! The Pterodactyl retaliates for 44.05 damage! [ 55.95 HP ] > a You attack! You hit the Pterodactyl for 7.54 damage! [ 55.95 HP ] > a You attack! You hit the Pterodactyl for 7.12 damage! You vanquished the Pterodactyl! You encounter a Pterodactyl Battle commands: i=inspect, a=attack, d=defend, h=help: [ 55.95 HP ] > a You attack! You hit the Pterodactyl for 4.68 damage! [ 55.95 HP ] > a You attack! You hit the Pterodactyl for 3.19 damage! [ 55.95 HP ] > a You attack! You hit the Pterodactyl for 2.99 damage! [ 55.95 HP ] > a You attack! You hit the Pterodactyl for 9.10 damage! You vanquished the Pterodactyl! You encounter a Vampire Battle commands: i=inspect, a=attack, d=defend, h=help: [ 55.95 HP ] > i The Vampire has 20.00 HP left. [ 55.95 HP ] > a You attack! You hit the Vampire for 8.36 damage! [ 55.95 HP ] > a You attack! You hit the Vampire for 7.88 damage! [ 55.95 HP ] > a You attack! You hit the Vampire for 5.93 damage! The Vampire dies, but comes back to life! [ 55.95 HP ] > a You attack! You hit the Vampire for 9.69 damage! The Vampire retaliates for 19.76 damage! [ 36.19 HP ] > a You attack! You hit the Vampire for 2.33 damage! [ 36.19 HP ] > a You attack! You hit the Vampire for 5.33 damage! [ 36.19 HP ] > a You attack! You hit the Vampire for 4.17 damage! You vanquished the Vampire! You encounter a Pterodactyl Battle commands: i=inspect, a=attack, d=defend, h=help: [ 36.19 HP ] > a You attack! You hit the Pterodactyl for 0.33 damage! [ 36.19 HP ] > a You attack! You hit the Pterodactyl for 5.54 damage! [ 36.19 HP ] > a You attack! You hit the Pterodactyl for 1.43 damage! [ 36.19 HP ] > a You attack! You hit the Pterodactyl for 6.55 damage! The Pterodactyl retaliates for 16.23 damage! [ 19.96 HP ] > a You attack! You hit the Pterodactyl for 1.86 damage! You vanquished the Pterodactyl! You encounter a Pterodactyl Battle commands: i=inspect, a=attack, d=defend, h=help: [ 19.96 HP ] > a You attack! You hit the Pterodactyl for 0.43 damage! [ 19.96 HP ] > a You attack! You hit the Pterodactyl for 5.12 damage! [ 19.96 HP ] > a You attack! You hit the Pterodactyl for 5.04 damage! [ 19.96 HP ] > a You attack! You hit the Pterodactyl for 7.37 damage! You vanquished the Pterodactyl! You encounter a Pterodactyl Battle commands: i=inspect, a=attack, d=defend, h=help: [ 19.96 HP ] > a You attack! You hit the Pterodactyl for 0.50 damage! [ 19.96 HP ] > a You attack! You hit the Pterodactyl for 0.42 damage! [ 19.96 HP ] > a You attack! You hit the Pterodactyl for 9.54 damage! [ 19.96 HP ] > a You attack! You hit the Pterodactyl for 1.65 damage! The Pterodactyl retaliates for 2.55 damage! [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 3.79 damage! You vanquished the Pterodactyl! You encounter a Pterodactyl Battle commands: i=inspect, a=attack, d=defend, h=help: [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 9.47 damage! [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 8.70 damage! You vanquished the Pterodactyl! You encounter a Pterodactyl Battle commands: i=inspect, a=attack, d=defend, h=help: [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 1.15 damage! [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 8.70 damage! [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 7.89 damage! You vanquished the Pterodactyl! You encounter a Pterodactyl Battle commands: i=inspect, a=attack, d=defend, h=help: [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 1.96 damage! [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 1.96 damage! [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 8.50 damage! [ 17.41 HP ] > a You attack! You hit the Pterodactyl for 2.24 damage! The Pterodactyl retaliates for 13.84 damage! [ 3.57 HP ] > a You attack! You hit the Pterodactyl for 6.56 damage! You vanquished the Pterodactyl! You encounter a Vampire Battle commands: i=inspect, a=attack, d=defend, h=help: [ 3.57 HP ] > a You attack! You hit the Vampire for 3.64 damage! [ 3.57 HP ] > a You attack! You hit the Vampire for 4.39 damage! [ 3.57 HP ] > a You attack! You hit the Vampire for 8.50 damage! [ 3.57 HP ] > a You attack! You hit the Vampire for 2.90 damage! The Vampire retaliates for 17.31 damage! You died! You killed 9 monsters before falling in battle. Monster roll call: 1. Pterodactyl <Strength=50.00, Hits taken=6, Damage taken/inflicted=16.92/44.05> 2. Pterodactyl <Strength=50.00, Hits taken=4, Damage taken/inflicted=19.96/0.00> 3. Vampire <Strength=20.00, Hits taken=7, Damage taken/inflicted=43.69/19.76> 4. Pterodactyl <Strength=50.00, Hits taken=5, Damage taken/inflicted=15.70/16.23> 5. Pterodactyl <Strength=50.00, Hits taken=4, Damage taken/inflicted=17.96/0.00> 6. Pterodactyl <Strength=50.00, Hits taken=5, Damage taken/inflicted=15.90/2.55> 7. Pterodactyl <Strength=50.00, Hits taken=2, Damage taken/inflicted=18.17/0.00> 8. Pterodactyl <Strength=50.00, Hits taken=3, Damage taken/inflicted=17.74/0.00> 9. Pterodactyl <Strength=50.00, Hits taken=5, Damage taken/inflicted=21.22/13.84>
There are many different ways that this exercise could be implemented — it is critical that you do so in a way that maximizes code reuse and demonstrates encapsulation (both programming best practices). We'll discuss the recommended strategy in class.
Scoring
- 10 points for your roster of monsters — behavior & implementation are both critical
- 5 points for your REPL improvements in exercise 2
- 5 points for a working monster roll call
- 5 points for properly implemented and functional battle statistics