#-------------------------------------------------------------------------- # Name : Endgame # Purpose : 11DGT # Author: Luke Jones # Created : 19/02/24 # Copyright : © Luke Jones 19/02/24 #-------------------------------------------------------------------------- import random import time # --- Starting variables --- # Player Name while True: player_name = input("What is your characters name? ") if player_name.isalpha() == True: break else: print ("Please enter a string input!") # Starting Health while True: try: START_HP_PLAYER = int(input("Select a health amount for {}. Make sure it is between 50-80! ".format(player_name))) if START_HP_PLAYER < 50 or START_HP_PLAYER > 80: print() print("Please select a number between 50-80!") else: break except: print() print("That is not a number!") START_HP_THANOS = 100 # Health player_health = 0 thanos_health = 0 # Attack thanos_attack = 0 player_attack = 0 # Deflect chance deflect = 0 # Player Decision player_choice = " " play_again = "y" # --- Introduction --- # --- Play Again Loop --- while play_again == "y": # Health Level Reset player_health = START_HP_PLAYER thanos_health = START_HP_THANOS # Game Loop while thanos_health > 0: # Printing health time.sleep(1) print() print ("Current Health") print ("{} HP: {}".format(player_name, player_health)) print ("Thanos HP: {}".format(thanos_health)) # User choice time.sleep(1) print() print ("What is your choice?") print ("Attack with your sword [A] or defend with your shield [D]") player_choice = input("Input your choice: ") # --- Player chooses [A] --- if player_choice == "A" or player_choice == "a": thanos_attack = random.randint(1, 20) print ("Thanos swings his sword and deals {} damage!".format(thanos_attack)) player_health = player_health - thanos_attack if player_health < 1: break player_attack = random.randint(1, 20) time.sleep(1) print ("You swing your sword and deal {} damage!".format(player_attack)) thanos_health = thanos_health - player_attack time.sleep(1) # --- Player chooses [D] --- elif player_choice == "D" or player_choice == "d": deflect = random.randint(1, 2) if deflect == 1: thanos_sword = random.randint(1, 20) print ("You didn't raise your shield in time and Thanos damages you with his sword. He deals {} damage.".format(thanos_sword)) player_health = player_health - thanos_sword if player_health < 1: break time.sleep(1) else: thanos_sword = random.randint(1, 20) print("You manage to raise your shield and Thanos sword rebounds and deals himself {} damage.".format(thanos_sword)) thanos_health = thanos_health - thanos_sword time.sleep(1) # --- End of the game --- if player_health < 1: print ("Thanos has won.") play_again = input("Would you like to play again? [y] or [n]") else: print("{} has won.".format(player_name)) play_again = input("Would you like to play again? [y] or [n]") time.sleep(1) print ("Thanks for playing my game!") time.sleep(1)