diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncher.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncher.java new file mode 100644 index 0000000..fd8a3f8 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncher.java @@ -0,0 +1,28 @@ +package it.polimi.ingsw.gc14; +import java.util.Scanner; + +public class ClientLauncher { + public void main() { + 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(); // chiudi solo alla fine + + if (networkType == 0) { + return; + } else if (networkType == 1) { + return; + } + } +} \ No newline at end of file diff --git a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java index b3c14d7..36b57bc 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java +++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java @@ -4,6 +4,7 @@ package it.polimi.ingsw.gc14; import it.polimi.ingsw.gc14.Controller.GameController; import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Network.NetworkEvent; +import it.polimi.ingsw.gc14.Network.NetworkEvents.AddPlayer; import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer; import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer; @@ -26,7 +27,7 @@ public class ServerLauncher { this.serverTCP = serverTCP; } - public boolean doFirstEvent() throws InterruptedException, RemoteException { + public boolean doFirstEven() throws InterruptedException, RemoteException { NetworkEvent event = actionQueue.take(); if(event.apply(gameController)) { serverRMI.notifyAll(event); @@ -40,24 +41,45 @@ public class ServerLauncher { } - public static void main() throws RemoteException { + public static void main() throws RemoteException, InterruptedException { + // TODO + // Deve avere una coda con gli eventi. + // Il server RMI e il server TCP quando ricevono un doEvent devono aggiungere l'evento alla coda condivisa + // Questa classe esegue gli eventi nella coda e chiama il notify all e notify error sia RMI che TCP + BlockingQueue actionQueue = new LinkedBlockingQueue<>(); - Game model = new Game(); - GameController gameController = new GameController(model); + GameController gameController = new GameController(); RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue); TCPServer serverTCP = new TCPServer(gameController, 8080, actionQueue); - serverRMI.start(); - new Thread (()->{serverTCP.start();}).start(); - ServerLauncher launcher = new ServerLauncher(actionQueue, gameController, serverRMI, serverTCP); launcher.run(); } - public void run() { + public void run() throws InterruptedException, RemoteException { + + // Aggiunge il primo player e imposta il numero di giocatori voluti + AddPlayer player1 = (AddPlayer) actionQueue.take(); + Game model = new Game(player1.getProposedNPlayer()); + gameController.setModel(model); + player1.apply(gameController); + + for(int i=1; i