Advertisement
BdW44222

03. Heroes of Code and Logic VII

Aug 11th, 2021
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.05 KB | None | 0 0
  1. max_health_points = 100
  2. max_mana_points = 200
  3.  
  4. n = int(input())
  5. heroes_party = {}
  6.  
  7. for _ in range(n):
  8.     hero = input()
  9.     name = hero.split()[0]
  10.     hp = int(hero.split()[1])
  11.     mp = int(hero.split()[2])
  12.  
  13.     if hp <= max_health_points and mp <= max_mana_points:
  14.         if name not in heroes_party:
  15.             heroes_party[name] = {'health_points': 0, 'mana_points': 0}
  16.         heroes_party[name]['health_points'] = hp
  17.         heroes_party[name]['mana_points'] = mp
  18.  
  19. commands = input()
  20.  
  21. while not commands == "End":
  22.     command = commands.split(" - ")[0]
  23.     hero_name = commands.split(" - ")[1]
  24.  
  25.     if command == "CastSpell":
  26.         needed_mana_points = int(commands.split(" - ")[2])
  27.         spell_name = commands.split(" - ")[3]
  28.  
  29.         if needed_mana_points <= heroes_party[hero_name]['mana_points']:
  30.             heroes_party[hero_name]['mana_points'] -= needed_mana_points
  31.  
  32.             print(f"{hero_name}"
  33.                   f" has successfully cast {spell_name}"
  34.                   f" and now has {heroes_party[hero_name]['mana_points']} MP!")
  35.         else:
  36.             print(f"{hero_name} does not have enough MP to cast {spell_name}!")
  37.  
  38.     elif command == "TakeDamage":
  39.         damage = int(commands.split(" - ")[2])
  40.         attacker = commands.split(" - ")[3]
  41.         heroes_party[hero_name]['health_points'] -= damage
  42.  
  43.         if heroes_party[hero_name]['health_points'] > 0:
  44.             print(f"{hero_name} was hit for {damage}"
  45.                   f" HP by {attacker} and now has "
  46.                   f"{heroes_party[hero_name]['health_points']} HP left!")
  47.         else:
  48.             del heroes_party[hero_name]
  49.             print(f"{hero_name} has been killed by {attacker}!")
  50.  
  51.     elif command == "Recharge":
  52.         amount = int(commands.split(" - ")[2])
  53.         heroes_party[hero_name]['mana_points'] += amount
  54.         if heroes_party[hero_name]['mana_points'] > max_mana_points:
  55.             recharged_for = heroes_party[hero_name]['mana_points'] - max_mana_points
  56.             heroes_party[hero_name]['mana_points'] -= recharged_for
  57.             print(f"{hero_name} recharged for {recharged_for} MP!")
  58.         else:
  59.             print(f"{hero_name} recharged for {amount} MP!")
  60.  
  61.     elif command == "Heal":
  62.         amount = int(commands.split(" - ")[2])
  63.         health_before_the_heal = heroes_party[hero_name]['health_points']
  64.         heroes_party[hero_name]['health_points'] += amount
  65.         if heroes_party[hero_name]['health_points'] > max_health_points:
  66.             healed_for = (max_health_points - health_before_the_heal)
  67.             heroes_party[hero_name]['health_points'] = (health_before_the_heal + healed_for)
  68.             print(f"{hero_name} healed for {healed_for} HP!")
  69.         else:
  70.             print(f"{hero_name} healed for {amount} HP!")
  71.     commands = input()
  72.  
  73. survived_heroes = sorted(heroes_party.items(), key=lambda tkvp: (-tkvp[1]['health_points'], tkvp[0]))
  74.  
  75. for player, data in survived_heroes:
  76.     print(f"{player}")
  77.     print(f" HP: {data['health_points']}")
  78.     print(f" MP: {data['mana_points']}")
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement