def move_prompt():
    print()
    print("-----========[CHOOSE STANCE]========-----")
    print("1. Attack")
    print("2. Defend")
    print()
    attack_input = input(player.player_name + ": ")
    attack_input = normalise_input(attack_input)
    while True:
        quit_test(attack_input)
        if "1" in attack_input:
            print("\nYou take on an offensive stance! You deal normal damage.")
            return 1
        elif "2" in attack_input:
            print("\nYou take on a defensive stance! You deal less damage but gain more armor!")
            return 2
        else:
            attack_input = input("You need to choose an option from the list (number): ")
            attack_input = normalise_input(attack_input)
def valid_weapon():
    print()
    print("-----========[CHOOSE WEAPON]========-----")
    print_list_of_weapons()
    print()
    weapon_input = input(player.player_name + ": ")
    weapon_input = normalise_input(weapon_input)
    while True:
        quit_test(weapon_input)
        # Checks if weapon_input list after being normalised has more than 1 word. If yes, combines 0 and 1 index of list into a 0-index list.
        if len(weapon_input) > 1:
            weapon_input[0] = weapon_input[0] + "_" + weapon_input[1]
            weapon_input = weapon_input[:1]
        # If list empty after normalization, puts an item in index 0 to prevent crash further down the function
        elif len(weapon_input) < 1:
            weapon_input = ["a"]
        # Tests if user input is a weapon from the list or no
        if weapon_input[0] == "weapons":
            print()
            print_list_of_weapons()
            print()
        else:
            # for weapon in list_of_weapons():
            #     if weapon_input[0] in weapon["id"]:
            if weapon_input[0].isdigit():
                if 0 < int(weapon_input[0]) <= len(list_of_weapons()):
                    weapon = list_of_weapons()[int(weapon_input[0]) - 1]
                    print()
                    print("You have chosen " + weapon["name"] + " with " + str(weapon["attributes"]["damage"]) + " base damage!\n")
                    return weapon
                else:
                    a = input("You have not entered a valid weapon number from the list!\n" + player.player_name + ": ")
                    weapon_input = normalise_input(a)
            else:
                a = input("You have not entered a valid weapon number from the list!\n" + player.player_name + ": ")
                weapon_input = normalise_input(a)
def main_fight(enemy):
    screen_flush()
    player.in_battle_enemy_hp = enemy["hp"]
    print_encounter()
    alpha = randint(0, len(encounter_fill) - 1)
    print("You have encountered " + enemy["name"] + encounter_fill[alpha])
    print("You must fight " + enemy["name"] + " to proceed (you cannot save during battle).")
    print()
    while True:
        a = input("Heads or Tails (winner goes first)? ")
        normalise_input(a)
        while True:
            quit_test(a)
            if "tails" in a:
                a = 0
                break
            elif "heads" in a:
                a = 1
                break
            else:
                a = input("You have to choose between Heads and Tails: ")
                a = normalise_input(a)
        b = randint(0, 1)
        if b == a:
            screen_flush()
            print_encounter()
            print("You go first!")
            enter()
            while player.in_battle_enemy_hp >= 1:
                screen_flush()
                print_encounter()
                print_stats(enemy)
                weapon_choice = valid_weapon()
                move = move_prompt()
                # Damage_dealt would return FALSE if enemy is dead, therefore damage_got will not be further executed.
                if damage_dealt(weapon_choice, enemy, move):
                    print()
                    damage_got(enemy, move)
                    if player.hp <= 0:
                        raise GameOver
                    enter()
                    screen_flush()

            break
        else:
            screen_flush()
            print_encounter()
            print(enemy["name"] + " goes first!")
            enter()
            print()
            move = 1
            while player.in_battle_enemy_hp >= 1:
                screen_flush()
                print_encounter()
                print_stats(enemy)
                print()
                damage_got(enemy, move)
                if player.hp <= 0:
                    raise GameOver
                weapon_choice = valid_weapon()
                move = move_prompt()
                # Damage_dealt would return FALSE if enemy is dead, therefore damage_got will not be further executed.
                if damage_dealt(weapon_choice, enemy, move):
                    enter()
                    screen_flush()
            break