Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. n = int(input())
  2. max_hp = 100
  3. max_mp = 200
  4.  
  5. heroes_dict = {}
  6.  
  7. for i in range(n):
  8.     line = input().split(" ")
  9.     hero = line[0]
  10.     hp = int(line[1])
  11.     mp = int(line[2])
  12.  
  13.     heroes_dict[hero] = [0] * 2
  14.     heroes_dict[hero][0] = hp
  15.     heroes_dict[hero][1] = mp
  16.  
  17. while True:
  18.     line = input()
  19.     if line == "End":
  20.         heroes_dict = dict(sorted(heroes_dict.items(), key=lambda x: (-x[1][0], x[0])))
  21.  
  22.         for k, v in heroes_dict.items():
  23.             print(f"{k}\nHP: {v[0]}\nMP: {v[1]}")
  24.         break
  25.  
  26.     line = line.split(" - ")
  27.     cmd = line[0]
  28.     hero = line[1]
  29.  
  30.     if cmd == "CastSpell":
  31.         needed_mp = int(line[2])
  32.         spell_name = line[3]
  33.  
  34.         if heroes_dict[hero][1] >= needed_mp:
  35.             heroes_dict[hero][1] -= needed_mp
  36.             print(f"{hero} has successfully cast {spell_name} and now has {heroes_dict[hero][1]} MP!")
  37.         else:
  38.             print(f"{hero} does not have enough MP to cast {spell_name}!")
  39.  
  40.     elif cmd == "TakeDamage":
  41.         damage = int(line[2])
  42.         attacker = line[3]
  43.  
  44.         heroes_dict[hero][0] -= damage
  45.         if heroes_dict[hero][0] > 0:
  46.             print(f"{hero} was hit for {damage} HP by {attacker} and now has {heroes_dict[hero][0]} HP left!")
  47.         else:
  48.             del heroes_dict[hero]
  49.             print(f"{hero} has been killed by {attacker}!")
  50.  
  51.     elif cmd == "Recharge":
  52.         amount = int(line[2])
  53.         if heroes_dict[hero][1] + amount > max_mp:
  54.             amount = max_mp - heroes_dict[hero][1]
  55.             heroes_dict[hero][1] = max_mp
  56.         else:
  57.             heroes_dict[hero][1] += amount
  58.         print(f"{hero} recharged for {amount} MP!")
  59.  
  60.     elif cmd == "Heal":
  61.         amount = int(line[2])
  62.         if heroes_dict[hero][0] + amount > max_hp:
  63.             amount = max_hp - heroes_dict[hero][0]
  64.             heroes_dict[hero][0] = max_hp
  65.         else:
  66.             heroes_dict[hero][0] += amount
  67.         print(f"{hero} healed for {amount} HP!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement