Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Monster: def __init__(self, name, hp=20) -> None: self.name = name self.type = Normal self.max_hp = hp self.current_hp = self.max_hp self.attacks = {wait:0} self.possible_attacks =

image text in transcribedimage text in transcribed

class Monster: def __init__(self, name, hp=20) -> None: self.name = name self.type = "Normal" self.max_hp = hp self.current_hp = self.max_hp self.attacks = {"wait":0} self.possible_attacks = {'sneak_attack': 1, "slash": 2, "ice_storm": 3, "fire_storm": 3, "whirlwind": 3, "earthquake": 2, "double_hit": 4, "tornado": 4, "wait": 0} pass

def add_attack(self,attack_name): if attack_name in self.possible_attacks.keys(): if(len(self.attacks) == 4): temp = min(self.attacks.values()) res = [key for key in self.attacks if self.attacks[key] == temp] res = res.sort() del self.attacks[res[0]] self.attacks[attack_name] = self.possible_attacks[attack_name] return True else: return False

def remove_attack(self, attack_name): if attack_name in self.attacks.keys(): del self.attacks[attack_name] self.attacks["wait"] = 0 return True else: return False

image text in transcribed

13.11 PA4 Q1: Build a Monster Construct a class "Monster" with the following attributes: 1. self.name (a string) 2. self.type (a string, default is 'Normal') 3. self.current_hp (int, start out equal to max_hp) 4. self.max_hp (int, is given as input when the class instance is created, default is 20) 5. self.attacks (a dictionary of all known attacks) 6. self. possible_attacks (a dictionary of all possible attacks) The dictionary of possible_attacks will map the name of an attack ( the key) to how many points of damage the attack does. They must be of the following list: 1. sneak_attack: 1 2. slash: 2 3. ice storm: 3 4. fire_storm: 3 5. whirlwind: 3 6. earthquake: 2 7. double_hit: 4 8. tornado: 4 9. wait: 0 Every monster will start out with only the "wait" attack within self attacks. You will need to construct the method add_attack and remove_attack. Both methods will take in an attack name as a parameter. A monster can only have a maximum of four attacks at a time. If you add an attack when the monster already has four, the weakest one should be dropped automatically. If there is a tie for the weakest attack, drop the attack that comes first alphabetically. If adding the attack ended successfully, return True. If you try to add an invalid attack return False. If all of a monster's attacks are removed, "wait" should automatically be added again, so that every monster always has at least 1 attack. If removing an attack ended successfully return True. If you try to remove an invalid attack or an attack that has not been learned return false. LAB ACTIVITY 13.11.1: PA4 01: Build a Monster 15/30 main.py Load default template... 1 class Monster(): def __init__(self, name, hp=20): self.exp = 0 #your code here def add_attack(self, attack_name): pass #your code here def remove_attack(self, attack_name): pass #your code here Develop mode Submit mode When done developing your program, press the Submit for grading button below. This will submit your program for auto-grading, Submit for grading What is this? Signature of your work 2/28.. U--- -- |15..3/10 10---10-115-1015 S-115-115101010--115 U|1515|15015 W-11510 1: Unit test 14 5/5 Test setting monster names Test feedback The names of the monsters are set properly 2: Unit test 24 5/5 Test adding monster attacks Test feedback A valid attack was added successfully An invalid attack was not added 3: Unit test 3 A 5/5 Test adding and removing attacks Test feedback Wait attack was removed successfully A valid attack was added successfully Attacks added successfully to the dictionary 4. Unit test 4 A 0/15 Test overall functionality Traceback (most recent call last): TypeError: 'NoneType' object is not subscriptable

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

Catalog a variety of business responses to these stakeholders.

Answered: 1 week ago