java – Game State Manager (FSM) with in.nextLine ()

I recently started creating a text-based game and had posted a question on this subject once before. When asking that question, I noticed that my game loop was too long and that I had to divide things. They gave me several different suggestions, all of which I am currently studying. Right now I'm trying to create States of the game by using an FSM to better help with the readability and "cleanup" (for lack of a better term) of the code. Apart from that, I have taken on this task to learn about the uses of the WSF in general, since I am self-taught and constantly try to learn more about the Games Programming.

My question today is …

Inside the declaration of change here:

Public Flying StateSwitch () {
switch (state) {
case NAME_STATE:
n.getName ();
break;

BATTLE_STATE case:
b.spawnEnemy ();
break;

VICTORY_STATE case:
v.reward ();
break;
DEATH_STATE case:
d.die ();

}

How can I configure the in.nextLine () as a parameter or requirement to advance to the next state using:

                name of public class

private status of GameStateManager;
GameState game = new GameStateManager.GameState (status);


public getid getName () {
Scanner on = new scanner (System.in);

System.out.println (" t ########################################################
" n  t # Welcome to Text Adventure! #" +
" n  t ######################################################################)
System.out.println (" t ---------------------------------");
System.out.println (" t What is your Adventurer name?");
String userName = in.nextLine ();

}

Similar to the use of:

switch (m_curState) {
TITLE_STATE case:
UpdateTitleScreen ();
if (UserPressesEnter ()) {
m_curState = MAINGAME_STATE;
}
break;

Note that the:

private status of GameStateManager;
Y
GameState game = new GameStateManager.GameState (status);

I am currently throwing errors that I know of. However, this line was written in an attempt to find out how to recover this in.nextLine () and configure it as what is required to finally move from NAME_STATE to BATTLE_STATE.

The idea is that when the game is opened / executed, the user will be prompted with the message "Welcome" and then asked what its name will be and, once the user enters the desired name, it will transition or change to BATTLE_STATE and go into battle with an enemy using spawnEnemy (). This is temporary since I would like to incorporate a MAIN_MENU_STATE at some point, but I'm just taking things step by step.

Below is the totality of my code for GameStateManager:

    public enumeration GameStateManager {

NAME_STATE, BATTLE_STATE, VICTORY_STATE, DEATH_STATE;

public class GameState {
State of GameStateManager;

GameState public status (GameStateManager status) {
this.state = state;

}

nameState n = new nameState ();
Battle b = new battle ();
deathState d = new deathState ();
victoryState v = new victoryState ();

Public Flying StateSwitch () {
switch (state) {
case NAME_STATE:
n.getName ();
break;

BATTLE_STATE case:
b.spawnEnemy ();
break;

VICTORY_STATE case:
v.reward ();
break;
DEATH_STATE case:
d.die ();

}
}

}

and the nameState code linked above is the complete class as of now.

Keep in mind that most of the code in GameStateManager enumeration down NAME_STATE Nothing is being done inside the switch yet. In fact state of victory Y state of death They are not even classes from the moment of writing.

Feel free to criticize this code in any way you like or offer help about things that you might consider wrong or clumsy, even if you do not refer to the question as I want to learn as much as I can. If the form in which I am writing my enumeration is incorrect, PLEASE, tell me, since it has cost me to find a reference on if this is the correct way to do it or not.