Question: python please class Monster(): def __init__(self, name, hp=20): self.name = name self.type = Normal self.max_hp = hp self.current_hp = hp self.attacks = {'wait': 0} self.exp

python please  python please class Monster(): def __init__(self, name, hp=20): self.name = name
class Monster():
def __init__(self, name, hp=20):
self.name = name
self.type = "Normal"
self.max_hp = hp
self.current_hp = hp
self.attacks = {'wait': 0}
self.exp = 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 }
def add_attack(self, attack_name):
if ((attack_name in self.possible_attacks) and (attack_name not in self.attacks)):
if(len(self.attacks)
self.attacks[attack_name] = self.possible_attacks[attack_name]
return True
else:
weak_attack = min(self.attacks.values())
weak_list = []
for attack in self.attacks:
if self.attacks[attack] == weak_attack:
weak_list.append(attack)
weak_list.sort()
del self.attacks[weak_list[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.possible_attacks) and (attack_name in self.attacks)):
del self.attacks[attack_name]
if len(self.attacks) == 0:
self.add_attack('wait')
return True
else:
return False
def win_fight(self):
self.exp = self.exp + 5
self.current_hp = self.max_hp
def lose_fight(self):
self.exp = self.exp + 1
self.current_hp = self.max_hp
class Ghost(Monster):
def win_fight(self):
#your code here
def lose_fight(self):
#your code here
class Dragon(Monster):
def win_fight(self):
#your code here
def lose_fight(self):
#your code here
13.13 PA4 Q3: Dragons and Ghosts Make 2 monster subclasses: Dragon and ghosts, both of which inherit all of the properties of the Monster class. Both should have their "type attribute updated to 'dragon' and 'ghost' respectively. Dragon and ghosts have the ability to level up! Every time a dragon gains 10 exp all of its attacks gain +1 damage. For Example, at 30 exp a dragon's attack will have each +3 damage total. This does NOT include any new attacks learned after gaining exp. For Ghosts, every time a Ghost gains 10exp it gains +5 to its max hp and therefore current_hp. In order to implement this change the win_fight and lose_fight methods within each subclass to account for these changes. There is no need to change the Monster class or the monster_fight function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!