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; public class ClientLauncherTUI { //TODO Javadoc TUI view; 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(); view.setUsername(username); System.out.println("Selezionare numero di giocatori desiderato: "); int proposedNumPlayers = scanner.nextInt(); System.out.println("Selezionare RMI[0] o TCP[1]: "); int networkType = scanner.nextInt(); // RMI if (networkType == 0) { // Connect RMIClient client = new RMIClient(controller, "localhost", 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); // Play //while(controller.localController.getModel()==null){ // scanner.nextInt(); //} while(true) { getInput(scanner, controller, username); } // TCP } else if (networkType == 1) { // Connect TCPClient client = new TCPClient(controller, "localhost", 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(); } private void getInput(Scanner scanner, ClientController controller, String username) { String action = scanner.next(); int pos=-1; if(!action.equals("7")&&!action.equals("8")&&!action.equals("9")&&!action.equals("A")&&!action.equals("B")&&!action.equals("C")) { try { System.out.println("Insert the required position:"); pos = scanner.nextInt(); } catch(Exception e) { System.out.println("ERROR: Invalid input(expected number)"); } } switch(action) { case "0" -> controller.slotChoice(username, pos); case "1" -> controller.drawUpperTribeCard(username, pos); case "2" -> controller.drawUpperBuildingCard(username, pos); case "3" -> controller.drawLowerTribeCard(username, pos); case "4" -> controller.drawLowerBuildingCard(username, pos); case "5" -> controller.pickOptionalTribeCard(username, pos); case "6" -> controller.pickOptionalBuildingCard(username, pos); case "7" -> controller.noOptionalCard(username); case "8" -> controller.skipUpper(username); case "9" -> controller.skipLower(username); case "A" -> view.fullRender(); case "B" -> view.renderBoard(); case "C" -> view.renderPlayer(); } return; } }