Add: LimitedList
This commit is contained in:
@@ -2,7 +2,7 @@ package it.polimi.ingsw.gc14;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LimitedList<Player> extends ArrayList<Player> {
|
||||
public class LimitedList<String> extends ArrayList<String> {
|
||||
private int limit;
|
||||
private final Runnable action;
|
||||
|
||||
@@ -12,7 +12,7 @@ public class LimitedList<Player> extends ArrayList<Player> {
|
||||
}
|
||||
|
||||
@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<Player> extends ArrayList<Player> {
|
||||
public void setElement(int num) {
|
||||
this.limit=num;
|
||||
}
|
||||
|
||||
public int getLimit(){return limit;}
|
||||
}
|
||||
@@ -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());
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user