A finite-state machine tracks which menu is active and changes the interface when that state changes. Here, an enum in MetaData stores states such as MAIN_MENU, IN_GAME, GAME_OVER, and PAUSE_MENU. section 8.2.3
SetMenuState() saves the old state, updates MetaData through a logic function, then hides the old menu and shows the new one. Some transitions also hide the board, such as entering the pause menu; the game-over menu leaves it visible. section 8.6.1
Listing 8.26 Method to set the menu state in Game
public void SetMenuState(MENU_STATE newMenuState)
{
MENU_STATE oldMenuState = m_metaData.MenuState;
Logic.SetMenuState(m_metaData, newMenuState);
if (oldMenuState == MENU_STATE.MAIN_MENU)
{
m_mainMenuVisual.Hide();
}
else if (oldMenuState == MENU_STATE.GAME_OVER)
{
Board.Hide();
m_gameOverVisual.Hide();
}
else if (oldMenuState == MENU_STATE.IN_GAME && newMenuState == MENU_STATE.PAUSE_MENU)
{
Board.Hide();
}
else if (oldMenuState == MENU_STATE.PAUSE_MENU)
{
m_pauseMenuVisual.Hide();
}
if (newMenuState == MENU_STATE.MAIN_MENU)
{
m_mainMenuVisual.Show();
}
else if (newMenuState == MENU_STATE.GAME_OVER)
{
m_gameOverVisual.Show();
}
else if (newMenuState == MENU_STATE.PAUSE_MENU)
{
m_pauseMenuVisual.Show();
}
else if (newMenuState == MENU_STATE.IN_GAME)
{
Board.Show();
}
}The method’s conditional branches show how menu transitions control menu and board visibility. section 8.6.1












