#Import modules
import pytilities as utils
import random, sys

#Variables
player_hp = 10
player_heal = 2
player_shield = False
enemy_hp = 10
enemy_heal = 2
enemy_shield = False
act = None
dmg = None


#Gameloop
def Main(stats):
    #Accessing variables
    global enemy_hp
    global enemy_heal
    global enemy_shield
    global player_hp
    global player_heal
    global player_shield
    global act
    global dmg
    #Player's turn
    player_shield = False
    if stats:
        utils.slowprint(f'Your HP: {player_hp}')
        utils.slowprint(f'Enemy HP: {enemy_hp}')
        utils.slowprint(f'Heals Left: {player_heal}')
        utils.slowprint('Action?\n(A)ttack\n(H)eal\n(S)hield\nor QUIT')
    act = input('>').upper()
    #Attack
    if act == 'A':
        #Find out if an attack is a critical hit
        if utils.randbool(1, 20):
            utils.slowprint('SMAAAAASH!')
            if not enemy_shield:
                enemy_hp = enemy_hp - 5
                utils.slowprint('Dealt 5 damage!')
            else:
                enemy_hp = enemy_hp - 4
                utils.slowprint('Dealt 4 damage!')
        #Find out how much damage the attack does
        else:
            dmg = random.randint(1, 3)
            if not enemy_shield:
                enemy_hp = enemy_hp - dmg
            else:
                dmg = dmg - 1
                enemy_hp = enemy_hp - dmg
            if dmg > 0:
                utils.slowprint(f'Dealt {dmg} damage.')
            else:
                utils.slowprint('Enemy succesfully blocked the damage.')
        if enemy_hp <= 0:
            utils.slowprint('You win!')
            return
    #Heal
    elif act == 'H':
        if player_heal > 0:
            utils.slowprint('Healed 3 HP')
            player_hp = player_hp + 3
            player_heal = player_heal - 1
            if player_hp > 10:
                player_hp = 10
        else:
            utils.slowprint('No heals left.')
            Main(False)
    #Shield
    elif act == 'S':
        utils.slowprint('You put up a shield until the start of your next turn.')
        player_shield = True
    #Quit
    elif act == 'QUIT':
        sys.exit()
    #Wrong Input
    else:
        utils.slowprint('Please enter a valid action')
        Main(False)
    #Enemy's Turn
    enemy_shield = False
    if enemy_hp < 5:
        if enemy_heal > 0:
            utils.slowprint('Enemy healed and recovered 3 HP')
            enemy_hp = enemy_hp + 3
            enemy_heal = enemy_heal - 1
        else:
            if utils.randbool(1, 3):
                utils.slowprint('Enemy puts up a shield until the start of its next turn.')
                enemy_shield = True
            else:
                utils.slowprint('Enemy attacks!')
                if utils.randbool(1, 20):
                    utils.slowprint('SMAAAAASH')
                    if not player_shield:
                        utils.slowprint('You took 5 damage!')
                        player_hp = player_hp - 5
                    else:
                        utils.slowprint('You took 4 damage!')
                else:
                    dmg = random.randint(1, 3)
                    if not player_shield:
                        utils.slowprint(f'You took {dmg} damage.')
                        player_hp = player_hp - dmg
                    else:
                        dmg = dmg - 1
                        if dmg > 0:
                            utils.slowprint(f'You took {dmg} damage.')
                            player_hp = player_hp - dmg
                        else:
                            utils.slowprint('You succesfully blocked the enemy\'s attack')
    else:
        utils.slowprint('Enemy attacks!')
        if utils.randbool(1, 20):
            utils.slowprint('SMAAAAASH')
            if not player_shield:
                utils.slowprint('You took 5 damage!')
                player_hp = player_hp - 5
            else:
                utils.slowprint('You took 4 damage!')
        else:
            dmg = random.randint(1, 3)
            if not playershield:
                utils.slowprint(f'You took {dmg} damage.')
                player_hp = player_hp - dmg
            else:
                dmg = dmg - 1
                if dmg > 0:
                    utils.slowprint(f'You took {dmg} damage.')
                    player_hp = player_hp - dmg
                else:
                    utils.slowprint('You succesfully blocked the enemy\'s attack')
    if player_hp > 0:
        Main(True)
    else:
        utils.slowprint('You lose!')
#Intro
utils.slowprint('Super Fighter\nby JSD-Games\nPress return to start.\n')
input('')
Main(True)
    
