Advertisement
horozov86

Heroes of Code and Logic VII

Mar 30th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. n = int(input())
  2.  
  3. dictionary_hp = {}
  4. dictionary_mp = {}
  5. for _ in range(n):
  6.     line = input()
  7.     line_split = line.split()
  8.     hero_name = line_split[0]
  9.     hp = int(line_split[1])
  10.     mp = int(line_split[2])
  11.  
  12.     dictionary_hp[hero_name] = hp
  13.     dictionary_mp[hero_name] = mp
  14.  
  15. while True:
  16.     data = input()
  17.     if data == "End":
  18.         break
  19.  
  20.     data_split = data.split(" - ")
  21.     command = data_split[0]
  22.     hero_name = data_split[1]
  23.  
  24.     if command == "CastSpell":
  25.         mp_needed = int(data_split[2])
  26.         spell_name = data_split[3]
  27.         if dictionary_mp[hero_name] > mp_needed:
  28.             dictionary_mp[hero_name] -= mp_needed
  29.             print(f"{hero_name} has successfully cast {spell_name} and now has {dictionary_mp[hero_name]} MP!")
  30.         else:
  31.             print(f"{hero_name} does not have enough MP to cast {spell_name}!")
  32.  
  33.     elif command == "TakeDamage":
  34.         damage = int(data_split[2])
  35.         attacker = data_split[3]
  36.  
  37.         dictionary_hp[hero_name] -= damage
  38.         if dictionary_hp[hero_name] > 0:
  39.             print(f"{hero_name} was hit for {damage} HP by {attacker} and now has {dictionary_hp[hero_name]} HP left!")
  40.         else:
  41.             del dictionary_hp[hero_name]
  42.             del dictionary_mp[hero_name]
  43.             print(f"{hero_name} has been killed by {attacker}!")
  44.  
  45.     elif command == "Recharge":
  46.         amount = int(data_split[2])
  47.         diff = abs(200 - dictionary_mp[hero_name])
  48.         dictionary_mp[hero_name] += amount
  49.         if dictionary_mp[hero_name] > 200:
  50.             print(f"{hero_name} recharged for {min(diff, amount)} MP!")
  51.             dictionary_mp[hero_name] = 200
  52.         else:
  53.             print(f"{hero_name} recharged for {max(200 - dictionary_mp[hero_name], amount)} MP!")
  54.  
  55.     else:
  56.         amount = int(data_split[2])
  57.         diff = abs(100 - dictionary_hp[hero_name])
  58.         dictionary_hp[hero_name] += amount
  59.         if dictionary_hp[hero_name] > 100:
  60.             print(f"{hero_name} healed for {min(diff, amount)} HP!")
  61.             dictionary_hp[hero_name] = 100
  62.         else:
  63.             print(f"{hero_name} healed for {max(100 - dictionary_hp[hero_name], amount)} HP!")
  64.  
  65. for hero_name in dictionary_hp.keys():
  66.     print(hero_name)
  67.     hp = dictionary_hp[hero_name]
  68.     mp = dictionary_mp[hero_name]
  69.     print(f"  HP: {hp}")
  70.     print(f"  MP: {mp}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement