Advertisement
GreatRaymondo

Simple Python Game

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