- This event has passed.
5:00 PM – Python Object Oriented Programming – Sebastian
June 20, 2023 @ 5:00 pm - 6:00 pm
Today We Did
- Introduction to inheritance
- Began Monster System project
- In case you need anything, feel free to email me at sebastian@ayclogic.com
Homework
- Name your homework JUN20_monster_system_hw, please submit by next Monday.
- Homework: Follow the instructions to build on to the code we made in class.a) Add on to our previous code from the MonsterSystem class so that the following monsters get these health and max_attack ranges:
dragon, 100, 50
troll, 50, 20
water_golem, 30, 20
cyclops, 60, 30b) Now we should have 3 variables in our add_monster() method. Use these 3 variables to create a Monster object, passing those 3 variables in as parameters to the constructor.
c) Finally time to use our self.monster_dictionary attribute. Use the species variable as the key, and the object we made in part (b) as the value. AKA, add the new monster object to our dictionary using species as the key.
Code from class in case you lost it:
import random class MonsterSystem: def __init__(self): self.main_menu = """ Main Menu 1. Add Monster 2. List all monsters 3. Play Adventure 4. Exit Enter your selection: """ self.attack_menu = """ 1. Magic attack 2. Sword attack - 10 to 20 damage Enter your selection: """ self.magic_attack_menu = """ What kind of magic attack you want to do: 1. Fire magic - Max damage: 10 2. Water magic - Max damage: 10 3. Earth magic - Max damage: 15 4. Wind magic - Max damage: 8 Enter your selection: """ self.monster_list = ["dragon", "troll", "water_golem", "cyclops"] self.monster_healths = { "dragon": 100 } self.monster_max_attacks = { "dragon": 50 } self.monster_dictionary = {} self.player_health = 200 def add_monster(self): species = random.choice(self.monster_list) health = random.randint(self.monster_healths[species]) max_attack = random.randint(self.monster_max_attacks[species] def application_loop(self): while True: selection = input(self.main_menu) if selection == "1": self.add_monster()