diff --git a/src/main/java/it/polimi/ingsw/gc14/LimitedList.java b/src/main/java/it/polimi/ingsw/gc14/LimitedList.java new file mode 100644 index 0000000..fb582c3 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/LimitedList.java @@ -0,0 +1,26 @@ +package it.polimi.ingsw.gc14; + +import java.util.ArrayList; + +public class LimitedList extends ArrayList { + private int limit; + private final Runnable action; + + public LimitedList(int limit, Runnable action) { + this.limit = limit; + this.action = action; + } + + @Override + public boolean add(Player element) { + boolean result = super.add(element); + if (size() >= limit) { + action.run(); + } + return result; + } + + public void setElement(int num) { + this.limit=num; + } +} \ 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 36b57bc..2761ab8 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java +++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java @@ -17,6 +17,7 @@ public class ServerLauncher { GameController gameController; RMIServer serverRMI; TCPServer serverTCP; + LimitedList players; @@ -25,6 +26,16 @@ public class ServerLauncher { this.serverRMI = serverRMI; this.gameController = gameController; this.serverTCP = serverTCP; + this.players = new LimitedList<>(5, ()->{ + synchronized (gameController) { + try { + serverRMI.notifyAll(gameController.getModel()); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } + + }); } public boolean doFirstEven() throws InterruptedException, RemoteException { @@ -59,21 +70,6 @@ public class ServerLauncher { 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