Merge branch 'main' into javadoc-fixes

This commit is contained in:
rubenpirreram
2026-04-30 20:11:10 +02:00
committed by GitHub
19 changed files with 1541 additions and 509 deletions
@@ -1,53 +1,85 @@
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.View.IView;
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
public void main() throws InterruptedException {
ClientController controller = new ClientController();
TUI 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();
System.out.println(username);
System.out.println("Selezionare numero di giocatori desiderato: ");
int proposedNumPlayers = scanner.nextInt();
System.out.println(proposedNumPlayers);
System.out.println("Selezionare RMI[0] o TCP[1]: ");
int networkType = scanner.nextInt();
System.out.println(networkType);
scanner.close();
// RMI
if (networkType == 0) {
RMIClient client = new RMIClient("localhost", 1099);
if (client.connect(username, proposedNumPlayers, controller)) {
// 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) {
System.out.flush();
if (controller.localModel!=null) {
break;
}
Thread.sleep(500);
getInput(scanner, controller, username);
}
System.out.println("Model set\n\n");
// TCP
} else if (networkType == 1) {
return;
// 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) {
int action = scanner.nextInt();
int pos = scanner.nextInt();
switch(action) {
case 1 -> controller.drawLowerBuildingCard(username, pos);
case 2 -> controller.drawLowerTribeCard(username, pos);
case 3 -> controller.drawUpperBuildingCard(username, pos);
case 4 -> controller.drawUpperTribeCard(username, pos);
case 5 -> controller.pickOptionalBuildingCard(username, pos);
case 6 -> controller.slotChoice(username, pos);
}
return;
}
}