Description
Monster Trials
Create a game where the user must defeat three monsters to pass the trials. Use the following
UML diagram and the method descriptions below to create your program.
Classes:
1. Entity (entity.py) – abstract class that the monsters and the hero extend from.
a. __init__(self, name, hp) – sets the name and hp.
b. name and hp properties – use decorators to get (not set) the values of _name and _hp.
c. take_damage(self, dmg) – deals the damage the entity takes. Subtract the dmg value
from the entity’s _hp. Do not let the hp go past 0 (if it’s negative, reset it back to 0).
d. __str__(self) – return a string with the entity’s name and hp.
e. melee_attack(self, enemy) – abstract – the attack the entity does to another entity.
2. Hero (hero.py) – the user’s character, extends from Entity.
a. __init__(self, name) – passes the name and default hp to the superclass’s init.
b. melee_attack(self, enemy) – deals 2D6 (the sum of two 6-sided dice) damage to the
explicit entity and returns a string description of the attack.
c. ranged_attack(self, enemy) – deals 1D12 (one 12-sided die) damage to the explicit
entity and returns a string description of the attack.
3. EnemyFactory (enemy_factory.py) – interface – template for all enemy factories.
a. create_random_enemy(self) – abstract method (no code) that each concrete factory
overrides to create and return enemy objects.
4. BeginnerFactory (beg_factory.py) – creates easy enemies, extends from EnemyFactory.
a. create_random_enemy(self) – randomly construct and return one of the easy enemies
(EasyGoblin, EasyOgre, or EasyTroll).
5. ExpertFacory (exp_factory.py) – creates difficult enemies, extends from EnemyFactory.
a. create_random_enemy(self) – randomly construct and return one of the difficult
enemies (Goblin, Ogre, or Troll).
6. Goblin (goblin.py), Ogre (ogre.py), Troll (troll.py), EasyGoblin (easy_goblin.py),
EasyOgre (easy_ogre.py), EasyTroll (easy_troll.py) – extend from Entity – the different
types of monsters that the factories will generate.
a. __init__(self) – using super, give each monster a default name and randomize its hp
based on the table below. (Note: give the difficult enemies a scarier name so that it is
easy to tell that the correct factory was used (ex. “Angry Troll” or “Horrible Ogre”)).
b. melee_attack(self, enemy) – randomize the damage based on the table below, deal the
damage to the explicit entity, and return a string describing the attack.
Enemy Goblin Ogre Troll
Easy HP: 5-7, Dmg: 4-6 HP: 7-8, Dmg: 5-8 HP: 6-9, Dmg: 5-9
Difficult HP: 6-10, Dmg: 5-8 HP: 8-12, Dmg: 6-10 HP: 10-14, Dmg: 8-12
Main – prompt the user to enter their name, and a difficulty level. Construct the hero, the
appropriate factory (beginner or expert) and then use that factory to generate a list of three
monsters that the user will fight.
Create a loop that repeats until the hero dies, or until the
monsters are defeated. Have the user choose a monster to fight and the type of attack. The hero
will attack the selected monster with the user’s choice of attack and the resulting string will be
displayed. If the monster is still alive, it will attack the hero back. Display the result of the
monster’s attack. If the monster is slain, then remove it from the list of monsters.
Example Output:
Monster Trials
What is your name? Link
You will face a series of 3
monsters, Link.
Defeat them all to win.
Difficulty:
1.Beginner
2.Expert
1
Choose an enemy to attack:
1. Troll HP: 6
2. Goblin HP: 6
3. Ogre HP: 7
Enter choice: 1
Link HP: 25
1. Sword Attack
2. Arrow Attack
Enter choice: 2
Link pierces a Troll with an arrow
for 11 damage.
You have slain the Troll
Choose an enemy to attack:
1. Goblin HP: 6
2. Ogre HP: 7
Enter choice: 1
Link HP: 25
1. Sword Attack
2. Arrow Attack
Enter choice: 1
Link slashes a Goblin with a sword
for 3 damage.
Goblin bites Link for 6 damage.
Choose an enemy to attack:
1. Goblin HP: 3
2. Ogre HP: 7
Enter choice: 1
Link HP: 19
1. Sword Attack
2. Arrow Attack
Enter choice: 1
Link slashes a Goblin with a sword
for 9 damage.
You have slain the Goblin
Choose an enemy to attack:
1. Ogre HP: 7
Enter choice: 1
Link HP: 19
1. Sword Attack
2. Arrow Attack
Enter choice: 2
Link pierces a Ogre with an arrow
for 5 damage.
Ogre slams Link for 6 damage.
Choose an enemy to attack:
1. Ogre HP: 2
Enter choice: 1
Link HP: 13
1. Sword Attack
2. Arrow Attack
Enter choice: 1
Link slashes a Ogre with a sword
for 10 damage.
You have slain the Ogre
Congratulations! You defeated all
three monsters!
Game Over
Notes:
1. You should have 12 different files: main.py, entity.py, hero.py, enemy_factory.py,
beg_factory.py, exp_factory.py, easy_troll.py, easy_ogre.py, easy_goblin.py, troll.py,
ogre.py, goblin.py.
2. Place your names, date, and a brief description of the program in a comment block at the
top of your main file. Place brief comments throughout your code.
3. Use docstrings to document each of the classes, their attributes, and their methods.
4. Please do not create any global variables or use attributes globally (ie. do not access any
of the attributes using the underscores).
5. Do not create any extra methods, attributes, parameters, or change the class hierarchy.
6. Check all user input using the get_int_range function in the check_input module.
7. You may modify the starting hp of the monsters and the hero. You may also modify the
random damage ranges of the monsters.
8. Thoroughly test your program before submitting:
a. Make sure that your class hierarchy is correct: abstract classes are abstract and
have abstract methods using the @abc.abstractmethod decorator, and the
subclasses extend from the correct superclasses (based on the UML above).
b. Make sure that the random monsters are constructed from the factory that the user
chose (beginner or expert).
c. Make sure that the opposing enemy takes the correct amount of damage when hit
d. Make sure that the monsters are removed from the list when they are defeated.
e. Make sure the game ends when the user runs out of hp or when all three monsters
are defeated.