diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index 6d2d854..03a7a6a 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -4,16 +4,32 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent; import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient; import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient; import it.polimi.ingsw.gc14.View.TUI.TUI; - import java.util.Scanner; +/** + * Entry point for the TUI-based game client. + * Handles the initial setup by asking the user for a username, the desired number of players, + * and the preferred network protocol (RMI or TCP). + * Once connected to the server, it continuously reads and dispatches user input to the controller. + */ public class ClientLauncherTUI { - //TODO Javadoc - TUI view; - public void main() throws InterruptedException { - view=new TUI(null); - ClientController controller = new ClientController(view); + /** + * The TUI view associated with this client. + */ + TUI view; + + /** + * Starts the TUI client. + * Prompts the user for a username, the desired number of players, and the network protocol. + * Attempts to connect to the server using either RMI or TCP depending on the selection. + * If the connection is successful, enters a loop to continuously read and process user input. + * + * @throws InterruptedException if the thread is interrupted while waiting. + */ + public void main() throws InterruptedException { + view = new TUI(null); + ClientController controller = new ClientController(view); Scanner scanner = new Scanner(System.in); System.out.println("Selezionare nome utente: "); String username = scanner.next(); @@ -22,9 +38,6 @@ public class ClientLauncherTUI { int proposedNumPlayers = scanner.nextInt(); System.out.println("Selezionare RMI[0] o TCP[1]: "); int networkType = scanner.nextInt(); - - - // RMI if (networkType == 0) { // Connect @@ -36,17 +49,10 @@ public class ClientLauncherTUI { return; } controller.setClient(client); - - // Play - //while(controller.localController.getModel()==null){ - // scanner.nextInt(); - //} - while(true) { + while (true) { getInput(scanner, controller, username); } - - - // TCP + // TCP } else if (networkType == 1) { // Connect TCPClient client = new TCPClient(controller, "localhost", 8080); @@ -57,33 +63,53 @@ public class ClientLauncherTUI { return; } controller.setClient(client); - // Play - while(true) { + while (true) { getInput(scanner, controller, username); } } - scanner.close(); } - - + /** + * Reads a single action from the user and dispatches it to the controller. + * The action is identified by a string code. Most actions also require a position index + * (e.g. the index of the card to draw from a list), which is read as a second input. + * Actions that do not require a position (7, 8, 9, A, B, C) skip the position prompt. + *
+ * Available actions: + *