#-------------------------------------------------------------------------- # Name: Endgame # Purpose: DGT1 # Author: Shia Abdul-Coley # Created: 17/02/2025 # Copyright: © Shia Abdul-Coley 2025 #-------------------------------------------------------------------------- # Libraries import random import time # Vitals starthpthanos = 100 caphp = 0 thanoshp = 0 # Winrate calculation def rate(a, b): wins = 10000 for i in range(10000): caphp2 = a thanoshp2 = b while thanoshp2 > 0: deflect = random.randint(1,2) if deflect == 1: caphp2 -= random.randint(1,20) if caphp2 < 1: wins -= 1 break else: thanoshp2 -= random.randint(1,20) return round(wins/100, 2) playagain = "y" # Dialogue print("The sky grows darker as the army of Thanos moves closer.") time.sleep(1) print("Thor and Tony lie battered and motionless on the ground from the previous encounter.") time.sleep(1) print("It is up to you to finish this. The fate of the universe is your weight to bare.") time.sleep(1) print("You stand there, hurt. But you have your shield in one hand and wield Mjolnir in the other.") time.sleep(1) print("You are worthy, but will the power of Thor be enough...") time.sleep(1) print("You are in the ENDGAME now.") time.sleep(1) while True: playername = input("What is your superhero name? ") if playername.isalpha() == True: break else: print("Please enter a string input.") while True: try: starthpcap = int(input("\nSelect a health amount for {} (between 50 and 80): ".format(playername))) if starthpcap < 50 or starthpcap > 80: print("\nPlease select a number between 50 and 80.") else: break except: print("\nNot a number, try again.") while playagain == "y": # Set starting health caphp = starthpcap thanoshp = starthpthanos while thanoshp > 0: print("\nVitals:\n{}: {}\nThanos: {}\nEstimated Winrate: {}%\n".format(playername, caphp, thanoshp, rate(caphp, thanoshp))) time.sleep(1) capchoice = input("\nMake a choice:\n[A]ttack with Mjolnir\nor\n[D]efend with your shield\n\nYour choice?\n") capdmg = random.randint(1,20) thanosdmg = random.randint(1,20) # Attack if capchoice == "A" or capchoice == "a": print("\nThanos attacks you with his double bladed sword and deals {} damage".format(thanosdmg)) caphp -= thanosdmg if caphp < 1: break time.sleep(1) print("You attack back with Mjolnir in hand dealing {} damage in return".format(capdmg)) thanoshp -= capdmg time.sleep(1) # Defend elif capchoice == "D" or capchoice == "d": print("\nThanos attacks you with his double bladed sword...") time.sleep(2) print("You raise your shield and try to deflect the blow...") time.sleep(2) deflect = random.randint(1, 2) # Defend success if deflect == 1: print("\nYou were too slow in raising your shield and Thanos strikes you with his sword for {} damage".format(thanosdmg)) caphp -= thanosdmg if caphp < 1: break time.sleep(1) # Defend fail else: print("\nThanos' sword rebounds off your vibranium shield and he deals himself {} damage".format(thanosdmg)) thanoshp -= thanosdmg time.sleep(1) # Invalid input else: print("\nInvalid command!") # Defeat print("\nThanos HP: {}".format(max(0, thanoshp))) time.sleep(2) if caphp < 1: print("\nThanos is too strong. He has broken your shield and cut you down. This is the end of all life in our universe...") time.sleep(5) # Victory else: print("\nThanos has fallen!") time.sleep(1) print("You drop to your knees, exhausted.") time.sleep(2) print("You stare out into a grateful universe.") time.sleep(3) print("It is safe...") time.sleep(3) print(" ...For now...") time.sleep(2) # Play again playagain = input("Play again? (y/n): ") time.sleep(1) print("\nThank you for playing c:") time.sleep(2)