#--------------------------------------------------------------------------- # Name : Endgame # Purpose : 11DGT # Author: Tynan # Created : Date # Copyright : © Tynan and 17/02/2025 #--------------------------------------------------------------------------- # Import libraries import random import time def play_game(): # Set starting variables ----------------------------------- cap_health = 50 thanos_health = 100 # Damage presets thanos_sword = 0 cap_mjolnir = 0 # Deflect Preset deflect = 0 # Player Decision Preset cap_choice = "hello" # Intro print("The sky grows darker as the army of Thanos moves closer.") time.sleep(2) print("Thor and Tony lie battered and motionless on the ground from the previous encounter.") time.sleep(3) print("It is up to you, Cap, to finish this. The fate of the universe is your weight to bare.") 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) # Print current health levels time.sleep(1) print() print("Current Health") print("Cap has {} HP...".format(cap_health)) print("Thanos has {} HP...".format(thanos_health)) time.sleep(2) # Game loop while cap_health > 0 and thanos_health > 0: # Player selects their action print() print("What do you choose?..") print("[a]ttack with Mjolnir") print("or") print("[d]efend with your shield") cap_choice = input("Your choice?... ").lower() print() # Player choice if cap_choice == "a": thanos_sword = random.randint(1, 20) print("Thanos attacks you with his double-bladed sword and deals {} damage".format(thanos_sword)) cap_health = cap_health - thanos_sword if cap_health <= 0: print("Cap has been defeated...") break time.sleep(1) cap_mjolnir = random.randint(1, 20) print("You attack back with Mjolnir in hand, dealing {} damage in return".format(cap_mjolnir)) thanos_health = thanos_health - cap_mjolnir time.sleep(1) # Defend Choice (deflect or block damage - reducing damage here) elif cap_choice == "d": print("You brace yourself with your shield...") deflect = random.randint(1, 10) # Simulating a deflection damage reduction print("You successfully deflect {} damage!".format(deflect)) reduced_damage = max(0, thanos_sword - deflect) # Ensuring damage doesn't go negative cap_health -= reduced_damage print("Thanos attacks you with his sword and deals {} damage after deflection".format(reduced_damage)) time.sleep(1) # Invalid input else: print("Invalid choice, please select 'a' to attack or 'd' to defend.") time.sleep(1) # Print updated health print() print("Current Health") print("Cap has {} HP...".format(cap_health)) print("Thanos has {} HP...".format(thanos_health)) time.sleep(2) # Ending message if cap_health <= 0: print("Cap has fallen! Thanos wins...") elif thanos_health <= 0: print("You have defeated Thanos! The universe is saved.") # Victory sequence (adjusted indentation) if thanos_health <= 0: # This should only happen if Thanos is defeated print() print("Thanos has fallen!") time.sleep(0.5) print("You drop to your 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...") time.sleep(5) # Option to play again play_again = input("Do you want to play again? [y]es or [n]o...").lower() # Restart game if player chooses yes if play_again == "y": play_game() # Call play_game again if the player wants to restart else: print("Thanks for playing my game") time.sleep(2) # Start the game play_game()