caphp = 0
thanoshp = 0

thanosdam = 0
capdam = 0

STARTHPCAP = 50
STARTHPTHANOS = 100

deflect = 0

capchoice = " "

playagain = "y"

import random
import time

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 arm 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)


time.sleep(2)

#MainStrCode----------------------


while playagain == "y":

    caphp = STARTHPCAP
    thanoshp = STARTHPTHANOS
   
    while thanoshp > 0:
        time.sleep(1)
        print( )
        print("Current hp")
        print("Cap has {} HP...".format(caphp))
        print("Thanos has {} HP...".format(thanoshp))
        print( )

        print("What do you choose!..")
        print("[a]ttack with hammer thing")
        print("or")
        print("[d]fend with your shield")
        capchoice = input("Your choice?:")
        print()

        if capchoice == "a" :
            thanosdam = random.randint(1, 20)
            print("Thanos attacks you with his double bladed sword and deals {} damage".format(thanosdam))
            caphp = caphp - thanosdam
            if caphp < 1:
                break
            time.sleep(1)
            capdam = random.randint(1, 30)
            print("You attack back with Mjolnir in hand dealing {} damage in return".format(capdam))
            thanoshp = thanoshp - capdam
            time.sleep(1)
        
        else:
            print("Thanos attacks you with his double bladed sword...")
            print("You raise your shield and deflect to deflect the blow...")
            time.sleep(1)
            deflect = random.randint(1, 2)
            if deflect == 1 :
                thanosdam = random.randint(1, 20)
                print("You were to slow in raising your shield and Thanos strikes you with his sword for {} damage".format(thanosdam))
                caphp = caphp - thanosdam
                if caphp < 1:
                    break
                time.sleep(1)
            else:
                thanosdam = random.randint(1, 30)
                print("Thanos' sword rebounds off Caps vibranium shield and he deals himself {} damage".format(thanosdam))
                thanoshp = thanoshp - thanosdam
                time.sleep(1)
    
    #CapHealthLoopCheck----------------

    if caphp < 1:
        print()
        print("Thanos is too strong. He has broken your shield and cut you down. This is the end of all life in our universe...")

        playagain = input("Do you want to play again? [y]es or [n]o: ")

    #EndCommands------------------------

    else:
        print()
        print("Thanos has fallen!")
        time.sleep(.5)
        print("You drop to your knees, exhausted.")
        time.sleep(.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)

        playagain = input("Do you want to play again? [y]es or [n]o: ")

time.sleep(2)
print("Thanks for playing my game!")
time.sleep(2)