Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cast_spell(heroes_, commands_):
- name = commands_[1]
- mana_needed = int(commands_[2])
- spell_name = commands_[3]
- if heroes_[name]["MANA"] >= mana_needed:
- heroes_[name]["MANA"] -= mana_needed
- print(f"{name} has successfully cast {spell_name} and now has {heroes_[name]['MANA']} MP!")
- else:
- print(f"{name} does not have enough MP to cast {spell_name}!")
- return heroes_
- def take_damage(heroes_, commands_):
- name = commands_[1]
- damage = int(commands_[2])
- attacker = commands_[3]
- if heroes_[name]["HP"] > damage:
- heroes_[name]["HP"] -= damage
- print(f"{name} was hit for {damage} HP by {attacker} and now has {heroes_[name]['HP']} HP left!")
- else:
- del heroes_[name]
- print(f"{name} has been killed by {attacker}!")
- return heroes_
- def recharge(heroes_, commands_):
- name = commands_[1]
- amount = int(commands_[2])
- amount_recovered = amount
- heroes_[name]["MANA"] += amount
- if heroes_[name]["MANA"] > 200:
- amount_recovered = amount - (heroes_[name]["MANA"] - 200)
- heroes_[name]["MANA"] = 200
- print(f"{name} recharged for {amount_recovered} MP!")
- return heroes_
- def heal(heroes_, commands_):
- name = commands_[1]
- amount = int(commands_[2])
- amount_recovered = amount
- heroes_[name]["HP"] += amount
- if heroes_[name]["HP"] > 100:
- amount_recovered = amount - (heroes_[name]["HP"] - 100)
- heroes_[name]["HP"] = 100
- print(f"{name} healed for {amount_recovered} HP!")
- return heroes_
- heroes = {}
- lines = int(input())
- for _ in range(lines):
- hero_name, hp, mana = input().split()
- hp = int(hp)
- mana = int(mana)
- heroes[hero_name] = {"HP": hp, "MANA": mana}
- while True:
- commands = input().split(" - ")
- command = commands[0]
- if command == "End":
- break
- if command == "CastSpell":
- heroes = cast_spell(heroes, commands)
- elif command == "TakeDamage":
- heroes = take_damage(heroes, commands)
- elif command == "Recharge":
- heroes = recharge(heroes, commands)
- elif command == "Heal":
- heroes = heal(heroes, commands)
- for hero, points in heroes.items():
- print(f"{hero}\n HP: {points['HP']}\n MP: {points['MANA']}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement