Advertisement
Guest User

Untitled

a guest
Jun 30th, 2020
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. import sys
  2.  
  3.  
  4. def find_best_room(rooms):
  5.     max_value = -sys.maxsize
  6.     for i in range(len(rooms)):
  7.         room_tokens = rooms[i].split()
  8.         if room_tokens[0] == 'chest':
  9.             if int(room_tokens[1]) >= max_value:
  10.                 max_value = int(room_tokens[1])
  11.                 best_room_index = i
  12.     return best_room_index
  13.  
  14.  
  15. initial_health = 100
  16. initial_bitcoins = 0
  17. is_dead = False
  18.  
  19. rooms = input().split('|')
  20.  
  21. health = initial_health
  22. bitcoins = initial_bitcoins
  23. best_room = None
  24. max_bitcoins = 0
  25.  
  26. for i in range(len(rooms)):
  27.     command = rooms[i]
  28.     tokens = command.split()
  29.     if tokens[0] == 'potion':
  30.         health_points = int(tokens[1])
  31.         if health + health_points > initial_health:
  32.             health_points = initial_health - health
  33.             health = initial_health
  34.         else:
  35.             health += health_points
  36.         print(f'You healed for {health_points} hp.')
  37.         print(f'Current health: {health} hp.')
  38.  
  39.     elif tokens[0] == 'chest':
  40.         amount = int(tokens[1])
  41.         print(f'You found {amount} bitcoins.')
  42.         bitcoins += amount
  43.         if bitcoins >= max_bitcoins:
  44.             max_bitcoins = bitcoins
  45.             best_room = find_best_room(rooms)
  46.     else:
  47.         monster = tokens[0]
  48.         attack = int(tokens[1])
  49.         health -= attack
  50.         if health > 0:
  51.             print(f'You slayed {monster}.')
  52.         else:
  53.  
  54.             # best_room = find_best_rooms()
  55.             print(f'You died! Killed by {monster}.')
  56.             print(f'Best room: {best_room}')
  57.             is_dead = True
  58.             break
  59.  
  60. if not is_dead:
  61.     print(f"You've made it!")
  62.     print(f"Bitcoins: {bitcoins}")
  63.     print(f"Health: {health}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement