Advertisement
GalinaKG

Heroes of Code and Logic VII

Jul 15th, 2022
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.56 KB | None | 0 0
  1. def cast_spell(name_hero, needed_mp, spell, mp_dict):
  2.     if mp_dict[name_hero] >= needed_mp:
  3.         mp_dict[name_hero] -= needed_mp
  4.         print(f"{name_hero} has successfully cast {spell} and now has {mp_dict[name_hero]} MP!")
  5.     else:
  6.         print(f"{name_hero} does not have enough MP to cast {spell}!")
  7.  
  8.  
  9. def take_damage(name_hero, damage, attacker, hp_dict):
  10.     hp_dict[name_hero] -= damage
  11.     if hp_dict[name_hero] > 0:
  12.         print(f'{name_hero} was hit for {damage} HP by {attacker} and now has {hp_dict[name_hero]} HP left!')
  13.     else:
  14.         del hp_dict[name_hero]
  15.         print(f'{name_hero} has been killed by {attacker}!')
  16.  
  17.  
  18. def recharge(name_hero, amount, mp_dict):
  19.     diff = 200 - mp_dict[name_hero]
  20.     mp_dict[name_hero] += amount
  21.     amount_recovered = 0
  22.     if mp_dict[name_hero] > 200:
  23.         mp_dict[name_hero] = 200
  24.         amount_recovered = diff
  25.     else:
  26.         amount_recovered = amount
  27.     print(f'{name_hero} recharged for {amount_recovered} MP!')
  28.  
  29.  
  30. def heal(name_hero, amount, hp_dict):
  31.     diff = 100 - hp_dict[name_hero]
  32.     hp_dict[name_hero] += amount
  33.     if hp_dict[name_hero] > 100:
  34.         hp_dict[name_hero] = 100
  35.         amount_recovered = diff
  36.     else:
  37.         amount_recovered = amount
  38.     print(f'{name_hero} healed for {amount_recovered} HP!')
  39.  
  40.  
  41. def heroes_commands(heroes_hp, heroes_mp):
  42.     while True:
  43.         command = input()
  44.         if command == 'End':
  45.             break
  46.         command = command.split(' - ')
  47.         hero_name = command[1]
  48.         if 'CastSpell' in command:
  49.             mp_needed = int(command[2])
  50.             spell_name = command[3]
  51.             cast_spell(hero_name, mp_needed, spell_name, heroes_mp)
  52.         elif 'TakeDamage' in command:
  53.             damage = int(command[2])
  54.             attacker = command[3]
  55.             take_damage(hero_name, damage, attacker, heroes_hp)
  56.         elif 'Recharge' in command:
  57.             amount = int(command[2])
  58.             recharge(hero_name, amount, heroes_mp)
  59.         elif 'Heal' in command:
  60.             amount = int(command[2])
  61.             heal(hero_name, amount, heroes_hp)
  62.  
  63.  
  64. def heroes():
  65.     n = int(input())
  66.     heroes_hp = {}
  67.     heroes_mp = {}
  68.  
  69.     for _ in range(n):
  70.         input_line = input().split()
  71.         hero_name = input_line[0]
  72.         hp = int(input_line[1])
  73.         mp = int(input_line[2])
  74.         heroes_hp[hero_name] = hp
  75.         heroes_mp[hero_name] = mp
  76.     heroes_commands(heroes_hp, heroes_mp)
  77.  
  78.     for k, v in heroes_hp.items():
  79.         print(f'{k}\n HP: {v}\n MP: {heroes_mp[k]}')
  80.  
  81.  
  82. heroes()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement