Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Monster:
- def __init__(self, name, hp=20):
- self.exp = 0
- 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, "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) < 4):
- 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 # pass # your code here
- 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 += 5
- self.current_hp = self.max_hp
- def lose_fight(self):
- self.exp += 1
- self.current_hp = self.max_hp
- def sortMoves(mon):
- sort = []
- for i,v in mon.attacks.items():
- index = 0
- while index < len(sort) and (sort[index][1] > v or (sort[index][1] == v and sort[index][0] < i)):
- index += 1
- sort.insert(index, [i,v])
- return sort
- def monster_fight(monster1, monster2):
- sort1 = sortMoves(monster1)
- sort2 = sortMoves(monster2)
- i = 0
- while monster1.current_hp > 0 and monster2.current_hp > 0 and i < 10000:
- monster2.current_hp -= sort1[i%len(sort1)][1]
- monster1.current_hp -= sort2[i%len(sort2)][1]
- print(str(monster1.current_hp) + " - " + str(monster2.current_hp))
- i += 1
- if monster1.current_hp <= 0:
- monster1.lose_fight()
- monster2.win_fight()
- print("monster 2 wins")
- elif monster2.current_hp <= 0:
- monster1.win_fight()
- monster2.lose_fight()
- print("monster 1 wins")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement