diff --git a/src/main/java/it/polimi/ingsw/gc14/LimitedList.java b/src/main/java/it/polimi/ingsw/gc14/LimitedList.java index fb582c3..0bb1d66 100644 --- a/src/main/java/it/polimi/ingsw/gc14/LimitedList.java +++ b/src/main/java/it/polimi/ingsw/gc14/LimitedList.java @@ -2,7 +2,7 @@ package it.polimi.ingsw.gc14; import java.util.ArrayList; -public class LimitedList extends ArrayList { +public class LimitedList extends ArrayList { private int limit; private final Runnable action; @@ -12,7 +12,7 @@ public class LimitedList extends ArrayList { } @Override - public boolean add(Player element) { + public boolean add(String element) { boolean result = super.add(element); if (size() >= limit) { action.run(); @@ -23,4 +23,6 @@ public class LimitedList extends ArrayList { public void setElement(int num) { this.limit=num; } + + public int getLimit(){return limit;} } \ 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 2761ab8..6db75a5 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java +++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java @@ -27,14 +27,13 @@ public class ServerLauncher { 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); - } + try { + run(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (RemoteException e) { + throw new RuntimeException(e); } - }); } @@ -70,7 +69,10 @@ public class ServerLauncher { public void run() throws InterruptedException, RemoteException { // Aggiunge il primo player e imposta il numero di giocatori voluti - + Game model = new Game(players.getLimit()); + gameController.setModel(model); + serverRMI.notifyAll(model); + //serverTCP.broadcastUpdate(model); while (true) {