package org.project;

import org.project.entity.enemies.*;
import org.project.entity.players.Assassin;
import org.project.entity.players.Knight;
import org.project.entity.players.Player;
import org.project.entity.players.Wizard;
import org.project.item.armors.*;
import org.project.item.potions.Potion;
import org.project.item.potions.healthPotion;
import org.project.item.potions.mixedPotion;
import org.project.item.potions.strengthPotion;
import org.project.item.weapons.*;
import org.project.location.Location;

import java.lang.foreign.PaddingLayout;
import java.util.*;

public class Main {

    //color codes

    public static final String RESET = "\u001B[0m";

    public static final String ELECTRIC_PURPLE = "\033[38;5;93m";
    public static final String YELLOW_VIVID = "\033[38;5;226m";

    //colorful characters

    static String leftParanthese = ELECTRIC_PURPLE + "(" + RESET;
    static String rightParanthese = ELECTRIC_PURPLE + ")" + RESET;

    // Locations

    static String[] places = {"Abandoned Docks", "Crystal Caverns", "Lava Pit",
            "Cyber Alley", "Frozen Tundra", "Haunted Mill", "Sandstorm Gate",
            "Iron Fortress", "Neon Rooftops", "Rainy Jungle"};

    // Menus

    static String[] ForE = {"", "Fight", "Escape", "Main page"};
    static String[] ForM = {"", "Fight", "Main page"};
    static String[] UorEorR = {"", "Equip", "Upgrade", "Repair"};
    static String[] UorE = {"", "Equip", "Upgrade"}; //______________
    static String[] U = {"", "Upgrade"};

    // Merchant items

    static Dagger d1 = new Dagger();
    static Bow b1 = new Bow();
    static Sword s1 = new Sword();
    static Spear sp1 = new Spear();
    static Halberd ha1 = new Halberd();

    static Armlet a1 = new Armlet();
    static Pauldron p1 = new Pauldron();
    static Helmet he1 = new Helmet();
    static Cuirass c1 = new Cuirass();

    static healthPotion hP1 = new healthPotion(1, 15, 10);
    static healthPotion hP2 = new healthPotion(1, 25, 20);
    static strengthPotion sP1 = new strengthPotion(1, 20, 10);
    static strengthPotion sP2 = new strengthPotion(1, 30, 20);
    static mixedPotion mP1 = new mixedPotion(1, 18, 5, 5);
    static mixedPotion mP2 = new mixedPotion(1, 23, 10, 10);

    // Lists of Items in merchant

    static Weapon[] W1 = {d1, b1, s1, sp1, ha1};
    static Armor[] A1 = {a1, p1, he1, c1};
    static Potion[] Po1 = {hP1, hP2, sP1, sP2, mP1, mP2};

    // Lists of menus

    static String[] sections = {"Items: ", "Weapons", "Armors", "Potions", "Main page"};

    static String[] weapons = {"Weapon | Base damage | Grade | Cost", "Dagger | 10 | 2 | 40",
            "Bow | 13 | 2 | 50", "Sword | 16 | 2 | 60",
            "Spear | 18 | 3 | 80", "Halberd | 20 | 3 | 100", "Sections"};

    static String[] armors = {"Armor | Base defense | Base durability | Grade | Cost", "Armlet | 15 | 4 | 2 | 30",
            "pauldron | 17 | 5 | 2 | 40", "Helmet | 19 | 6 | 3 | 60",
            "Cuirass | 21 | 7 | 3 | 80", "Sections"};

    static String[] potion = {"Potion | HP/Mana | Cost", "Health potion | 10 | 15",
            "Health potion | 20 | 25", "Strength potion | 10 | 20", "Strength potion | 20 | 30",
            "Mixed potion | 5,5 | 18", "Mixed potion | 10,10 | 23", "Sections"};


    public static void pressKeyToContinue() {
        System.out.println();
        System.out.println("Press any key _c_ to continue. ");
        Scanner in_ = new Scanner(System.in);
        String ___ = in_.next();
    }

    public static void pressKeyToContinue(String str) {
        System.out.println();
        System.out.println(str);
        System.out.println();
        System.out.println("Press any key _c_ to continue. ");
        Scanner in_ = new Scanner(System.in);
        String ___ = in_.next();
    }

    public static int menuMaker(String[] options, boolean horizontal) {
        if (horizontal) {
            System.out.println();
            for (int i = 0; i < options.length ; i++) {
                if (i == 0) {
                    System.out.println(options[i]);
                }
                else {
                    String ln = " " + ELECTRIC_PURPLE + String.valueOf(i) + "." + RESET + options[i];
                    System.out.print(ln);
                    if (i != options.length - 1) {
                        System.out.print(ELECTRIC_PURPLE + " |" + RESET);
                    } else {
                        System.out.println();
                    }
                }
            }
            System.out.println();
        }
        else {
            System.out.println();
            for (int i = 0; i < options.length; i++) {
                if (i == 0) {
                    System.out.println(options[i]);
                } else {
                    String ln = ELECTRIC_PURPLE + String.valueOf(i) + "." + RESET + options[i];
                    System.out.println(ln);
                }
            }
            System.out.println();
        }

        Scanner in1 = new Scanner(System.in);

        int chosenOption;
        int a = 0;
        do {
            a = in1.nextInt();
            if (!(a > 0 && a < options.length)) {
                System.out.println("Enter a valid number. ");
            }
        } while (!(a > 0 && a < options.length));
        chosenOption = a;

        return chosenOption;
    }

    public static void home(Player player) {
        while (true) {
            int num8 = menuMaker(sections, false);
            switch (num8) {
                case 1: {
                    List<Weapon> wLst = player.getWeaponsList();
                    ArrayList<String> wLstNames = new ArrayList<String>();
                    wLstNames.add("Weapons: ");
                    for (Weapon w : wLst) {
                        wLstNames.add(w.getClass().getSimpleName());
                    }
                    wLstNames.add("sections");
                    String[] wArrayNames = wLstNames.toArray(new String[wLstNames.size()]);
                    while (true) {
                        int num9 = menuMaker(wArrayNames, false);
                        if (num9 == wLst.size() + 1) {
                            break;
                        }
                        if (wLst.get(num9 - 1).getClass() != player.getWeapon().getClass()) {
                            int num10 = menuMaker(UorE, true);
                            if (num10 == 1) {
                                player.setWeapon(wLst.get(num9 - 1));
                                pressKeyToContinue("Equipped with the weapon. ");
                            } else if (num10 == 2) {
                                boolean res = wLst.get(num9 - 1).upgrade(player);

                                if (res) {
                                    pressKeyToContinue("Upgraded the weapon. ");
                                }
                                else {
                                    pressKeyToContinue("You don't have enough coins. ");
                                }
                            }
                        } else {
                            int num10 = menuMaker(U, true);
                            if (num10 == 1) {
                                boolean res = player.getWeapon().upgrade(player);

                                if (res) {
                                    pressKeyToContinue("Upgraded the weapon. ");
                                }
                                else {
                                    pressKeyToContinue("You don't have enough coins. ");
                                }
                            }
                        }
                    }
                    break;
                }
                case 2: {
                    List<Armor> aLst = player.getArmorsList();
                    ArrayList<String> aLstNames = new ArrayList<String>();
                    aLstNames.add("Armors: ");
                    for (Armor a : aLst) {
                        aLstNames.add(a.getClass().getSimpleName());
                    }
                    aLstNames.add("sections");
                    String[] aArrayNames = aLstNames.toArray(new String[aLstNames.size()]);
                    while (true) {
                        int num9 = menuMaker(aArrayNames, false);
                        if (num9 == aLst.size() + 1) {
                            break;
                        }
                        if (aLst.get(num9 - 1).getMaxDurability() != aLst.get(num9 - 1).getDurability()) {
                            int num10 = menuMaker(UorEorR, true);
                            if (num10 == 1) {
                                player.setArmor(aLst.get(num9 - 1));
                                pressKeyToContinue("Equipped with the armor. ");
                            } else if (num10 == 2) {
                                boolean res = aLst.get(num9 - 1).upgrade(player);

                                if (res) {
                                    pressKeyToContinue("Upgraded the armor. ");
                                }
                                else {
                                    pressKeyToContinue("You don't have enough coins. ");
                                }
                            }
                            else if (num10 == 3) {
                                boolean res = aLst.get(num9 - 1).repair(player);

                                if (res) {
                                    pressKeyToContinue("Repaired the armor. ");
                                }
                                else {
                                    pressKeyToContinue("You don't have enough coins. ");
                                }
                            }
                        }
                        else if (aLst.get(num9 - 1).getClass() != player.getArmor().getClass()) {
                            int num10 = menuMaker(UorE, true);
                            if (num10 == 1) {
                                player.setArmor(aLst.get(num9));
                                pressKeyToContinue("Equipped with the armor. ");
                            } else if (num10 == 2) {
                                boolean res = aLst.get(num9 - 1).upgrade(player);

                                if (res) {
                                    pressKeyToContinue("Upgraded the armor. ");
                                }
                                else {
                                    pressKeyToContinue("You don't have enough coins. ");
                                }
                            }
                        } else {
                            int num10 = menuMaker(U, true);
                            if (num10 == 1) {
                                boolean res = player.getArmor().upgrade(player);

                                if (res) {
                                    pressKeyToContinue("Upgraded the armor. ");
                                }
                                else {
                                    pressKeyToContinue("You don't have enough coins. ");
                                }
                            }
                        }
                    }
                    break;
                }
                case 3: {
                    List<Potion> pLst = player.getPotionsList();
                    ArrayList<String> pLstNames = new ArrayList<String>();
                    pLstNames.add("Potion | +HP | +Mana | Number");
                    for (Potion p : pLst) {
                        String pData = String.format("%s | %d | %d | %d", p.getClass().getSimpleName(),
                                p.getExtraHP(), p.getExtraMP(), p.getNumber());
                        pLstNames.add(pData);
                    }
                    for (int i = 0; i < pLstNames.size(); i++) {
                        System.out.println(pLstNames.get(i));
                    }
                    pressKeyToContinue();
                    break;
                }
                case 4: {
                    return;
                }
                default:
                    break;
            }
        }
    }

