Class ClientLauncherTUI

java.lang.Object
it.polimi.ingsw.gc14.ClientLauncherTUI

public class ClientLauncherTUI extends Object
Entry point for the TUI-based game client. Handles login, connects to the server, and drives the JLine-powered command loop.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
     
    private static final String
     
    private String
    Username of the currently logged-in player; empty string before login.
    private static final String
     
    private org.jline.reader.LineReader
    Line reader used during active gameplay, with tab-completion wired.
    private org.jline.terminal.Terminal
    JLine terminal used for all input/output.
    private TUI
    TUI view shared with the client controller.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private org.jline.reader.LineReader
    Builds the JLine LineReader used during gameplay, with tab-completion for all valid commands.
    private String
    Returns the command-line prompt string showing the current username.
    private boolean
    Prompts for username, player count, network type, and server IP, then connects.
    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.
    private boolean
    Returns true when the caller should break out of the game loop (rematch requested).
    private void
    handleDraw(String[] parts, ClientController controller)
    Handles the draw command, dispatching to the appropriate controller draw method.
    private void
    Handles the clear command by triggering a full board re-render.
    (package private) static void
    main(String[] args)
    Launches the TUI client.
    private int
    parsePos(String[] parts, int idx)
    Parses an integer position argument at idx in parts.
    private void
    Disconnects the client if one is currently connected; safe to call when already disconnected.
    private void
    Starts the TUI client.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • view

      private TUI view
      TUI view shared with the client controller.
    • terminal

      private org.jline.terminal.Terminal terminal
      JLine terminal used for all input/output.
    • gameReader

      private org.jline.reader.LineReader gameReader
      Line reader used during active gameplay, with tab-completion wired.
    • currentUsername

      private String currentUsername
      Username of the currently logged-in player; empty string before login.
    • BUILDING_DETAILS

      private static final String BUILDING_DETAILS
      See Also:
    • EVENT_DETAILS

      private static final String EVENT_DETAILS
      See Also:
    • CHARACTER_DETAILS

      private static final String CHARACTER_DETAILS
      See Also:
  • Constructor Details

    • ClientLauncherTUI

      public ClientLauncherTUI()
  • Method Details

    • main

      static void main(String[] args) throws InterruptedException
      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

      private boolean doLogin(ClientController controller)
      Prompts for username, player count, network type, and server IP, then connects.
      Parameters:
      controller - the client controller to connect.
      Returns:
      true on successful connection; false if 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:
      true on successful connection; false if input is invalid or connection fails.
    • buildGameReader

      private org.jline.reader.LineReader buildGameReader()
      Builds the JLine LineReader used during gameplay, with tab-completion for all valid commands.
      Returns:
      the configured LineReader.
    • buildPrompt

      private String buildPrompt()
      Returns the command-line prompt string showing the current username.
      Returns:
      the prompt string.
    • handleCommand

      private boolean handleCommand(String line, ClientController controller)
      Returns true when the caller should break out of the game loop (rematch requested).
    • handleDraw

      private void handleDraw(String[] parts, ClientController controller)
      Handles the draw command, 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 the clear command by triggering a full board re-render.
    • parsePos

      private int parsePos(String[] parts, int idx)
      Parses an integer position argument at idx in parts.
      Parameters:
      parts - the tokenized command array.
      idx - index of the position argument.
      Returns:
      the parsed integer, or -1 if missing or malformed.
    • safeQuit

      private void safeQuit(ClientController controller)
      Disconnects the client if one is currently connected; safe to call when already disconnected.
      Parameters:
      controller - the client controller to disconnect.