Advertisement
pacho_the_python

Untitled

Dec 9th, 2023
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.85 KB | None | 0 0
  1. def heroes_dict(num):
  2.     hero_dict = {}
  3.     for i in range(num):
  4.         hero_data = input().split(" ")
  5.         hero_name = hero_data[0]
  6.         hp = int(hero_data[1])
  7.         mp = int(hero_data[2])
  8.         hero_dict[hero_name] = [hp, mp]
  9.     return hero_dict
  10.  
  11.  
  12. def cast_spell(current_hero, needed_mp, spell, current_hero_dict):
  13.     if needed_mp <= current_hero_dict[current_hero][1]:
  14.         current_hero_dict[current_hero][1] -= needed_mp
  15.         return f"{current_hero} has successfully cast {spell} and now has {current_hero_dict[current_hero][1]} MP!"
  16.     else:
  17.         return f"{current_hero} does not have enough MP to cast {spell}!"
  18.  
  19.  
  20. def take_damage(hero, damage, attacker, heroes):
  21.     if heroes[hero][0] > damage:
  22.         heroes[hero][0] -= damage
  23.         return f"{hero} was hit for {damage} HP by {attacker} and now has {heroes[hero][0]} HP left!"
  24.     else:
  25.         del heroes[hero]
  26.         return f"{hero} has been killed by {attacker}!"
  27.  
  28.  
  29. def recharge(hero, recharge_mp, needed_mp, heroes):
  30.     if needed_mp >= recharge_mp:
  31.         heroes[hero][1] += recharge_mp
  32.         return f"{hero} recharged for {recharge_mp} MP!"
  33.     else:
  34.         heroes[hero][1] += needed_mp
  35.         return f"{hero} recharged for {needed_mp} MP!"
  36.  
  37.  
  38. def heal(hero, healed_hp, needed_hp, heroes):
  39.     if needed_hp >= healed_hp:
  40.         heroes[hero][0] += healed_hp
  41.         return f"{hero} healed for {healed_hp} HP!"
  42.     else:
  43.         heroes[hero][0] += needed_hp
  44.         return f"{hero} healed for {needed_hp} HP!"
  45.  
  46.  
  47. def get_info(heroes):
  48.     for k, v in heroes.items():
  49.         print(f"{k}")
  50.         print(f" HP: {v[0]}")
  51.         print(f" MP: {v[1]}")
  52.  
  53.  
  54. def main_func(heroes):
  55.     command_data = input().split(" - ")
  56.     while True:
  57.         command = command_data[0]
  58.         if command == "End":
  59.             get_info(heroes)
  60.             break
  61.  
  62.         if command == "CastSpell":
  63.             hero = command_data[1]
  64.             mp_need = int(command_data[2])
  65.             spell_name = command_data[3]
  66.             print(cast_spell(hero, mp_need, spell_name, heroes))
  67.  
  68.         elif command == "TakeDamage":
  69.             hero = command_data[1]
  70.             damage = int(command_data[2])
  71.             attacker = command_data[3]
  72.             print(take_damage(hero, damage, attacker, heroes))
  73.  
  74.         elif command == "Recharge":
  75.             hero = command_data[1]
  76.             recharge_mp = int(command_data[2])
  77.             needed_mp = 200 - heroes[hero][1]
  78.             print(recharge(hero, recharge_mp, needed_mp, heroes))
  79.  
  80.         elif command == "Heal":
  81.             hero = command_data[1]
  82.             healed_hp = int(command_data[2])
  83.             needed_hp = 100 - heroes[hero][0]
  84.             print(heal(hero, healed_hp, needed_hp, heroes))
  85.  
  86.         command_data = input().split(" - ")
  87.  
  88.  
  89. number = int(input())
  90.  
  91. main_func(heroes_dict(number))
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement