Client Launcher TUI input handler added
This commit is contained in:
@@ -1,32 +1,30 @@
|
|||||||
package it.polimi.ingsw.gc14;
|
package it.polimi.ingsw.gc14;
|
||||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
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.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.IView;
|
|
||||||
import it.polimi.ingsw.gc14.View.TUI.TUI;
|
import it.polimi.ingsw.gc14.View.TUI.TUI;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class ClientLauncherTUI {
|
public class ClientLauncherTUI {
|
||||||
private TUI view;
|
|
||||||
public void main() throws InterruptedException {
|
public void main() throws InterruptedException {
|
||||||
view=new TUI(null);
|
TUI 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();
|
||||||
|
|
||||||
System.out.println("Selezionare numero di giocatori desiderato: ");
|
System.out.println("Selezionare numero di giocatori desiderato: ");
|
||||||
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
|
||||||
if (networkType == 0) {
|
if (networkType == 0) {
|
||||||
|
// Connect
|
||||||
RMIClient client = new RMIClient(controller, "localhost", 1099);
|
RMIClient client = new RMIClient(controller, "localhost", 1099);
|
||||||
if (client.connect(username, proposedNumPlayers)) {
|
if (client.connect(username, proposedNumPlayers)) {
|
||||||
System.out.println("Succesfully connected to RMI server\n\n");
|
System.out.println("Succesfully connected to RMI server\n\n");
|
||||||
@@ -35,21 +33,19 @@ public class ClientLauncherTUI {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.setClient(client);
|
controller.setClient(client);
|
||||||
int h;
|
|
||||||
while(controller.localController.getModel()==null){
|
// Play
|
||||||
h = scanner.nextInt();
|
//while(controller.localController.getModel()==null){
|
||||||
if(controller.localController.getModel()!=null)
|
// scanner.nextInt();
|
||||||
{
|
//}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(true) {
|
while(true) {
|
||||||
h = scanner.nextInt();
|
getInput(scanner, controller, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TCP
|
||||||
} else if (networkType == 1) {
|
} else if (networkType == 1) {
|
||||||
|
// Connect
|
||||||
TCPClient client = new TCPClient(controller, "localhost", 8080);
|
TCPClient client = new TCPClient(controller, "localhost", 8080);
|
||||||
if (client.connect(username, proposedNumPlayers)) {
|
if (client.connect(username, proposedNumPlayers)) {
|
||||||
System.out.println("Succesfully connected to TCP server\n\n");
|
System.out.println("Succesfully connected to TCP server\n\n");
|
||||||
@@ -58,11 +54,31 @@ public class ClientLauncherTUI {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.setClient(client);
|
controller.setClient(client);
|
||||||
|
|
||||||
|
// Play
|
||||||
while(true) {
|
while(true) {
|
||||||
int h = scanner.nextInt();
|
getInput(scanner, controller, username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner.close();
|
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 ───────────────────────────────────────
|
// ── punto di ingresso ───────────────────────────────────────
|
||||||
public void render()
|
public void render()
|
||||||
{
|
{
|
||||||
this.model=model;
|
|
||||||
try{
|
try{
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
ProcessBuilder pb;
|
ProcessBuilder pb;
|
||||||
|
|||||||
Reference in New Issue
Block a user