package it.polimi.ingsw.gc14; import it.polimi.ingsw.gc14.Controller.ClientController; 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 { /** * 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("Insert username: "); String username = scanner.next(); view.setUsername(username); System.out.println("Insert preferred number of players: "); int proposedNumPlayers = scanner.nextInt(); System.out.println("Select RMI[0] o TCP[1]: "); int networkType = scanner.nextInt(); System.out.println("Insert server IP: "); String IP = scanner.next(); // RMI if (networkType == 0) { // Connect RMIClient client = new RMIClient(controller, IP, 1099); if (client.connect(username, proposedNumPlayers)) { System.out.println("Succesfully connected to RMI server\n\n"); } else { System.out.println("RMI connection refused\n\n"); return; } controller.setClient(client); while (true) { getInput(scanner, controller, username); } // TCP } else if (networkType == 1) { // Connect TCPClient client = new TCPClient(controller, IP, 8080); if (client.connect(username, proposedNumPlayers)) { System.out.println("Succesfully connected to TCP server\n\n"); } else { System.out.println("TCP connection refused\n\n"); return; } controller.setClient(client); // Play 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: *