    public static void merchant(Player player) {

        while (true) {
            int num6 = menuMaker(sections, false);
            switch (num6) {
                case 1: {
                    while (true) {
                        int num7 = menuMaker(weapons, false);
                        if (num7 != 6) {
                                boolean b = W1[num7 - 1].buy(player);
                                if (b) {
                                    pressKeyToContinue("There you go, The weapon is added to your storage. ");
                                } else {
                                    pressKeyToContinue("You either already have the weapon, or you don't have enough coins. ");
                                }
                        }
                        else { break; }
                    }
                    break;
                }
                case 2: {
                    while (true) {
                        int num7 = menuMaker(armors, false);
                        if (num7 != 5) {
                            boolean b = A1[num7 - 1].buy(player);
                            if (b) {
                                pressKeyToContinue("There you go, The Armor is added to your storage. ");
                            }
                            else {
                                pressKeyToContinue("You either already have the armor, or you don't have enough coins. ");
                            }
                        }
                        else { break; }
                    }
                    break;
                }
                case 3: {
                    while (true) {
                        int num7 = menuMaker(potion, false);
                        if (num7 != 7) {
                            boolean res = Po1[num7 - 1].buy(player);
                            if (res) {
                                pressKeyToContinue("There you go, The potion is added to your storage. ");
                            }
                            else {
                                pressKeyToContinue("You don't have enough coins. ");
                            }
                        }
                        else { break; }
                    }
                    break;
                }
                case 4: {
                    return;
                }
                default:
                    break;
            }
        }
    }

    //randomly drops a key from the enemy
    public static boolean isThereAKey() {
        Random rand = new Random();
        boolean res = 0.3 > rand.nextDouble();
        return res;
    }

    //is used to randomly make an enemy in a random location
    public static int randomIndex(int size) {
        Random rnd = new Random();
        int num = rnd.nextInt(size);
        return num;
    }

    public static boolean playersTurn(Player player, Enemy enemy, boolean usedPotion, ArrayList<String> combatActionsLst) {
        boolean usedPotionTemp = usedPotion;
        String eName = YELLOW_VIVID + enemy.getClass().getSimpleName() + RESET;
        String pName = ELECTRIC_PURPLE + player.getName() + RESET;
        if ((player.potionsNumber() != 0)&&(!usedPotionTemp)) {
            combatActionsLst.add("Use Potion " + leftParanthese + YELLOW_VIVID + "0" + RESET + " Mana" + rightParanthese);
        }

        String[] combatActions = combatActionsLst.toArray(new String[combatActionsLst.size()]);
        while (true) {
            int num4 = menuMaker(combatActions, true);
            switch (num4) {
                case 1: {
                    player.attack(enemy);

                    String no01 = String.format("%s (%s) used light attack! (0 Mana)",
                            pName, player.getClass().getSimpleName());
                    String no02 = String.format("%s has %d/%d HP remaining.",
                            eName, enemy.getHP(), enemy.getMaxHP());
                    String no03 = String.format("%s Mana: %d/%d",
                            pName, player.getMP(), player.getMaxMP());

                    System.out.println("You chose to attack the enemy lightly. ");
                    System.out.println();
                    System.out.println(no01);
                    System.out.println(no02);
                    System.out.println(no03);
                    pressKeyToContinue();
                    return usedPotionTemp;
                }
                case 2: {
                    boolean b2 = player.heavyAttack(enemy);
                    if (b2) {
                        String no01 = String.format("%s (%s) used heavy attack! (8 Mana)",
                                pName, player.getClass().getSimpleName());
                        String no02 = String.format("%s has %d/%d HP remaining.",
                                eName, enemy.getHP(), enemy.getMaxHP());
                        String no03 = String.format("%s Mana: %d/%d",
                                pName, player.getMP(), player.getMaxMP());

                        System.out.println("You chose to attack the enemy heavily. ");
                        System.out.println();
                        System.out.println(no01);
                        System.out.println(no02);
                        System.out.println(no03);
                        pressKeyToContinue();
                        return usedPotionTemp;
                    } else {
                        pressKeyToContinue("You don't have enough Mana. ");
                    }
                    break;
                }
                case 3: {
                    if (!(enemy instanceof Dragon)) {
                        boolean b3 = player.defend(enemy);
                        if (b3) {
                            String no01 = String.format("%s (%s) used defending! (6 Mana)",
                                    pName, player.getClass().getSimpleName());
                            String no02 = String.format("%s Mana: %d/%d",
                                    pName, player.getMP(), player.getMaxMP());

                            System.out.println("You chose to defend yourself. ");
                            System.out.println();
                            System.out.println(no01);
                            System.out.println(no02);
                            pressKeyToContinue();
                            return usedPotionTemp;
                        } else {
                            pressKeyToContinue("You don't have enough Mana. ");
                        }
                    } else {
                        pressKeyToContinue("Useless against the dragon. ");
                    }
                    break;
                }
                case 4: {
                    if (player.getMP() >= 12) {
                        player.spendMP(12);
                        player.heal(enemy, 10);

                        String no01 = String.format("%s (%s) used healing! (12 Mana)",
                                pName, player.getClass().getSimpleName());
                        String no02 = String.format("%s took +10 HP", pName);
                        String no03 = String.format("%s has %d HP now.", pName, player.getHP());
                        String no04 = String.format("%s Mana: %d/%d",
                                pName, player.getMP(), player.getMaxMP());

                        System.out.println("You chose to heal yourself. ");
                        System.out.println();
                        System.out.println(no01);
                        System.out.println(no03);
                        System.out.println(no02);
                        System.out.println(no04);
                        pressKeyToContinue();
                        return usedPotionTemp;
                    } else {
                        pressKeyToContinue("You don't have enough Mana. ");
                    }

                    break;
                }
                case 5: {
                    boolean b5 = player.specialAbility(player, enemy);
                    if (b5) {
                        String specialAbility;
                        if (player instanceof Knight) { specialAbility = "Shield Bash"; }
                        else if (player instanceof Assassin) { specialAbility= "Turning Invisible"; }
                        else { specialAbility = "Spell Casting"; }

                        String no01 = String.format("%s (%s) used %s! (15 Mana)",
                                pName, player.getClass().getSimpleName(), specialAbility);
                        String no02 = String.format("%s has %d/%d HP remaining.",
                                eName, enemy.getHP(), enemy.getMaxHP());
                        String no03 = String.format("%s Mana: %d/%d",
                                pName, player.getMP(), player.getMaxMP());

                        System.out.println("You chose to use your special ability. ");
                        System.out.println();
                        System.out.println(no01);
                        System.out.println(no02);
                        System.out.println(no03);
                        pressKeyToContinue();
                        return usedPotionTemp;
                    } else {
                        pressKeyToContinue("You don't have enough Mana. ");
                    }
                    break;
                }
                case 6: {
                    if (player.getPotionsList() == null) {
                        pressKeyToContinue("You have no potions. ");
                    }
                    else {
                        ArrayList<String> potionsMenuLst = new ArrayList<String>();
                        potionsMenuLst.add("Choose a potion: ");
                        for (Potion e : player.getPotionsList()) {
                            String potionName = e.getClass().getSimpleName();
                            int extraHP = e.getExtraHP();
                            int extraMP = e.getExtraMP();
                            int number = e.getNumber();

                            String eData = String.format("%s  +%d HP  +%d Mana  (%d)",
                                    potionName, extraHP, extraMP, number);
                            potionsMenuLst.add(eData);
                        }

                        String[] potionsMenu = potionsMenuLst.toArray(new String[potionsMenuLst.size()]);
                        int num5 = menuMaker(potionsMenu, false);
                        Potion p = player.getPotionsList().get(num5 - 1);
                        p.consume(enemy, player);
                        int n = p.getNumber();
                        if (n <= 0) {
                            player.removePotion(p);
                        }

                        usedPotionTemp = true;
                        combatActionsLst.removeLast();

                        String no01 = String.format("%s (%s) used a potion! (0 Mana)",
                                pName, player.getClass().getSimpleName());
                        String no04 = String.format("%s Mana: %d/%d  HP: %d/%d",
                                pName, player.getMP(), player.getMaxMP(), player.getHP(), player.getMaxHP());

                        System.out.println();
                        System.out.println(no01);
                        System.out.println(no04);
                        pressKeyToContinue();

                        return usedPotionTemp;
                    }
                    break;
                }
                default: {
                    break;
                }
            }
        }
    }

    public static void fight(Player player, Enemy enemy) {
        Scanner in11 = new Scanner(System.in);

        boolean hasntResurrectedBefore = true;

        String eName = YELLOW_VIVID + enemy.getClass().getSimpleName() + RESET;
        String pName = ELECTRIC_PURPLE + player.getName() + RESET;

        ArrayList<String> combatActionsLst = new ArrayList<String>();
        combatActionsLst.add("Your turn: ");
        combatActionsLst.add("Light attack " + leftParanthese + YELLOW_VIVID + "0" + RESET + " Mana" + rightParanthese);
        combatActionsLst.add("Heavy Attack " + leftParanthese + YELLOW_VIVID + "8" + RESET + " Mana" + rightParanthese);
        combatActionsLst.add("Defend " + leftParanthese + YELLOW_VIVID + "6" + RESET + " Mana" + rightParanthese);
        combatActionsLst.add("Heal " + leftParanthese + YELLOW_VIVID + "12" + RESET + " Mana" + rightParanthese);
        if (player instanceof Knight) { combatActionsLst.add("Shield Bash " + leftParanthese + YELLOW_VIVID + "15" + RESET + " Mana" + rightParanthese); }
        else if (player instanceof  Assassin) { combatActionsLst.add("Turn invisible " + leftParanthese + YELLOW_VIVID + "15" + RESET + " Mana"+ rightParanthese); }
        else if (player instanceof Wizard) { combatActionsLst.add("Cast a spell " + leftParanthese + YELLOW_VIVID + "15" + RESET + " Mana" + rightParanthese); }

        boolean usedPotion = false;

        while (enemy.isAlive() && player.isAlive()) {

            boolean bbb = playersTurn(player, enemy, usedPotion, combatActionsLst);

            usedPotion = bbb;

            if (enemy.isAlive()) {
                enemy.attack(player);

                String no0 = String.format("%s's turn: ", eName);

                String no6 = String.format("%s has %d/%d HP remaining.",
                        pName, player.getHP(), player.getMaxHP());

                System.out.println();
                System.out.println(no0);
                if (!(enemy.isStunned())) {
                    if (enemy instanceof Goblin) {
                        String ability1 = "Critical strike";
                        String ability2 = "Critical hit";
                        int damage3 = enemy.getWeapon().getDamage() + 5;

                        String no1 = String.format("%s used %s!", eName, ability1);
                        String no2 = String.format("%s! %s took %d damage!", ability2, pName, damage3);

                        System.out.println(no1);
                        System.out.println(no2);
                    }
                    else if (enemy instanceof Skeleton) {
                        String ability1 = "Solid strike";
                        String ability2 = "Solid hit";
                        int damage3 = enemy.getWeapon().getDamage();
                        String ability4 = "resurrection";

                        String no1 = String.format("%s used %s!", eName, ability1);
                        String no2 = String.format("%s! %s took %d damage!", ability2, pName, damage3);

                        String no3 = String.format("%s used %s ability!", eName, ability4);
                        String no4 = String.format("%s took some HP back!", eName);
                        String no5 = String.format("%s has %d HP now.", eName, enemy.getHP());

                        System.out.println(no1);
                        System.out.println(no2);
                        if (enemy.getResurrectionStatus() && hasntResurrectedBefore) {
                            System.out.println(no3);
                            System.out.println(no4);
                            System.out.println(no5);
                            hasntResurrectedBefore = false;
                        }
                    }
                    else if (enemy instanceof Vampire) {
                        String ability1 = "Solid strike";
                        String ability2 = "Solid hit";
                        int damage3 = enemy.getWeapon().getDamage();
                        String ability4 = "life_steal";

                        String no1 = String.format("%s used %s!", eName, ability1);
                        String no2 = String.format("%s! %s took %d damage!", ability2, pName, damage3);

                        String no3 = String.format("%s used %s ability!", eName, ability4);
                        String no4 = String.format("%s took some HP back!", eName);
                        String no5 = String.format("%s has %d HP now.", eName, enemy.getHP());

                        System.out.println(no1);
                        System.out.println(no2);
                        System.out.println(no3);
                        System.out.println(no4);
                        System.out.println(no5);
                    }
                    else {
                        String ability1 = "Fiery breath";
                        String ability2 = "Severe injury";
                        int damage3 = enemy.getDragonDamage();

                        String no1 = String.format("%s used %s!", eName, ability1);
                        String no2 = String.format("%s! %s took %d damage!", ability2, pName, damage3);

                        System.out.println(no1);
                        System.out.println(no2);
                    }
                }
                else {
                    System.out.println(eName + " is stunned!");
                    enemy.toBeStunned(false);
                }
                System.out.println(no6);
                System.out.println();


            }
            else {
                System.out.println();
                System.out.println( ELECTRIC_PURPLE + "~" + RESET + YELLOW_VIVID + " Victory " + RESET + ELECTRIC_PURPLE + "~" + RESET);
                if (enemy instanceof Dragon) {
                    System.out.println("Congratulations! You have defeated the dragon. ");
                    System.out.println();
                    System.out.println("Press key _c_ to go to main page. ");
                    String __ = in11.next();
                    System.out.println();
                }
                else {
                    System.out.println("+" + enemy.getXpPrize() + " xp");
                    System.out.println("+" + enemy.getCoinPrize() + " coins");
                    player.victory(enemy);

                    if (!player.keyStatus(enemy)) {
                        if (isThereAKey()) {
                            player.grabTheKey(enemy);
                            String grabTheKey = String.format("You've just got the %ss' key. ", enemy.getClass().getSimpleName());
                            System.out.println();
                            System.out.println(grabTheKey);
                            System.out.println();
                        }
                    }

                    System.out.println();
                    System.out.println("Press _c_ key to go to main page. ");
                    String __ = in11.next();
                    System.out.println();
                }
                return;
            }

            if (!player.isAlive()) {
                System.out.println();
                System.out.println("Game over");
                System.out.println("You have to start from scratch. ");
                player.failure();
                System.out.println();
                System.out.println("Press _c_ key to go to main page. ");
                String __ = in11.next();
                System.out.println();
                return;
            }
        }
    }

    public static void fightTheDragon(Player player) {
        Dragon dragon = new Dragon();
        Location finalLoc = new Location("The Castle", dragon);

        System.out.println();
        System.out.println("Location: " + finalLoc.getName() + " Enemy: " + finalLoc.getEnemy().getClass().getSimpleName());
        System.out.println();

        int num3 = menuMaker(ForM, true);
        switch (num3) {
            case 1: {
                System.out.println();
                System.out.println("You chose to fight the dragon. ");
                System.out.println();
                fight(player, dragon);
                return;
            }
            case 2:
                return;
            default:
                break;
        }
    }

    public static void play(Player player) {

        while (true) {
            int[] hps = {40, 45, 50};
            int rnd1 = randomIndex(3);
            int EHP = hps[rnd1];

            Weapon EWeapon;
            int rnd2 = randomIndex(5);
            switch (rnd2) {
                case 0: {
                    EWeapon = new Sword();
                    break;
                }
                case 1: {
                    EWeapon = new Bow();
                    break;
                }
                case 2: {
                    EWeapon = new Spear();
                    break;
                }
                case 3: {
                    EWeapon = new Halberd();
                    break;
                }
                case 4: {
                    EWeapon = new Dagger();
                    break;
                }
                default: {
                    EWeapon = new Sword();
                    break;
                }
            }

            Enemy enemy;
            int rnd3 = randomIndex(3);
            switch (rnd3) {
                case 0: {
                    enemy = new Goblin(EHP, EWeapon);
                    break;
                }
                case 1: {
                    enemy = new Skeleton(EHP, EWeapon);
                    break;
                }
                case 2: {
                    enemy = new Vampire(EHP, EWeapon);
                    break;
                }
                default: {
                    enemy = new Goblin(EHP, EWeapon);
                    break;
                }
            }

            int rnd4 = randomIndex(places.length);
            String place = places[rnd4];

            Location loc = new Location(place, enemy);

            System.out.println();
            System.out.println("Location: " + loc.getName() + " Enemy: " + loc.getEnemy().getClass().getSimpleName());
            System.out.println();

            int num3 = menuMaker(ForE, true);
            switch (num3) {
                case 1: {
                    String intro1 = String.format("[%s - %d/%d HP | %d/%d Mana]",
                            player.getName(), player.getHP(), player.getMaxHP(),
                            player.getMP(), player.getMaxMP());
                    String intro2 = String.format("[%s - %d/%d HP]",
                            enemy.getClass().getSimpleName(), enemy.getHP(), enemy.getMaxHP());

                    System.out.println();
                    System.out.println("You chose to fight ");
                    System.out.println();
                    System.out.println(intro1);
                    System.out.println(intro2);
                    System.out.println();
                    System.out.println("---");
                    System.out.println();

                    fight(player, enemy);
                    return;
                }
                case 2:
                    break;
                case 3: {
                    return;
                }
                default:
                    break;
            }
        }
    }

    public static void mainMenu(Player player) {

        ArrayList<String> MainMenuLst = new ArrayList<>();
        MainMenuLst.add("");
        MainMenuLst.add("Home");
        MainMenuLst.add("Merchant");
        MainMenuLst.add("Play");
        if (player.threeKeys()) {
            MainMenuLst.add("Fight THe Dragon");
        }

        String[] MainMenu = MainMenuLst.toArray(new String[MainMenuLst.size()]);
        while (true) {
            System.out.println("Level " + ELECTRIC_PURPLE + player.getLevel() + RESET);
            System.out.println("XP " + ELECTRIC_PURPLE + player.getXP() + RESET + "/" + ELECTRIC_PURPLE + player.getMaxXP() + RESET);
            System.out.println("Coins: " + ELECTRIC_PURPLE + player.getCoins() + RESET);
            int num2 = menuMaker(MainMenu, true);
            switch (num2) {
                case 1: {
                    home(player);
                    break;
                }
                case 2: {
                    merchant(player);
                    break;
                }
                case 3: {
                    play(player);
                    break;
                }
                case 4: {
                    fightTheDragon(player);
                    break;
                }
                default: {
                    System.out.println("Enter a valid number. ");
                    break;
                }
            }
        }
    }

    public static void main(String[] args) {

        Scanner in2 = new Scanner(System.in);

        System.out.println(ELECTRIC_PURPLE + "~" + RESET + " KNIGHT GAME " + ELECTRIC_PURPLE + "~" + RESET);
        System.out.println();
        System.out.println("Enter your name: ");
        String name = in2.nextLine();
        String[] characters = {"Choose a character:", "Knight", "Assassin", "Wizard"};
        int num1 = menuMaker(characters, true);
        pressKeyToContinue("You have chosen to be a(an) " + characters[num1]);

        Player player;
        Armlet armlet = new Armlet();
        switch (num1) {
            case 1: {
                Sword PSword = new Sword();
                player = new Knight(name, PSword, armlet);
                mainMenu(player);
            }
            case 2: {
                Dagger PDagger = new Dagger();
                player = new Assassin(name, PDagger, armlet);
                mainMenu(player);
            }
            case 3: {
                Bow PBow = new Bow();
                player = new Wizard(name, PBow, armlet);
                mainMenu(player);
            }
            default: {
                System.out.println("Enter a valid number. ");
            }
        }
    }
}