#------------------------------------------------
#   Name:      Endgame
#   Purpose:   11DGT
#   Author:    Raymond Wilson
#   Created:   17/02/2025
#   Copyright: © Raymond Wilson 17/02/2025
#------------------------------------------------

#   Import libaries
import random
import time

#   Set starting varibles------------------------

while True:
    player_name = input("Welcome, What would you like us to call you?")
    if player_name.isalpha() == True:
        break
    else:
        print("Please enter a string input. J.A.R.V.I.S error <pointbreak>")

#   Starting health (CONSTANT)
while True:
    try:
        print()
        player_health = int(input("Select a helth amount for {} between 50 and 80:".format(player_name)))
        if player_health < 50 or player_health > 80: 
            print()
            print("Please select an amount between 50 and 80")
        else:
            break
    except:
            print()
            print("Thats is not a number... do we need to go back to school?")

START_HP_THANOS = 100

#   Starting health 
PLAYER_HEALTH = player_health
thanos_health = 0
#   Damage presets
player_mjonlnir = 0
thanos_sword = 0

#   Deflect presets
player_deflect = 0

#   Player Decision preset

player_choice = " "

play_again = "y"


#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, {}, to finish this. The fate of the universe is your weight to bare." .format(player_name))
time.sleep(3.5)
print("You stand there, hurt. But you have your shield in 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)

while play_again == "y":

    #Reset health levels for character
    thanos_health = START_HP_THANOS
    player_health =PLAYER_HEALTH

    #start of game loop
    while thanos_health > 0:

#Printing player health
        while thanos_health >0 and player_health > 0:
            time.sleep(1)
            print()
            print("Current health")
            time.sleep (1.5)
            print("You have {} HP...".format(player_health))
            time.sleep (1.5)
            print("Thanos has {} HP...".format(thanos_health))
    
    #Players action
            print()
            print("What are you gonna do?..")
            time.sleep(1)
            print("[a]ttack with Mjolnir")
            time.sleep(1)
            print("or")
            time.sleep(1)
            print("[d]efend with your shield")
            time.sleep (1)
            player_choice = input('Your choice?...')
            print()
    #Player choice
            if player_choice == "a": 
                thanos_sword = random.randint(1,20)
                print("Thanos swings at you and deals {} damage".format(thanos_sword))
                player_health = player_health - thanos_sword
                if player_health < 1: 
                    break
                time.sleep(1)
                player_mjonlnir = random.randint (1,20)
                print("You strike right back with Mjolnir dealing {} damage to Thanos".format(player_mjonlnir))
                thanos_health = thanos_health - player_mjonlnir
                time.sleep(1)
        
    #Choice D   
            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 :
                    thanos_sword = random.randint(1, 20)
                    print("You were to slow in raising your shield and Thanos strikes you with his sword for {} 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("Thanos' sword rebounds off your vibranium shield and he deals himself {} damage".format(thanos_sword))
                    thanos_health = thanos_health - thanos_sword
                    time.sleep(1)


    if player_health < 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...")

        #play again option
        play_again = input ("Do you want to see other outcomes?(Y/N)")
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("                                          (till you play again ;)")
    time.sleep(5)

    #play again option
    play_again = input ("Do you want to see other outcomes?(Y/N)")   

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