Advertisement
go6odn28

3_heroes_of_code_and_logic.

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