Add: JavaDOC to ClientLauncherTUI
This commit is contained in:
@@ -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.RMI.Client.RMIClient;
|
||||||
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
|
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
|
||||||
import it.polimi.ingsw.gc14.View.TUI.TUI;
|
import it.polimi.ingsw.gc14.View.TUI.TUI;
|
||||||
|
|
||||||
import java.util.Scanner;
|
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 {
|
public class ClientLauncherTUI {
|
||||||
//TODO Javadoc
|
|
||||||
|
/**
|
||||||
|
* The TUI view associated with this client.
|
||||||
|
*/
|
||||||
TUI view;
|
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 {
|
public void main() throws InterruptedException {
|
||||||
view = new TUI(null);
|
view = new TUI(null);
|
||||||
ClientController controller = new ClientController(view);
|
ClientController controller = new ClientController(view);
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
System.out.println("Selezionare nome utente: ");
|
System.out.println("Selezionare nome utente: ");
|
||||||
String username = scanner.next();
|
String username = scanner.next();
|
||||||
@@ -22,9 +38,6 @@ public class ClientLauncherTUI {
|
|||||||
int proposedNumPlayers = scanner.nextInt();
|
int proposedNumPlayers = scanner.nextInt();
|
||||||
System.out.println("Selezionare RMI[0] o TCP[1]: ");
|
System.out.println("Selezionare RMI[0] o TCP[1]: ");
|
||||||
int networkType = scanner.nextInt();
|
int networkType = scanner.nextInt();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// RMI
|
// RMI
|
||||||
if (networkType == 0) {
|
if (networkType == 0) {
|
||||||
// Connect
|
// Connect
|
||||||
@@ -36,16 +49,9 @@ public class ClientLauncherTUI {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.setClient(client);
|
controller.setClient(client);
|
||||||
|
|
||||||
// Play
|
|
||||||
//while(controller.localController.getModel()==null){
|
|
||||||
// scanner.nextInt();
|
|
||||||
//}
|
|
||||||
while (true) {
|
while (true) {
|
||||||
getInput(scanner, controller, username);
|
getInput(scanner, controller, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TCP
|
// TCP
|
||||||
} else if (networkType == 1) {
|
} else if (networkType == 1) {
|
||||||
// Connect
|
// Connect
|
||||||
@@ -57,29 +63,49 @@ public class ClientLauncherTUI {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.setClient(client);
|
controller.setClient(client);
|
||||||
|
|
||||||
// Play
|
// Play
|
||||||
while (true) {
|
while (true) {
|
||||||
getInput(scanner, controller, username);
|
getInput(scanner, controller, username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner.close();
|
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.
|
||||||
|
* <p>
|
||||||
|
* Available actions:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@code 0} - Choose a slot by index.</li>
|
||||||
|
* <li>{@code 1} - Draw an upper building card by index.</li>
|
||||||
|
* <li>{@code 2} - Draw an upper tribe card by index.</li>
|
||||||
|
* <li>{@code 3} - Draw a lower building card by index.</li>
|
||||||
|
* <li>{@code 4} - Draw a lower tribe card by index.</li>
|
||||||
|
* <li>{@code 5} - Pick an optional tribe card by index.</li>
|
||||||
|
* <li>{@code 6} - Pick an optional building card by index.</li>
|
||||||
|
* <li>{@code 7} - Skip the optional card choice.</li>
|
||||||
|
* <li>{@code 8} - Skip the upper draw.</li>
|
||||||
|
* <li>{@code 9} - Skip the lower draw.</li>
|
||||||
|
* <li>{@code A} - Render the full game view.</li>
|
||||||
|
* <li>{@code B} - Render the board view.</li>
|
||||||
|
* <li>{@code C} - Render the player view.</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param scanner the scanner used to read user input.
|
||||||
|
* @param controller the client controller to which actions are dispatched.
|
||||||
|
* @param username the username of the current player.
|
||||||
|
*/
|
||||||
private void getInput(Scanner scanner, ClientController controller, String username) {
|
private void getInput(Scanner scanner, ClientController controller, String username) {
|
||||||
String action = scanner.next();
|
String action = scanner.next();
|
||||||
int pos = -1;
|
int pos = -1;
|
||||||
if (!action.equals("7") && !action.equals("8") && !action.equals("9") && !action.equals("A") && !action.equals("B") && !action.equals("C")) {
|
if (!action.equals("7") && !action.equals("8") && !action.equals("9") && !action.equals("A") && !action.equals("B") && !action.equals("C")) {
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
System.out.println("Insert the required position:");
|
System.out.println("Insert the required position:");
|
||||||
pos = scanner.nextInt();
|
pos = scanner.nextInt();
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("ERROR: Invalid input(expected number)");
|
System.out.println("ERROR: Invalid input(expected number)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,8 +123,7 @@ public class ClientLauncherTUI {
|
|||||||
case "A" -> view.fullRender();
|
case "A" -> view.fullRender();
|
||||||
case "B" -> view.renderBoard();
|
case "B" -> view.renderBoard();
|
||||||
case "C" -> view.renderPlayer();
|
case "C" -> view.renderPlayer();
|
||||||
}
|
default -> {}
|
||||||
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ public class RMIClient implements IClient {
|
|||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Javadoc fix
|
|
||||||
/**
|
/**
|
||||||
* Connects to the RMI server and attempts to join the game.
|
* Connects to the RMI server and attempts to join the game.
|
||||||
* Looks up the RMI registry to retrieve the {@link IGameServer} stub.
|
* Looks up the RMI registry to retrieve the {@link IGameServer} stub.
|
||||||
|
|||||||
Reference in New Issue
Block a user