Class ClientLauncherTUI
java.lang.Object
it.polimi.ingsw.gc14.ClientLauncherTUI
Entry point for the TUI-based game client.
Handles login, connects to the server, and drives the JLine-powered command loop.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate StringUsername of the currently logged-in player; empty string before login.private static final Stringprivate org.jline.reader.LineReaderLine reader used during active gameplay, with tab-completion wired.private org.jline.terminal.TerminalJLine terminal used for all input/output.private TUITUI view shared with the client controller. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate org.jline.reader.LineReaderBuilds the JLineLineReaderused during gameplay, with tab-completion for all valid commands.private StringReturns the command-line prompt string showing the current username.private booleandoLogin(ClientController controller) Prompts for username, player count, network type, and server IP, then connects.private booleandoLoginInner(ClientController controller, org.jline.reader.LineReader loginReader, org.jline.reader.LineReader ipReader) Reads login fields from the terminal and connects to the server.private booleanhandleCommand(String line, ClientController controller) Returnstruewhen the caller should break out of the game loop (rematch requested).private voidhandleDraw(String[] parts, ClientController controller) Handles thedrawcommand, dispatching to the appropriate controller draw method.private voidHandles theclearcommand by triggering a full board re-render.(package private) static voidLaunches the TUI client.private intParses an integer position argument atidxinparts.private voidsafeQuit(ClientController controller) Disconnects the client if one is currently connected; safe to call when already disconnected.private voidstart()Starts the TUI client.
-
Field Details
-
view
TUI view shared with the client controller. -
terminal
private org.jline.terminal.Terminal terminalJLine terminal used for all input/output. -
gameReader
private org.jline.reader.LineReader gameReaderLine reader used during active gameplay, with tab-completion wired. -
currentUsername
Username of the currently logged-in player; empty string before login. -
BUILDING_DETAILS
- See Also:
-
EVENT_DETAILS
- See Also:
-
CHARACTER_DETAILS
- See Also:
-
-
Constructor Details
-
ClientLauncherTUI
public ClientLauncherTUI()
-
-
Method Details
-
main
Launches the TUI client.- Parameters:
args- command-line arguments (unused).- Throws:
InterruptedException- if the thread is interrupted during startup.
-
start
private void start()Starts the TUI client. Creates a JLine terminal, loops through login → game → rematch. -
doLogin
Prompts for username, player count, network type, and server IP, then connects.- Parameters:
controller- the client controller to connect.- Returns:
trueon successful connection;falseif input is invalid or connection fails.
-
doLoginInner
private boolean doLoginInner(ClientController controller, org.jline.reader.LineReader loginReader, org.jline.reader.LineReader ipReader) Reads login fields from the terminal and connects to the server.- Parameters:
controller- the client controller to connect.loginReader- line reader used for username, player count, and network type.ipReader- line reader with localhost auto-complete for the server IP.- Returns:
trueon successful connection;falseif input is invalid or connection fails.
-
buildGameReader
private org.jline.reader.LineReader buildGameReader()Builds the JLineLineReaderused during gameplay, with tab-completion for all valid commands.- Returns:
- the configured
LineReader.
-
buildPrompt
Returns the command-line prompt string showing the current username.- Returns:
- the prompt string.
-
handleCommand
Returnstruewhen the caller should break out of the game loop (rematch requested). -
handleDraw
Handles thedrawcommand, dispatching to the appropriate controller draw method.- Parameters:
parts- the tokenized command:[draw, upper|lower, tribe|building, pos].controller- the client controller to invoke.
-
handleRender
private void handleRender()Handles theclearcommand by triggering a full board re-render. -
parsePos
Parses an integer position argument atidxinparts.- Parameters:
parts- the tokenized command array.idx- index of the position argument.- Returns:
- the parsed integer, or
-1if missing or malformed.
-
safeQuit
Disconnects the client if one is currently connected; safe to call when already disconnected.- Parameters:
controller- the client controller to disconnect.
-