Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. class Monster:
  2. def __init__(self, name, hp=20):
  3. self.exp = 0
  4. self.name = name
  5. self.type = "Normal"
  6. self.max_hp = hp
  7. self.current_hp = self.max_hp
  8. self.attacks = {"wait":0}
  9. self.possible_attacks = {"sneak_attack":1, "slash":2, "ice_storm":3, "fire_storm":3, "whirlwind":3, "earthquake":2, "double_hit":4, "wait":0}
  10.  
  11. def add_attack(self, attack_name):
  12. if((attack_name in self.possible_attacks) and (attack_name not in self.attacks)):
  13. if(len(self.attacks) < 4):
  14. self.attacks[attack_name] = self.possible_attacks[attack_name]
  15. return True
  16.  
  17. else:
  18. weak_attack = min(self.attacks.values())
  19. weak_list = [ ]
  20. for attack in self.attacks:
  21. if self.attacks[attack] == weak_attack:
  22. weak_list.append(attack)
  23. weak_list.sort()
  24. del self.attacks[weak_list[0]]
  25. self.attacks[attack_name] = self.possible_attacks[attack_name]
  26. return True # pass # your code here
  27. else:
  28. return False
  29.  
  30. def remove_attack(self, attack_name):
  31. if((attack_name in self.possible_attacks) and (attack_name in self.attacks)):
  32. del self.attacks[attack_name]
  33. if len(self.attacks) == 0:
  34. self.add_attack("wait")
  35. return True
  36. else:
  37. return False
  38.  
  39. def win_fight(self):
  40. self.exp += 5
  41. self.current_hp = self.max_hp
  42.  
  43. def lose_fight(self):
  44. self.exp += 1
  45. self.current_hp = self.max_hp
  46.  
  47. def sortMoves(mon):
  48. sort = []
  49.  
  50. for i,v in mon.attacks.items():
  51. index = 0
  52.  
  53. while index < len(sort) and (sort[index][1] > v or (sort[index][1] == v and sort[index][0] < i)):
  54. index += 1
  55.  
  56. sort.insert(index, [i,v])
  57.  
  58. return sort
  59.  
  60. def monster_fight(monster1, monster2):
  61. sort1 = sortMoves(monster1)
  62. sort2 = sortMoves(monster2)
  63.  
  64. i = 0
  65. while monster1.current_hp > 0 and monster2.current_hp > 0 and i < 10000:
  66. monster2.current_hp -= sort1[i%len(sort1)][1]
  67. monster1.current_hp -= sort2[i%len(sort2)][1]
  68. print(str(monster1.current_hp) + " - " + str(monster2.current_hp))
  69. i += 1
  70.  
  71. if monster1.current_hp <= 0:
  72. monster1.lose_fight()
  73. monster2.win_fight()
  74. print("monster 2 wins")
  75. elif monster2.current_hp <= 0:
  76. monster1.win_fight()
  77. monster2.lose_fight()
  78. print("monster 1 wins")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement