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

I've recently started creating a text-based game and have already asked a question about it here. In asking this question, it was pointed out that my game loop was too long and that I had to split things up. I have been given multiple different suggestions that I am currently considering. Right now I'm trying to create GameStates through the use of an FSM to improve readability and "cleanliness" (for lack of a better term) code. In addition to that, I have undertaken this task to learn about the uses of FSMs in general because I am self taught and I am constantly trying to learn more about game programming.

My question today is …

In the switch statement, here:

public void stateSwitch () {
switch (state) {
case NAME_STATE:
n.getName ();
Pause;

BATTLE_STATE box:
b.spawnEnemy ();
Pause;

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

}

How to set in.nextLine () as a parameter or condition to move to the next state using:

                public class nameState {

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


empty public getName () {
Scanner in = new Scanner (System.in);

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

}

Similar to the use of:

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

Note that the:

private state of GameStateManager;
and
GameState game = new GameStateManager.GameState (state);

are currently throwing errors that I am aware of. However, this line was written in order to understand how to recover this in.nextLine () and define it as what is needed to finally move from NAME_STATE at BATTLE_STATE.

The idea is that when the game is opened / executed, the user receives the message "Welcome", then his name is asked and, once the user has entered the desired name, he / she switch to the desired mode. BATTLE_STATE and enter the battle with an enemy using spawnEnemy (). This is temporary because I would like to incorporate a MAIN_MENU_STATE at one point, but I'm just taking things one step at a time.

You will find below all of my code for GameStateManager:

    Public enumeration GameStateManager {

NAME_STATE, BATTLE_STATE, VICTORY_STATE, DEATH_STATE;

Public class GameState {
GameStateManager state;

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

}

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

public void stateSwitch () {
switch (state) {
case NAME_STATE:
n.getName ();
Pause;

BATTLE_STATE box:
b.spawnEnemy ();
Pause;

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

}
}

}

and the nameState code linked earlier is the entire class from now on.

Note that most of the code in GameStateManager enumeration below NAME_STATE in the switch does not do anything yet. In reality victoireState and state of death are not even classes at the time of writing.

Do not hesitate to criticize this code in any way or to offer help on things that you might consider bad or clumsy, even if they do not relate to the question asked, because I wish to learn as much as possible. If the way I write my enum is incorrect, PLEASE tell me because I've had a hard time finding a reference to the question of whether or not it's the right way to do it or not .