Advertisement
Guest User

code

a guest
Sep 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. from random import randint
  2.  
  3. game_running = True
  4. game_results = []
  5.  
  6. def calculate_monster_attack():
  7. return randint(monster['attack_min'], monster['attack_max'])
  8.  
  9. def game_ends(winner_name):
  10. print(f'{winner_name} won the game')
  11.  
  12.  
  13.  
  14.  
  15. while game_running == True:
  16. counter = 0
  17. new_round = True
  18. player = {'name': 'Kat', 'attack': 13, 'heal': 16, 'health': 100}
  19. monster = {'name': 'Beaner', 'attack_min': 10, 'attack_max': 20, 'health':100}
  20.  
  21. print('---' * 7)
  22. print('Enter player Name. ')
  23. player['name'] = input()
  24.  
  25. print('---' * 7)
  26. print(player['name'] + " has " + str(player['health']) + ' health. ')
  27. print(monster['name'] + " has " + str(monster['health']) + " health. ")
  28.  
  29. while new_round == True:
  30. counter = counter + 1
  31. player_won = False
  32. monster_won = False
  33.  
  34. print('---' * 7)
  35. print('Please select action')
  36. print('1) Attack')
  37. print('2) Heal')
  38. print('3) Exit Game')
  39. print('4) Show Results')
  40.  
  41. player_choice = input()
  42.  
  43. if player_choice == '1':
  44. monster['health'] = monster['health'] - player['attack']
  45. if monster['health'] <= 0:
  46. player_won = True
  47.  
  48. else:
  49. calculate_monster_attack()
  50. player['health'] = player['health'] - calculate_monster_attack()
  51. if player['health'] <= 0:
  52. monster_won = True
  53.  
  54.  
  55. elif player_choice == '2':
  56.  
  57. player['health'] = player['health'] + player['heal']
  58. player['health'] = player['health'] - calculate_monster_attack()
  59.  
  60. if player['health'] <= 0:
  61. monster_won = True
  62.  
  63. elif player_choice == '3':
  64. new_round = False
  65. game_running = False
  66. elif player_choice == '4':
  67. for player_stat in game_results:
  68. print(player_stat)
  69.  
  70.  
  71. else:
  72. print('Invalid Input')
  73.  
  74. print('---' * 7)
  75. if player_won == False and monster_won == False:
  76. print(player['name'] + ' has ' + str(player['health']) + ' left')
  77. print(monster['name'] + ' has ' + str(monster['health']) + ' left')
  78.  
  79. elif player_won:
  80. game_ends(player['name'])
  81. print('---' * 7)
  82.  
  83. round_result = {'name': player['name'], 'health': player['health'], 'rounds': counter}
  84. game_results.append(round_result)
  85. print(game_results)
  86. new_round = False
  87.  
  88. elif monster_won:
  89. game_ends(monster['name'])
  90. print('---' * 7)
  91. round_result = {'name': player['name'], 'health': player['health'], 'rounds': counter}
  92. game_results.append(round_result)
  93. print(game_results)
  94. new_round = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement