5
\$\begingroup\$

I recently got into coding and built a small game in Java to practice and test myself. As I started plugging away at it, it very soon became...not so small. As of this moment, everything works the way I want it to, but it's a getting a bit clunky and I'm having trouble expanding on the content, namely moving it all over into a GUI. Does anyone have any recommendations/ideas as to how I can optimize my code so that it'll be easier to update as I go along?

The idea of the game is that you are an alien and are able to make drones using the resources nutrients and metals. The resources are gained by sending your drones to explore different areas, thus far: mountains, plains, coast, and forest. For now that's all I've coded in but I know the code could be much more efficiently laid out for when I add different creature encounters, more areas, etc.

Here is a link to the Github: https://github.com/FormOther/Hive-Quest

Here is the main Hive game:

 import java.util.Scanner;
 import java.util.Random;

 public class Hive {
 //Class Instances are defined here.
     Random random = new Random();
     Events event = new Events();
     static Scanner myScanner = new Scanner(System.in);
     static Scanner enterScanner = new Scanner(System.in);

 //Nutrients in the main menu
    static int nutrients = 50;
    static int metals = 0;

//Nutrients gained while exploring
    public int missionNutrients;
    public int missionMetals;

//Drones available in the menu
    static int warriorDrones; 
    static int workerDrones;
    static int thinkerDrones;
    static int totalDrones = warriorDrones + workerDrones + thinkerDrones;

//Drones available while exploring
    public int missionWorkerDrones;
    public int missionWarriorDrones;
    public int missionDrones;

//Integers for battles
    public int critterHealth;
    int d2Result;
    int d3Result;
    int d10Result;
    int d20Result;
    int d30Result;
    int d50Result;
    int d100Result;

//Name Strings
    static String playerName;
    public String critterName;

//booleans for battle locations
    boolean mountBattle;
    boolean forestBattle;
    boolean plainBattle;
    boolean coastBattle; 

//booleans for player actions
    boolean dronesOffensive;
    boolean dronesDefensive;
    boolean dronesEvasive;

//booleans for creature actions
    boolean critterOffensive;
    boolean critterDefensive;
    boolean critterEvasive;

int mainMenuChoice;
int exploreMenuChoice;
int eggMenuChoice;
int droneRecruit;
int battleChoice;

//Opening Scene is here
    public void openingScene() {
        myScanner = new Scanner(System.in);
        System.out.println("What color is your carapace?");
        playerName = myScanner.nextLine();
    }

//Hive Main Menu Here
    public void mainMenu() {
        d2Result = 0;
        d3Result = 0;
        d10Result = 0;
        d20Result = 0;
        d30Result = 0;
        d50Result = 0;
        d100Result = 0;
        System.out.println("\n----------------------------------------------
----------------------");
    System.out.println("Your are the " + playerName + " Queen.");
    System.out.println("You are currently resting in your newly formed 
hive.\n");
    System.out.println("You have " + nutrients + " nutrients.");
    System.out.println("You have " + metals + " metals.\n");
    System.out.println("You have " + workerDrones + " worker drones.");
    System.out.println("You have " + warriorDrones + " warrior drones.");
    System.out.println("You have " + thinkerDrones + " thinker drones.\n");
    System.out.println("What would you like to do?\n");
    System.out.println("1) Lay Egg");
    System.out.println("2) Explore Outside");
    System.out.println("3) Check Hive"); 
    /*if (spaceshipMine = true) {
        System.out.println("4) Mine the derelict");
    }*/
    System.out.println("\n--------------------------------------------------------------------");
    mainMenuChoice = myScanner.nextInt();


    switch(mainMenuChoice) {
    case 1: makeDroneMenu();
    break;
    case 2: exploreBarracks();
    break;
    case 3: checkHiveMenu();
    break;
    default: System.out.println("That's not a choice!");
    mainMenu();
    break;
    }

}

//Check Hive Menu
    public void checkHiveMenu() {
    System.out.println("You are the " + playerName + " Queen.\n");
    System.out.println("You have " + nutrients + " nutrients.");
    System.out.println("You have " + metals + " metals.\n");
    System.out.println("You have " + workerDrones + " worker drones.");
    System.out.println("You have " + warriorDrones + " warrior drones.");
    System.out.println("You have " + thinkerDrones + " thinker drones.\n");
    enterScanner.nextLine();
    mainMenu();
}

//Lay Egg Main Menu
    public void makeDroneMenu() {
        if (nutrients >= 5) {
            System.out.println("\n------------------------------------------
--------------------------\n");
            System.out.println("What kind of child will be born to the hive?
\n");
            System.out.println("You have " + nutrients + " nutrients 
available.");
            System.out.println("You have " + metals + " metals 
available.\n");         
            System.out.println("1) Worker Drone | Cost: -5 Nutrients");
            System.out.println("2) Warrior Drone | Cost: -10 Nutrients, -5 
Metals");
            System.out.println("3) Thinker Drone | Cost: -6 Nutrients");
            System.out.println("4) Back");
            eggMenuChoice = myScanner.nextInt();
            System.out.println("\n------------------------------------------
 --------------------------\n");

            switch(eggMenuChoice) {
            case 1:
                addWorker();
                makeDroneMenu();
                break;  
            case 2:
                addWarrior();
                makeDroneMenu();
                break;  
            case 3:
                addThinker();
                makeDroneMenu();
                break;  
            case 4:
                mainMenu();
                break;
            }
        } else if (nutrients < 4) {
            System.out.println("You don't have enough nutrients to make 
drones!");
            mainMenu();
        }
    }

//Explore Recruitment Menu
    public void exploreBarracks() {
    System.out.println("------------------------------------------------------------------");
    System.out.println("Which drones do you send to explore?\n");

    System.out.println("You have " + workerDrones + " worker drones available.");
    System.out.println("You have " + warriorDrones + " warrior drones available.\n");

    System.out.println("You assigned " + missionWorkerDrones + " worker drones to explore.");
    System.out.println("You have " + missionWarriorDrones + " warrior drones to explore.\n");

    System.out.println("1) Add worker drones");
    System.out.println("2) Add warrior drones");
    System.out.println("3) Clear exploration queue");
    System.out.println("4) Continue");
    System.out.println("5) Back");  
    droneRecruit = myScanner.nextInt();
    System.out.println("------------------------------------------------------------------");
    switch (droneRecruit) {
        case 1:
            if (workerDrones == 0) {
                System.out.println("You don't have enough worker drones to explore for you.");
                exploreBarracks();
            } else {
            recruitWorker();
            exploreBarracks();
            }
            break;
        case 2:
            if (warriorDrones == 0) {
                System.out.println("You don't have enough warrior drones to explore for you.");
                exploreBarracks();
            } else {
            recruitWarrior();
            exploreBarracks();
            }
            break;
        case 3:
            resetDrones();
            exploreBarracks();
        case 4:
            if (missionWorkerDrones == 0 && missionWarriorDrones == 0) {
                System.out.println("You haven't assigned any drones to explore yet!");
                exploreBarracks();
            } else {
            exploreMenu(); 
            }
            break;
        case 5: 
            resetDrones();
            mainMenu();
            break;
        default:
            System.out.println("That's not an option.");
            exploreMenu();
            break;
}
}

//Exploration Location Menu
public void exploreMenu() {
    System.out.println("\n--------------------------------------------------------------------\n");
    System.out.println("Where would you like your children to explore?\n");
    System.out.println("1) The mountains to the north.\n");
    System.out.println("2) The forest to the south.\n");
    System.out.println("3) The plains to the east.\n");
    System.out.println("4) The coastline to the west.\n");
    System.out.println("5) Back");
    System.out.println("\n--------------------------------------------------------------------\n");

    exploreMenuChoice = myScanner.nextInt();


    switch (exploreMenuChoice) {
    case 1: 
        exploreMountains();
        break;
    case 2: 
        exploreForest();
        break;
    case 3: 
        explorePlains();
        break;
    case 4: 
        exploreCoast();
        break;
    case 5: 
        resetDrones();
        mainMenu();
        break; 
    default: 
        System.out.println("That isn't a place you can explore.");
        enterScanner.nextLine();
        exploreMenu();
        break;
    }
}

//Battle encounter Menu
public void battleMenu() {
    System.out.println("\n------------------------------------------------------------------\n");
    System.out.println("You are currently fighting a " + critterName + ".");
    System.out.println("The " + critterName + " has " + critterHealth + " health.");
    if (missionWorkerDrones > 0) {
    System.out.println("\nYou have " + missionWorkerDrones + " worker drones available to fight.");
    }
    if (missionWarriorDrones > 0) {
    System.out.println("You have " + missionWarriorDrones + " warrior drones available to fight.");
    }
    System.out.println("");
    System.out.println("How should your drones fight this enemy?\n");
    System.out.println("1) Offensively");
    System.out.println("2) Defensively");
    System.out.println("3) Evasively");
    battleChoice = myScanner.nextInt();
    System.out.println("\n------------------------------------------------------------------\n");   
    switch (battleChoice) {
    case 1:
    droneOffensive();
    break;
    case 2:
    droneDefensive();
    break;
    case 3:
    droneEvasive(); 
    break;
    default:
    System.out.println("That is not an option.");
    battleMenu();
    break;
    }
}

//Option for if the player chooses the OFFENSIVE option
public void droneOffensive() {
System.out.println("Your drones charge the " + critterName + "!");
dronesOffensive = true;
dronesDefensive = false;
dronesEvasive = false;

//This is where the critter attack goes
/*
 * d100();
 * 
 * if (d100Result >= 0 && d100Result <= 20) {
 * 
 * } else if (d100Result >= 21 && d100Result <= 40) {
 * 
 * } else if (d100Result >= 41 && d100Result <= 100) {
 * 
 * } else {
 * System.out.println(there is an error here!");
 * }
 * 
 */
d3();
switch (d3Result) {
case 1:
    critterOffensive = true;
    critterDefensive = false;
    critterEvasive = false;
    System.out.println("The " + critterName + " charges!");
    System.out.println("Your children and the " + critterName + " are evenly matched!");
    break;
case 2:
    critterDefensive = true;
    critterOffensive = false;
    critterEvasive = false;
    System.out.println("The " + critterName + " protects itself!");
    System.out.println("Your children crush the " + critterName + "'s defenses!");
    System.out.println("The " + critterName + " takes damage!");
    critterHealth -= 1 * missionWorkerDrones + (missionWarriorDrones * 2);
    break;
case 3:
    critterEvasive = true;
    critterDefensive = false;
    critterOffensive = false;
    System.out.println("The " + critterName + " moves quickly!");
    System.out.println("Your children are outflanked by the " + critterName + "!");
    System.out.println("One of your drones falls from it's wounds!");
    d2();
    switch (d2Result) {
        case 1:
            if (missionWarriorDrones > 0) {
                killWarrior();
            } else if (missionWarriorDrones <= 0) {
                killWorker();
            }
            break;
        case 2:
            if (missionWorkerDrones > 0) {
                killWorker();
            } else if (missionWorkerDrones <= 0) {
                killWarrior();
            }
            break;
        default:
            System.out.println("There is an error here");
            break;
    }
    break;
default:
    System.out.println("Here is where the error is.");
    }
    d3Result = 0;
    d2Result = 0;

//End loop or continue battle
if (missionWorkerDrones <= 0 && missionWarriorDrones <= 0) {
    System.out.println("Your drones were wiped out by the " + critterName);
    resetDrones();
    enterScanner.nextLine();
    mainMenu();
} else if (critterHealth <= 0) {
    System.out.println("Your drones brought down the " + critterName);
    getSpoils();
    addSpoils();
    resetDrones();
    enterScanner.nextLine();
    mainMenu();
} else {
    battleMenu();
}

}

//Option for if the player chooses the DEFENSIVE option
public void droneDefensive() {
System.out.println("Your drones shield eachother from the " + critterName + "!");
dronesDefensive = true;
dronesOffensive = false;
dronesEvasive = false;

//This is where the critter attack goes
d3();
switch (d3Result) {
case 1:
    critterOffensive = true;
    critterDefensive = false;
    critterEvasive = false;
    System.out.println("The " + critterName + " charges!");
    System.out.println("Your children's defenses are crushed by the " + critterName + "!");
    System.out.println("One of your drones falls from it's wounds!");
    d2();
    switch (d2Result) {
        case 1:
            if (missionWarriorDrones > 0) {
                killWarrior();
            } else if (missionWarriorDrones <= 0) {
                killWorker();
            }
            break;
        case 2:
            if (missionWorkerDrones > 0) {
                killWorker();
            } else if (missionWorkerDrones <= 0) {
                killWarrior();
            }
            break;
        default:
            System.out.println("There is an error here");
            break;
    }
    break;

case 2:
    critterDefensive = true;
    critterOffensive = false;
    critterEvasive = false;
    System.out.println("The " + critterName + " protects itself!");
    System.out.println("The " + critterName + " and your drones poke at eachothers defenses to no avail!");
    break;
case 3:
    critterEvasive = true;
    critterDefensive = false;
    critterOffensive = false;
    System.out.println("The " + critterName + " moves quickly!");
    System.out.println("YOur children hold their ground and lay into the " + critterName + "!");
    System.out.println("The " + critterName + " takes damage!");
    critterHealth -= 1 * missionWorkerDrones + (missionWarriorDrones * 2);
    break;

default:
    System.out.println("Here is where the error is.");
    break;
}
d3Result = 0;
d2Result = 0;
//End loop or continue battle
if (missionWorkerDrones <= 0 && missionWarriorDrones <= 0) {
    System.out.println("Your drones were wiped out by the " + critterName);
    resetDrones();
    enterScanner.nextLine();
    mainMenu();
} else if (critterHealth <= 0) {
    System.out.println("Your drones brought down the " + critterName);
    getSpoils();
    addSpoils();
    resetDrones();
    enterScanner.nextLine();
    mainMenu();
} else {
    battleMenu();
    }
    }

//Option for if the player chooses the EVASIVE option
public void droneEvasive() {
System.out.println("Your drones rush around in a dizzying flurry of chitin!");
dronesEvasive = true;
dronesDefensive = false;
dronesOffensive = false;

//This is where the critter attack goes
d3();
switch (d3Result) {
case 1:
    critterOffensive = true;
    critterDefensive = false;
    critterEvasive = false;
    System.out.println("The " + critterName + " charges!");
    System.out.println("Your children easily ourflank the " + critterName + "!");
    System.out.println("The " + critterName + " takes damage!");
    critterHealth -= 1 * missionWorkerDrones + (missionWarriorDrones * 2);
    break;

case 2:
    critterDefensive = true;
    critterOffensive = false;
    critterEvasive = false;
    System.out.println("The " + critterName + " protects itself!");
    System.out.println("The " + critterName + "holds it's ground and lays into your children!");
    System.out.println("One of your drones falls from it's wounds!");
    d2();
    switch (d2Result) {
        case 1:
            if (missionWarriorDrones > 0) {
                killWarrior();
            } else if (missionWarriorDrones <= 0) {
                killWorker();
            }
            break;
        case 2:
            if (missionWorkerDrones > 0) {
                killWorker();
            } else if (missionWorkerDrones <= 0) {
                killWarrior();
            }
            break;
        default:
            System.out.println("There is an error here");
            break;
    }
    break;

case 3:
    critterEvasive = true;
    critterDefensive = false;
    critterOffensive = false;
    System.out.println("The " + critterName + " moves quickly!");
    System.out.println("Your children and the " + critterName + " dance around eachother, looking for an opening.");
    break;

default:
    System.out.println("Here is where the error is.");
    break;
}
d3Result = 0;
d2Result = 0;
//End loop or continue battle
if (missionWorkerDrones <= 0 && missionWarriorDrones <= 0) {
    System.out.println("Your drones were wiped out by the " + critterName + "!");
    resetDrones();
    enterScanner.nextLine();
    mainMenu();
} else if (critterHealth <= 0) {
    System.out.println("Your drones brought down the " + critterName + "!");
    getSpoils();
    addSpoils();
    resetDrones();
    enterScanner.nextLine();
    mainMenu();
} else {
    battleMenu();
}
}

//Mountain Exploration Roll Table
public void exploreMountains() {
    System.out.println("Your drones explore the mountainous region.");
    d100();
    //System.out.println("Rolled a " + d100Result);
    if (d100Result <= 0) {
        event.mountEvent1();
        missionWarriorDrones = 0;
        missionWorkerDrones = 0;
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 0 && d100Result <= 10) {
        System.out.println("Your drones don't find anything in the mountains.");
        enterScanner.nextLine();
        resetDrones();
        mainMenu();
    } else if (d100Result >= 11 && d100Result <= 20) {
        event.mountEvent2();
        //mountBattle = true;
        hillCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 21 && d100Result <= 30) {
        event.mountEvent3();
        //mountBattle = true;
        hillCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 31 && d100Result <= 40) {
        event.mountEvent4();
        //mountBattle = true;
        hillCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 41 && d100Result <=50) {
        event.mountEvent5();
        //mountBattle = true;
        hillCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 51 && d100Result <= 60) {
        event.mountEvent6();
        d10();
        missionMetals = d10Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("\nYou gain " + missionMetals + " metals!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 61 && d100Result <= 70) {
        event.mountEvent7();
        d20();
        missionMetals = d20Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("\nYou gain " + missionMetals + " metals!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 71 && d100Result <= 80) {
        event.mountEvent8();
        d20();
        d10();
        missionMetals = d20Result * missionWorkerDrones + missionWarriorDrones;
        missionNutrients = d10Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("Your gain " + missionMetals + " metals and " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 81 && d100Result <= 90) {
        event.mountEvent9();
        d30();
        missionMetals = d30Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("\nYou gain " + missionMetals + " metals!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 91 && d100Result <= 99) {
        event.mountEvent9a();
        d50();
        missionMetals = d50Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("\nYou gain " + missionMetals + " metals!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result == 100) {
        System.out.println("While exploring the mountains your drones find a scrap of rectancular metal embedded in a stone");
        System.out.println("They follow the trail of discarded metal until they come to a valley and crashed within it is a colossal spaceship!");
        System.out.println("Because you now know the way to this site, you can come here to mine metals for free!");
        //spaceshipMine = true;
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else {
        System.out.println("There is an error here");
    }
}

//Forest Exploration Roll Table
public void exploreForest() {
    System.out.println("Your drones explore the forested region.");
    d100();
    //System.out.println("Rolled a " + d100Result);
    if (d100Result <= 0) {
        event.forestEvent1();
        missionWarriorDrones = 0;
        missionWorkerDrones = 0;
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 1 && d100Result <= 10) {
        System.out.println("Your drones don't find anything in the forest.");
        enterScanner.nextLine();
        resetDrones();
        mainMenu();
    } else if (d100Result >= 11 && d100Result <= 20) {
        event.forestEvent2();
        woodsCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 21 && d100Result <= 30) {
        event.forestEvent3();
        d10();
        missionNutrients = d10Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("\nYou gain " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 31 && d100Result <= 40) {
        event.forestEvent4();
        woodsCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 41 && d100Result <=50) {
        event.forestEvent5();
        woodsCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 51 && d100Result <= 60) {
        event.forestEvent6();
        d10();
        missionNutrients = d10Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("\nYou gain " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 61 && d100Result <= 70) {
        event.forestEvent7();
        d20();
        missionNutrients = d20Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("\nYou gain " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 71 && d100Result <= 80) {
        event.forestEvent8();
        d30();
        missionNutrients = d30Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("\nYou gain " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 81 && d100Result <= 90) {
        event.forestEvent9();
        d50();
        missionNutrients = d50Result * missionWorkerDrones + missionWarriorDrones;
        System.out.println("\nYou gain " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 91 && d100Result <= 99) {
        event.forestEvent9a();
        woodsCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result == 100) {
        event.forestEvent10();
        enterScanner.nextLine();
        mainMenu();
    } else {
        System.out.println("There is an error here");
    }
}

//Plains Exploration Roll Table
public void explorePlains() {
    System.out.println("Your drones explore the flat expanse.");
    d100();
    //System.out.println("Rolled a " + d100Result);
    if (d100Result <= 0) {
        event.plainsEvent1();
        missionWarriorDrones = 0;
        missionWorkerDrones = 0;
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 1 && d100Result <= 10) {
        System.out.println("Your drones trek through the plains is surprisingly uneventful.");
        enterScanner.nextLine();
        resetDrones();
        mainMenu();
    } else if (d100Result >= 11 && d100Result <= 20) {
        event.plainsEvent2();
        grassCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 21 && d100Result <= 30) {
        event.plainsEvent3();
        grassCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 31 && d100Result <= 40) {
        event.plainsEvent4();
        grassCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 41 && d100Result <=50) {
        event.plainsEvent5();
        grassCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 51 && d100Result <= 60) {
        event.plainsEvent6();
        grassCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 61 && d100Result <= 70) {
        event.plainsEvent7();
        d20();
        missionNutrients = d20Result * (missionWorkerDrones + missionWarriorDrones);
        System.out.println("\nYou gain " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 71 && d100Result <= 80) {
        event.plainsEvent8();
        d20();
        missionMetals = d20Result * (missionWorkerDrones + missionWarriorDrones);
        System.out.println("\nYou gain " + missionMetals + " metals!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 81 && d100Result <= 90) {
        event.plainsEvent9();
        d50();
        missionNutrients = d50Result * (missionWorkerDrones + missionWarriorDrones);
        System.out.println("\nYou gain " + missionMetals + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 91 && d100Result <= 99) {
        event.plainsEvent9a();
        d50();
        missionMetals = d50Result * (missionWorkerDrones + missionWarriorDrones);
        System.out.println("\nYou gain " + missionMetals + " metals!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result == 100) {
        event.plainsEvent10();
    }
}

//Coast Exploration Roll Table
public void exploreCoast() {
    System.out.println("Your drones explore the coastal region.");
    d100();

    if (d100Result == 0) {
        event.coastEvent1();
        missionWarriorDrones = 0;
        missionWorkerDrones = 0;
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 1 && d100Result <= 10) {
        System.out.println("Your drones don't find anything on the coast.");
        enterScanner.nextLine();
        resetDrones();
        mainMenu();
    } else if (d100Result >= 11 && d100Result <= 20) {
        event.coastEvent2();
        seaCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 21 && d100Result <= 30) {
        event.coastEvent3();
        seaCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 31 && d100Result <= 40) {
        event.coastEvent4();
        d10();
        missionMetals = d10Result * (missionWorkerDrones + missionWarriorDrones);
        d10Result = 0;
        d10();
        missionNutrients = d10Result * (missionWorkerDrones + missionWarriorDrones);
        System.out.println("Your gain " + missionMetals + " metals and " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 41 && d100Result <=50) {
        event.coastEvent5();
        seaCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 51 && d100Result <= 60) {
        event.coastEvent6();
        seaCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 61 && d100Result <= 70) {
        event.coastEvent7();
        d20();
        missionMetals = d20Result * (missionWorkerDrones + missionWarriorDrones);
        d10();
        missionNutrients = d10Result * (missionWorkerDrones + missionWarriorDrones);
        System.out.println("Your gain " + missionMetals + " metals and " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 71 && d100Result <= 80) {
        event.coastEvent8();
        d10();
        missionMetals = d10Result * (missionWorkerDrones + missionWarriorDrones);
        d20();
        missionNutrients = d20Result * (missionWorkerDrones + missionWarriorDrones);
        System.out.println("Your gain " + missionMetals + " metals and " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result >= 81 && d100Result <= 90) {
        event.coastEvent9();
        seaCritter();
        enterScanner.nextLine();
        battleMenu();
    } else if (d100Result >= 91 && d100Result <= 99) {
        event.coastEvent9a();
        d30();
        missionMetals = d10Result * (missionWorkerDrones + missionWarriorDrones);
        d30Result = 0;
        d30();
        missionNutrients = d10Result * (missionWorkerDrones + missionWarriorDrones);
        System.out.println("Your gain " + missionMetals + " metals and " + missionNutrients + " nutrients!");
        addSpoils();
        resetDrones();
        enterScanner.nextLine();
        mainMenu();
    } else if (d100Result == 100) {
        event.coastEvent10();
    } else {
        System.out.println("Here there be errors.");
    }
}

//Spawn Worker Drone Method
public int addWorker() {
    if (nutrients >= 5) {
        System.out.println("You lay a small egg which quickly hatches ino a worker drone!");
        System.out.println("'Mother! Ready to work! Work hard for Mother!'");
        workerDrones += 1;
        nutrients -= 5;
    } else {
        System.out.println("You do not have enough resources for a worker drone.");
        makeDroneMenu();
    }
    return workerDrones;
}

//Spawn Warrior Drone Method
public int addWarrior() {
    if (nutrients >= 10 && metals >= 5) {
        System.out.println("You lay a large egg that quickly hatches into a warrior drone!");
        System.out.println("'Ready to fight for Mother!'");
        warriorDrones += 1;
        nutrients -= 10;
        metals -= 5;
    } else {
        System.out.println("You do not have enough resources for a warrior drone.");
        makeDroneMenu();
    }
    return warriorDrones;
}

//Spawn Thinker Drone Method
public int addThinker() {
    if (nutrients >= 6) {
        System.out.println("You lay a translucent egg that quickly hatches into a thinker drone!");
        System.out.println("'Have ideas! Many thoughts for Mother!'");
        thinkerDrones += 1;
        nutrients -= 6;
    }else {
        System.out.println("You do not have enough resources for a thinker drone.");
        makeDroneMenu();
    }
    return thinkerDrones;
}

//Recruit Worker Drone 
public void recruitWorker() {
    workerDrones -= 1;
    missionWorkerDrones += 1; 
    missionDrones += 1;
}

//Recruit Warrior Drone
public void recruitWarrior() {
    warriorDrones -= 1;
    missionWarriorDrones += 1;
    missionDrones += 1;
}

 //Kill Worker Drone
public void killWorker() {
        missionWorkerDrones -= 1;
    }

//Kill Warrior Drone
public void killWarrior() {
        missionWarriorDrones -= 1;
    }   

//Basic mountain critter
public void hillCritter() {
    critterName = ("mountain creature");
    critterHealth = 20;
}

//Basic forest critter
public void woodsCritter() {
    critterName = ("forest creature");
    critterHealth = 5;
}

//Basic plains critter
public void grassCritter() {
    critterName = ("grass creature");
    critterHealth = 15;
}

//Basic coast critter
public void seaCritter() {
    critterName = ("sea creature");
    critterHealth = 15;
}

//Add explore spoils to total nutrients/metals
public void addSpoils() {
nutrients += missionNutrients;
metals += missionMetals;
missionNutrients = 0;
missionMetals = 0;
}

//Battle win spoils
public void getSpoils() {
//TO DO:
//set it up so that the spoils are random integers depending on the region
missionMetals += 5;
missionNutrients += 20;
System.out.println("You gain " + missionMetals + " metals and " + missionNutrients + " nutrients.");
}

//Returns drones from missions back to the main menu
public void resetDrones () {
workerDrones += missionWorkerDrones;
warriorDrones += missionWarriorDrones;
missionWorkerDrones = 0;
missionWarriorDrones = 0;
missionDrones = 0;

}

//D2 dice roller 
public int d2() {
d2Result += random.nextInt(2) +1;
return d2Result;
}

//D3 dice roller
public int d3() {
    d3Result += random.nextInt(3) +1;
    return d3Result;
    }

//D10 dice roller 
public int d10() {
d10Result += random.nextInt(10) +1;
return d10Result;
}

//D20 dice roller 
public int d20() {
d20Result += random.nextInt(20) +11;
return d20Result;
}

//D30 dice roller 
public int d30() {
d30Result += random.nextInt(30) +21;
return d30Result;
}

//D50 dice roller 
public int d50() {
d50Result += random.nextInt(50) +41;
return d50Result;
}

//D100 dice roller 
public int d100() {
d100Result += random.nextInt(100);
return d100Result;
}

//THE MAIN METHOD ALL THE FUN STARTS HERE!!!
public static void main(String[] args) {
    Hive hive = new Hive();
    hive.openingScene();
    hive.mainMenu();
    }
}

And here is the code for the events:

public class Events {

//MOUNTAIN EVENTS START

//Event 1: Lose all drones
public void mountEvent1() {
    System.out.println("------------------------------------------------------------------------------------------------------------------");
    System.out.println("Your drones pick through the crags and stones of the mountain, searching for resources for your growing hive.");
    System.out.println("There is a rumble and your drones get one good look at the wave of stone");
    System.out.println("headed toward them before your link to them is severed.");
    System.out.println("------------------------------------------------------------------------------------------------------------------");
}

//Event 2: Combat Encounter
public void mountEvent2() {
System.out.println("Your drones make their way through the mountain when they are suddenly ambushed!");
}

//Event 3: Combat Encounter
public void mountEvent3() {
System.out.println("While out exploring the mountainous wilderness your drones encounter a hostile creature!");
}

//Event 4: Combat Encounter
public void mountEvent4() {
System.out.println("Your children don't get far from the hive before they encounter a hostile creature.");
}

//Event 5: Combat Encounter
public void mountEvent5() {
System.out.println("While out patrolling the mountains, your drones encounter a hostile creature!");
}

//Event 6: Resource Gain, Metals
public void mountEvent6() {
System.out.println("While out patrolling the mountains, your drones find a small deposit of metal ore.");
}

//Event 7: Resource Gain, Metals
public void mountEvent7() {
System.out.println("While out patrolling the mountains, your drones find a respectable deposit of metal ore.");
}

//Event 8: Resource Gain, Metals + Nutrients
public void mountEvent8() {
System.out.println("Your drones find the carcass of a large mountainous creature.");
}

//Event 9: Resource Gain Metals
public void mountEvent9() {
System.out.println("While out patrolling the mountains, your drones find a large deposit of metal ore.");
}

//Event 9a: Large Resource Gain Metals
public void mountEvent9a() {
System.out.println("While out patrolling the mountains, your drones find an enormous deposit of metal ore.");
}

/**In which the hive discovers a colossal derelict spaceship and has free access to a 
 * random value of metals depending on how many workers they send to mine it. Basically
 * a metal farm. Unlocks once on the main menu.
 */ 
public void mountEvent10() {
System.out.println("");
}
//MOUNTAIN EVENTS END

//FOREST EVENTS START
//Event 1: All drones killed
public void forestEvent1() {
System.out.println("Your drones scout out the forest before your connection is severed from them one by one.");
System.out.println("Whatever is picking them off is too fast to see, and you only catch a blur of movement");
System.out.println("before the last of your children vanishes from your concience.");   
}

//Event 2: Combat Encounter
public void forestEvent2() {
System.out.println("Your drones encounter a creature while out patrolling the forest"); 
}

//Event 3: Find pathetic amount of nutrients
public void forestEvent3() {
System.out.println("Your drones harvest some of the local flora and bring it back to the hive!");   
}

//Event 4: Combat Encounter
public void forestEvent4() {
System.out.println("Your drones stumble across a hostile creature while in the forest!");   
}

//Event 5: Combat Encounter 
public void forestEvent5() {
System.out.println("Your drones are ambushed by a hostile creature in the forest!");        
}

//Event 6: Find acceptable amount of nutrients
public void forestEvent6() {
System.out.println("Your drones capture a small den of creatures that they break down into nutrients.");    
}

//Event 7: find acceptable amount of nutrients
public void forestEvent7() {
System.out.println("Your drones notice several creatures eating berries off of a bush.");
System.out.println("They cheerfully uproot the bush and bring it back to the hive!");   
}

//Event 8: find good amount of nutrients
public void forestEvent8() {
System.out.println("Your drones encounter the corpse of a creature cooling in the forest!");    
}

//Event9: find excellent amount of nutrients
public void forestEvent9() {
System.out.println("Your drones encounter the corpse of a large creature cooling in the forest!");
}

//Event 9a: difficult encounter for VERY high yield of nutrients (maybe a danger trigger or something)
public void forestEvent9a() {
System.out.println("Your drones hear a screech and before they can react a 
very large creature attacks them!");
}

/**In which the Hive discovers a giant mushroom that they can harvest for free nutrients. 
* Unlocks the mushroom on the Main menu.
*/
public void forestEvent10() {
System.out.println("Your drones notice a river running red with what looks like a viscous sap.");
System.out.println("When one of yur drones tries this fluid, you notice that it is very nutritious!");
System.out.println("Your drones follow the flow of the river to it's source and find themselves before a gigantic mostly submeged mushroom!");
System.out.println("The water that flows around the mushroom is converted into this nutritious red jelly!");
System.out.println("Elated, you order your drones to collect as much of this foodstuff as possible before returning!");
System.out.println("And now that you know where it is, your drones can always come back to collect more with ease!");

}
//FOREST EVENTS END

//PLAINS EVENTS START
//Event 1: All drones killed
public void plainsEvent1() {
System.out.println("As your drones venture along the grassy plains, you hear a sieries of sonic shrieks from above.");
System.out.println("Without warning, hordes of blurry shapes burst from the cloudy skies and snatch all of drones before retreating back into the clouds.");
System.out.println("All of your drones have been killed!");
}

//Event 2: Combat Encounter
public void plainsEvent2() {
System.out.println("While venturing through the plains, your children encounter a hostile creature!");
}

//Event 3: Combat Encounter
public void plainsEvent3() {
System.out.println("Your children are exploring the vast plains when the hear a screech from above!");
}

//Event 4: Combat Encounter
public void plainsEvent4() {
System.out.println("Your children ecounter one of the many hostile creatures in the plains!");
}

//Event 5: Combat Encounter
public void plainsEvent5() {
System.out.println("Your drones don't have to wander in the plains long before they encounter a hostile creature!");
}

//Event 6: Combat Encounter
public void plainsEvent6() {
System.out.println("Your children are immediately attacked by a hostile creature.");

}

//Event 7: Nutrient Gain
public void plainsEvent7() {
System.out.println("Your drones find the still warm corpse of one of the many hostile creatures in the area.");
System.out.println("They gather what remains they can and return to the hive.");
}

//Event 8: Metals gain
public void plainsEvent8() {
System.out.println("While out in the plains your drones come across a deposit of surface metals!");

}

//Event 9 Large Nutrient gain
public void plainsEvent9() {
System.out.println("While out exploring, your drones come into contact with one of the enormous armored insectoids that roam the plains.");
System.out.println("It is heavily wounded, though you find no trace of what brought it to this state.");
System.out.println("You witness the creature's last heaving breaths before it goes still.");
System.out.println("Quickly as to avoid other predators, your drones strip as much meat off the creature as possible and return to the hive.");
}

//Event 9a Large Metals gain
public void plainsEvent9a() {
System.out.println("Your drones are exploring the plains when a line of fire scorches across the sky and lands deeper into the plains.");
System.out.println("Carefully your children approach the crash site, and chitter with glee when they peer over the lip of the impact crater.");
System.out.println("Resting at the bottom of the pit is a massive meteor, shimmering with heat and the glow of raw metals.");
System.out.println("After waiting for the meteor to cool, your drones carefully extract what metals they can and make their way back to the hive.");

}

/**
* In which the hive can fight some gigantic bug thing and if they win get research for 
* VERY powerful chitin armor, and unlock the titantic creature class. 
*/
public void plainsEvent10() {
System.out.println("Your drones encounter one of the heavily armored insectoids that roam the plains!");
System.out.println("Placeholder text");

}
//PLAINS EVENTS END

//COAST EVENTS START
//Event 1: All drones die
public void coastEvent1() {
System.out.println("Your drones pick across the beach carefully, scanning for useful things for the hive.");
System.out.println("Suddenly massive barbed tentacle erupts from the water and sweeps all of your drones beneath the waves.");
System.out.println("The last thing you can see from their perspective is a truly massive beast snapping up all your drones");
System.out.println("before your connection to them is cut.");
}
//Event 2:  Combat Encounter
public void coastEvent2() {
System.out.println("Your drones encounter a hostile creature on the beach!");
}
//Event 3:  Combat Encounter 
public void coastEvent3() {
System.out.println("While travelling along the coast, your drones encounter a hostile creature");
}
//Event 4:  Find small metals and nutrients
public void coastEvent4() {
System.out.println("Your drones recover the remains of some form of crustacean whose shell is oddly metallic.");
}
//Event 5:  Combat Encounter
public void coastEvent5() {
System.out.println("Your children's search for materials on the beach is interrupted when a hostile creature");
System.out.println("attacks!");
}
//Event 6:  Combat Encounter
public void coastEvent6() {
System.out.println("The drones you sent to explore the coast are attacked by a hostile creature!");
}
//Event 7:  Find acceptable metals and nutrients
public void coastEvent7() {
System.out.println("Your drones find a plantlike growth growing on a metallic outcropping.");
System.out.println("They bring samples of both back to the hive.");
}
//Event 8:  Find good metals and nutrients
public void coastEvent8() {
System.out.println("Your drones find an empty metallic shell while exploring the coast.");
System.out.println("The ragged chunks of meat lining the inside indicate that it was emptied by force.");
System.out.println("Your children bring samples of both back to the hive.");
}
//Event 9: Combat Encounter
public void coastEvent9() {
System.out.println("As your drones explore the breadth of the coast, a large hostile creature attacks!");
}
//Event 9a: Find excellent metals and nutrients
public void coastEvent9a() {
System.out.println("Your drones find the beached remains of an larged crustacean while exploring the coast.");
System.out.println("It's hardly been touched by any passing creatures, so your drones collect as much as they.");
System.out.println("can and return to the hive.");
}
/**
* In which the hive finds....something cool I dont know yet. 
*/      
public void coastEvent10() {
System.out.println("YOU ROLLED A 100 MO FUCKAAAAA!");
System.out.println("This is a placeholder for something truly spectacular");
}
//COAST EVENTS END

}
\$\endgroup\$
4
\$\begingroup\$

One Scanner per stream

     static Scanner myScanner = new Scanner(System.in);
     static Scanner enterScanner = new Scanner(System.in);

System.in is publicly available. As such, there is no reason to make the Scanner masking it less than public (you made it package-private, the default).

     public final static Scanner myScanner = new Scanner(System.in);

You also don't need two Scanner objects for System.in. One is plenty and is less likely to lead to confusion.

Since the Scanner is going to stay the same for the life of the program, we can make it final.

As previously said, we only need one Scanner for each stream. We only need multiple Scanner objects if we have multiple streams, e.g. for files or whatever.

Structure

Hive is huge. If I were editing this code for more than trivial changes, the first thing that I would do would be to refactor it into smaller pieces. This would help me figure out what should and should not go together.

Having the class with main in it do everything can be confusing. A first step might be to move main into its own class. Then you can start thinking about how the other elements interact. Should they share classes? Have separate classes?

You have results stored in the Hive. Why not provide a Results class for that?

Similarly, why not provide a separate class for processing input and output? Or provide a separate class for managing things like resources.

You might create a Critter interface or class rather than changing a Hive field.

One of the reasons that you're having trouble migrating to a GUI is that your input and output is intermixed with everything else. Try to separate the game logic from the input and output. Then you don't have to change the logic to migrate to a GUI.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.