Merge pull request #74 from rubenpirreram/javadoc-fixes

Javadoc fixes
This commit is contained in:
rubenpirreram
2026-05-02 19:29:47 +02:00
committed by GitHub
4 changed files with 170 additions and 57 deletions
@@ -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.
* <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) {
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
{
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)
{
} catch (Exception e) {
System.out.println("ERROR: Invalid input(expected number)");
}
}
switch(action) {
switch (action) {
case "0" -> controller.slotChoice(username, pos);
case "1" -> controller.drawUpperTribeCard(username, pos);
case "2" -> controller.drawUpperBuildingCard(username, pos);
@@ -97,8 +123,7 @@ public class ClientLauncherTUI {
case "A" -> view.fullRender();
case "B" -> view.renderBoard();
case "C" -> view.renderPlayer();
default -> {}
}
return;
}
}