#-------------------------------------------------------------------------- # Name : Endgame # Purpose : 11DGT # Author: Alex Sanita # Created : 19/02/2025 # Copyright : © Alex Sanita 2025 #-------------------------------------------------------------------------- # Import libraries import random import time # Constants for Thanos' starting health START_HP_THANOS = 100 # Initialize variables player_health = 0 thanos_health = START_HP_THANOS thanos_sword = 0 player_damage = 0 deflect = 0 player_choice = "0" play_again = "y" player_name = "" # Input validation for player name (Hero name) while True: player_name = input("Enter your hero name: ") if player_name.isalpha(): # Check if the name contains only alphabetic characters break else: print("Invalid name! Please enter a name containing only letters (a-z).") # Game introduction print(f"The sky grows darker as the army of Thanos moves closer, {player_name}.") time.sleep(2) print(f"Thor and Tony lie battered and motionless on the ground from the previous encounter.") time.sleep(3) print(f"It is up to you, {player_name}, to finish this. The fate of the universe is your weight to bear.") time.sleep(3.5) print("You stand there, hurt. But you have your shield in one hand and wield Mjolnir in the other.") time.sleep(4) print("You are worthy, but will the power of Thor be enough....") time.sleep(3) print("You are in the ENDGAME now") time.sleep(1) # Input validation for player health (difficulty) while True: try: player_health = int(input(f"Choose your starting health, {player_name}, between 50 and 80: ")) if 50 <= player_health <= 80: break else: print("Please choose a health between 50 and 80.") except ValueError: print("Invalid input! Please enter a number.") # main game while play_again.lower() == "y": # reset health at the beginning of each game cap_health = player_health thanos_health = START_HP_THANOS # game loop while thanos_health > 0: # print current health levels time.sleep(1) print() print(f"Current Health") print(f"{player_name} has {cap_health} HP...") print(f"Thanos has {thanos_health} HP...") time.sleep(2) # Pplayer selects their attack print() print("What do you choose?..") print("[a]ttack with Mjolnir") print("or") print("[d]efend with your shield") player_choice = input("Your choice?... ").lower() # Added .lower() for case-insensitive input print() # player choice # choice a if player_choice == "a": thanos_sword = random.randint(1, 20) print(f"Thanos attacks you with his double-bladed sword and deals {thanos_sword} damage.") cap_health -= thanos_sword if cap_health < 1: break time.sleep(1) player_damage = random.randint(1, 20) print(f"You attack back with Mjolnir in hand, dealing {player_damage} damage in return.") thanos_health -= player_damage time.sleep(1) # choice d else: print("Thanos attacks you with his double-bladed sword...") print("You raise your shield to deflect the blow...") time.sleep(1) deflect = random.randint(1, 2) if deflect == 1: thanos_sword = random.randint(1, 20) print(f"You were too slow in raising your shield and Thanos strikes you with his sword for {thanos_sword} damage.") cap_health -= thanos_sword if cap_health < 1: break time.sleep(1) else: thanos_sword = random.randint(1, 20) print(f"Thanos' sword rebounds off {player_name}'s vibranium shield and he deals himself {thanos_sword} damage.") thanos_health -= thanos_sword time.sleep(1) # end of game loop cecking health values to determine a winner if cap_health < 1: print() print(f"{player_name} is too strong. Thanos has broken your shield and cut you down.") print("This is the end of all life in our universe...") else: print() print("Thanos has fallen!") time.sleep(0.5) print(f"{player_name} drops to their knees, exhausted.") time.sleep(0.5) print("You stare out into a grateful universe.") time.sleep(1) print("It is safe...") time.sleep(3) print(" ..for now ts pmo broseph...") time.sleep(5) # ask if the palyer wanna play again play_again = input("do you want to play again brobro? (y/n): ") # end of game print("thanks for playing this ts brobro")