Client Launcher TUI input handler added
This commit is contained in:
@@ -1,32 +1,30 @@
|
||||
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.IView;
|
||||
import it.polimi.ingsw.gc14.View.TUI.TUI;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ClientLauncherTUI {
|
||||
private TUI view;
|
||||
public void main() throws InterruptedException {
|
||||
view=new TUI(null);
|
||||
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("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");
|
||||
@@ -35,21 +33,19 @@ public class ClientLauncherTUI {
|
||||
return;
|
||||
}
|
||||
controller.setClient(client);
|
||||
int h;
|
||||
while(controller.localController.getModel()==null){
|
||||
h = scanner.nextInt();
|
||||
if(controller.localController.getModel()!=null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Play
|
||||
//while(controller.localController.getModel()==null){
|
||||
// scanner.nextInt();
|
||||
//}
|
||||
while(true) {
|
||||
h = scanner.nextInt();
|
||||
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");
|
||||
@@ -58,11 +54,31 @@ public class ClientLauncherTUI {
|
||||
return;
|
||||
}
|
||||
controller.setClient(client);
|
||||
|
||||
// Play
|
||||
while(true) {
|
||||
int h = scanner.nextInt();
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ public class TUI implements IView, Observer {
|
||||
// ── punto di ingresso ───────────────────────────────────────
|
||||
public void render()
|
||||
{
|
||||
this.model=model;
|
||||
try{
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
ProcessBuilder pb;
|
||||
|
||||
Reference in New Issue
Block a user