Fix: full model refactor

This commit is contained in:
2026-06-14 12:28:53 +02:00
parent 9a931bfc1b
commit 85f2dd9208
24 changed files with 311 additions and 253 deletions
@@ -349,7 +349,7 @@ public class GameEventProcessor {
* @return a new {@link ArrayList} of disconnected usernames. * @return a new {@link ArrayList} of disconnected usernames.
*/ */
private ArrayList<String> buildDisconnectedList(Game game) { private ArrayList<String> buildDisconnectedList(Game game) {
return game.disconnectedPlayers.entrySet().stream() return game.getDisconnectedPlayers().entrySet().stream()
.filter(Map.Entry::getValue) .filter(Map.Entry::getValue)
.map(e -> e.getKey().getUserName()) .map(e -> e.getKey().getUserName())
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
@@ -53,7 +53,7 @@ public class DecksCreator {
InputStream is = DecksCreator.class.getResourceAsStream(resourcePath); InputStream is = DecksCreator.class.getResourceAsStream(resourcePath);
if (is == null) { if (is == null) {
throw new RuntimeException("File non trovato: " + resourcePath); throw new RuntimeException("Resource file not found: " + resourcePath);
} }
try (Reader reader = new InputStreamReader(is)) { try (Reader reader = new InputStreamReader(is)) {
@@ -64,7 +64,7 @@ public class DecksCreator {
} }
return cards; return cards;
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Errore caricamento mazzo: " + resourcePath, e); throw new RuntimeException("Error loading deck: " + resourcePath, e);
} }
} }
@@ -94,7 +94,7 @@ public class DecksCreator {
InputStream is = DecksCreator.class.getResourceAsStream(resourcePath); InputStream is = DecksCreator.class.getResourceAsStream(resourcePath);
if (is == null) { if (is == null) {
throw new RuntimeException("File non trovato: " + resourcePath); throw new RuntimeException("Resource file not found: " + resourcePath);
} }
try (Reader reader = new InputStreamReader(is)) { try (Reader reader = new InputStreamReader(is)) {
@@ -105,7 +105,7 @@ public class DecksCreator {
} }
return cards; return cards;
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Errore caricamento mazzo: " + resourcePath, e); throw new RuntimeException("Error loading deck: " + resourcePath, e);
} }
} }
@@ -143,7 +143,7 @@ public class DecksCreator {
case "Hunt" -> new Hunt(def.id,era,p[0]); case "Hunt" -> new Hunt(def.id,era,p[0]);
case "CavePaintings" -> new CavePaintings(def.id,era,p[0],p[1],p[2]); case "CavePaintings" -> new CavePaintings(def.id,era,p[0],p[1],p[2]);
case "ShamanicRitual" -> new ShamanicRitual(def.id,era,p[0],p[1]); case "ShamanicRitual" -> new ShamanicRitual(def.id,era,p[0],p[1]);
default -> throw new IllegalArgumentException("Tipo sconosciuto: " + def.type); default -> throw new IllegalArgumentException("Unknown event type: " + def.type);
}; };
} }
return switch (def.type) { return switch (def.type) {
@@ -153,29 +153,29 @@ public class DecksCreator {
case "Builder" -> switch (p.length) { case "Builder" -> switch (p.length) {
case 2 -> new Builder(def.id,era, p[0], p[1]); case 2 -> new Builder(def.id,era, p[0], p[1]);
case 3 -> new Builder(def.id,era, p[0], p[1], p[2]); case 3 -> new Builder(def.id,era, p[0], p[1], p[2]);
default -> throw new IllegalArgumentException("Builder: parametri non validi"); default -> throw new IllegalArgumentException("Builder: invalid parameters");
}; };
case "Gatherer" -> switch (p.length) { case "Gatherer" -> switch (p.length) {
case 0 -> new Gatherer(def.id,era); case 0 -> new Gatherer(def.id,era);
case 1 -> new Gatherer(def.id,era, p[0]); case 1 -> new Gatherer(def.id,era, p[0]);
default -> throw new IllegalArgumentException("Gatherer: parametri non validi"); default -> throw new IllegalArgumentException("Gatherer: invalid parameters");
}; };
case "Artist" -> switch (p.length) { case "Artist" -> switch (p.length) {
case 0 -> new Artist(def.id,era); case 0 -> new Artist(def.id,era);
case 1 -> new Artist(def.id,era, p[0]); case 1 -> new Artist(def.id,era, p[0]);
default -> throw new IllegalArgumentException("Artist: parametri non validi"); default -> throw new IllegalArgumentException("Artist: invalid parameters");
}; };
case "Inventor" -> switch (p.length) { case "Inventor" -> switch (p.length) {
case 1 -> new Inventor(def.id,era, p[0]); case 1 -> new Inventor(def.id,era, p[0]);
case 2 -> new Inventor(def.id,era, p[0], p[1]); case 2 -> new Inventor(def.id,era, p[0], p[1]);
default -> throw new IllegalArgumentException("Inventor: parametri non validi"); default -> throw new IllegalArgumentException("Inventor: invalid parameters");
}; };
case "Shaman" -> switch (p.length) { case "Shaman" -> switch (p.length) {
case 1 -> new Shaman(def.id,era, p[0]); case 1 -> new Shaman(def.id,era, p[0]);
case 2 -> new Shaman(def.id,era, p[0], p[1]); case 2 -> new Shaman(def.id,era, p[0], p[1]);
default -> throw new IllegalArgumentException("Shaman: parametri non validi"); default -> throw new IllegalArgumentException("Shaman: invalid parameters");
}; };
default -> throw new IllegalArgumentException("Tipo sconosciuto: " + def.type); default -> throw new IllegalArgumentException("Unknown card type: " + def.type);
}; };
} }
@@ -212,7 +212,7 @@ public class DecksCreator {
int era; int era;
boolean armed; boolean armed;
boolean isEvent; boolean isEvent;
List<Object> params; // Object per gestire boolean e int misti List<Object> params; // Object to support mixed boolean and numeric parameters from JSON
} }
/** /**
@@ -225,6 +225,6 @@ public class DecksCreator {
int era; int era;
int price; int price;
int prestigeValue; int prestigeValue;
List<Object> params; // Object per gestire boolean e int misti List<Object> params; // Object to support mixed boolean and numeric parameters from JSON
} }
} }
@@ -84,7 +84,7 @@ public class Game implements Serializable {
* @return {@code true} if the choice is applied successfully, {@code false} otherwise. * @return {@code true} if the choice is applied successfully, {@code false} otherwise.
*/ */
public synchronized boolean totemChoice(Player player,Totems totem) { public synchronized boolean totemChoice(Player player,Totems totem) {
if(!currentState.getGameStage().equals(GameStages.TOTEM_CHOICE)) if(currentState.getGameStage() != GameStages.TOTEM_CHOICE)
return false; return false;
if(!getCurrentState().getCurrentPlayer().equals(player)) if(!getCurrentState().getCurrentPlayer().equals(player))
return false; return false;
@@ -120,8 +120,18 @@ public class Game implements Serializable {
/** /**
* Map tracking the players who are currently disconnected. * Map tracking the players who are currently disconnected.
* Key: player; value: {@code true} if currently disconnected, {@code false} if reconnected.
*/ */
public Map<Player,Boolean> disconnectedPlayers = new HashMap<>(); private Map<Player,Boolean> disconnectedPlayers = new HashMap<>();
/**
* Returns an unmodifiable view of the disconnected-players map.
*
* @return map from player to disconnection status.
*/
public Map<Player,Boolean> getDisconnectedPlayers() {
return Collections.unmodifiableMap(disconnectedPlayers);
}
/** /**
* Marks the specified player as disconnected and updates the game flow accordingly. * Marks the specified player as disconnected and updates the game flow accordingly.
@@ -142,13 +152,13 @@ public class Game implements Serializable {
return false; return false;
} }
disconnectedPlayers.put(player,true); disconnectedPlayers.put(player,true);
if (currentState.getGameStage().equals(GameStages.WAITING)) { if (currentState.getGameStage() == GameStages.WAITING) {
playersList.remove(player); playersList.remove(player);
totemChoiceQueue.remove(player); totemChoiceQueue.remove(player);
return true; return true;
} }
if(currentState.getCurrentPlayer().equals(player)) { if(currentState.getCurrentPlayer().equals(player)) {
if (!currentState.getGameStage().equals(GameStages.TOTEM_CHOICE)) { if (currentState.getGameStage() != GameStages.TOTEM_CHOICE) {
nextPlayerSetup(); nextPlayerSetup();
return true; return true;
} }
@@ -184,15 +194,15 @@ public class Game implements Serializable {
return false; return false;
} }
disconnectedPlayers.put(player,false); disconnectedPlayers.put(player,false);
if(currentState.getGameStage().equals(GameStages.SLOT_CHOICE) ) if(currentState.getGameStage() == GameStages.SLOT_CHOICE)
{ {
disconnectedPlayers.remove(player); disconnectedPlayers.remove(player);
if(!orderLogicCard.players.contains(player)) if(!orderLogicCard.containsInQueue(player))
{ {
orderLogicCard.pushNoEffect(player); orderLogicCard.pushNoEffect(player);
} }
} }
else if(currentState.getGameStage().equals(GameStages.RES_ACTIONS)) { else if(currentState.getGameStage() == GameStages.RES_ACTIONS) {
if(slotMap.containsValue(player)) if(slotMap.containsValue(player))
{ {
disconnectedPlayers.remove(player); disconnectedPlayers.remove(player);
@@ -247,7 +257,7 @@ public class Game implements Serializable {
/** /**
* The queue of players involved in optional card resolution. * The queue of players involved in optional card resolution.
*/ */
private Queue<Player> OptionalCardQueue; private Queue<Player> optionalCardQueue;
/** /**
* The order logic card associated with this game. * The order logic card associated with this game.
@@ -274,39 +284,39 @@ public class Game implements Serializable {
public Board getBoard() {return board;} public Board getBoard() {return board;}
/** /**
* Returns clones of the upper tribe cards currently available on the board. * Returns a copy of the upper tribe cards currently available on the board.
* *
* @return a list containing clones of the upper tribe cards currently available on the board. * @return a new list containing the upper tribe cards currently on the board.
*/ */
public ArrayList<TribeCard>getUpperListTribeCards() { public ArrayList<TribeCard> getUpperListTribeCards() {
return (ArrayList<TribeCard>)board.upperListTribe; return new ArrayList<>(board.getUpperListTribe());
} }
/** /**
* Returns clones of the lower tribe cards currently available on the board. * Returns a copy of the lower tribe cards currently available on the board.
* *
* @return a list containing clones of the lower tribe cards currently available on the board. * @return a new list containing the lower tribe cards currently on the board.
*/ */
public ArrayList<TribeCard>getLowerListTribeCards() { public ArrayList<TribeCard> getLowerListTribeCards() {
return (ArrayList<TribeCard> )board.lowerListTribe; return new ArrayList<>(board.getLowerListTribe());
} }
/** /**
* Returns clones of the upper building cards currently available on the board. * Returns a copy of the upper building cards currently available on the board.
* *
* @return a list containing clones of the upper building cards currently available on the board. * @return a new list containing the upper building cards currently on the board.
*/ */
public ArrayList<BuildingCard>getUpperListBuilding() { public ArrayList<BuildingCard> getUpperListBuilding() {
return (ArrayList<BuildingCard>)board.upperListBuilding; return new ArrayList<>(board.getUpperListBuilding());
} }
/** /**
* Returns clones of the lower building cards currently available on the board. * Returns a copy of the lower building cards currently available on the board.
* *
* @return a list containing clones of the lower building cards currently available on the board. * @return a new list containing the lower building cards currently on the board.
*/ */
public ArrayList<BuildingCard>getLowerListBuilding() { public ArrayList<BuildingCard> getLowerListBuilding() {
return (ArrayList<BuildingCard>) board.lowerListBuilding; return new ArrayList<>(board.getLowerListBuilding());
} }
/** /**
@@ -316,7 +326,7 @@ public class Game implements Serializable {
*/ */
public CurrentState getCurrentState() { public CurrentState getCurrentState() {
return currentState; return currentState;
}; }
/** /**
* Returns the player with the specified username, if present. * Returns the player with the specified username, if present.
@@ -357,7 +367,7 @@ public class Game implements Serializable {
} }
currentState= new CurrentState(); currentState= new CurrentState();
playersList = new ArrayList<>(); playersList = new ArrayList<>();
OptionalCardQueue = new LinkedList<>(); optionalCardQueue = new LinkedList<>();
} }
/** /**
@@ -482,7 +492,7 @@ public class Game implements Serializable {
* @return {@code true} if the draw succeeds, {@code false} otherwise. * @return {@code true} if the draw succeeds, {@code false} otherwise.
*/ */
public boolean drawUpperTribeCardByIndex(Player player,int cardIndex) { public boolean drawUpperTribeCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListTribe.size()) if( cardIndex<0 || cardIndex >=board.getUpperListTribe().size())
return false; return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E) if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
{ {
@@ -494,7 +504,7 @@ public class Game implements Serializable {
} }
if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS) if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
return false; return false;
TribeCard tribeCard = board.upperListTribe.get(cardIndex); TribeCard tribeCard = board.getUpperListTribe().get(cardIndex);
if(tribeCard.isEventCard()) if(tribeCard.isEventCard())
return false; return false;
@@ -525,7 +535,7 @@ public class Game implements Serializable {
* @return {@code true} if the skip succeeds, {@code false} otherwise. * @return {@code true} if the skip succeeds, {@code false} otherwise.
*/ */
public boolean skipTurn(Player player) { public boolean skipTurn(Player player) {
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && !currentState.getGameStage().equals(GameStages.OPT_CARD_E)) if(currentState.getGameStage() != GameStages.RES_ACTIONS && currentState.getGameStage() != GameStages.OPT_CARD_E)
{ {
return false; return false;
} }
@@ -565,7 +575,7 @@ public class Game implements Serializable {
* @return {@code true} if the draw succeeds, {@code false} otherwise. * @return {@code true} if the draw succeeds, {@code false} otherwise.
*/ */
public boolean drawLowerTribeCardByIndex(Player player, int cardIndex) { public boolean drawLowerTribeCardByIndex(Player player, int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListTribe.size()) if( cardIndex<0 || cardIndex >=board.getLowerListTribe().size())
return false; return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS) if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{ {
@@ -579,7 +589,7 @@ public class Game implements Serializable {
if(currentState.getNLower() <1) if(currentState.getNLower() <1)
return false; return false;
TribeCard tribeCard = board.lowerListTribe.get(cardIndex); TribeCard tribeCard = board.getLowerListTribe().get(cardIndex);
if(tribeCard.isEventCard()) if(tribeCard.isEventCard())
return false; return false;
@@ -606,7 +616,7 @@ public class Game implements Serializable {
* @return {@code true} if the draw succeeds, {@code false} otherwise. * @return {@code true} if the draw succeeds, {@code false} otherwise.
*/ */
public boolean drawUpperBuildingCardByIndex(Player player,int cardIndex) { public boolean drawUpperBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size()) if( cardIndex<0 || cardIndex >=board.getUpperListBuilding().size())
return false; return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E) if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
{ {
@@ -616,7 +626,7 @@ public class Game implements Serializable {
{ {
return false; return false;
} }
BuildingCard buildingCard = board.upperListBuilding.get(cardIndex); BuildingCard buildingCard = board.getUpperListBuilding().get(cardIndex);
if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS) if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
return false; return false;
if(!buildingCard.buy(player)) if(!buildingCard.buy(player))
@@ -624,7 +634,7 @@ public class Game implements Serializable {
return false; return false;
} }
board.removeUpperBuildingCard(buildingCard); board.removeUpperBuildingCard(buildingCard);
if(currentState.getGameStage().equals(GameStages.RES_ACTIONS)) if(currentState.getGameStage() == GameStages.RES_ACTIONS)
{ {
currentState.upperDrawn(); currentState.upperDrawn();
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty()))) if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
@@ -650,7 +660,7 @@ public class Game implements Serializable {
* @return {@code true} if the draw succeeds, {@code false} otherwise. * @return {@code true} if the draw succeeds, {@code false} otherwise.
*/ */
public boolean drawLowerBuildingCardByIndex(Player player,int cardIndex) { public boolean drawLowerBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListBuilding.size()) if( cardIndex<0 || cardIndex >=board.getLowerListBuilding().size())
return false; return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS) if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{ {
@@ -661,7 +671,7 @@ public class Game implements Serializable {
{ {
return false; return false;
} }
BuildingCard buildingCard = board.lowerListBuilding.get(cardIndex); BuildingCard buildingCard = board.getLowerListBuilding().get(cardIndex);
if(currentState.getNLower() <1) if(currentState.getNLower() <1)
return false; return false;
if(buildingCard.buy(player)) if(buildingCard.buy(player))
@@ -788,7 +798,7 @@ public class Game implements Serializable {
} }
if (GameStages.OPT_CARD_E == currentState.getGameStage()) { if (GameStages.OPT_CARD_E == currentState.getGameStage()) {
Player optionalPlayer = OptionalCardQueue.poll(); Player optionalPlayer = optionalCardQueue.poll();
if (optionalPlayer != null) { if (optionalPlayer != null) {
currentState.playerUpdate(optionalPlayer, null); currentState.playerUpdate(optionalPlayer, null);
@@ -821,7 +831,7 @@ public class Game implements Serializable {
private synchronized void transitionToOptionalOrNextRound() { private synchronized void transitionToOptionalOrNextRound() {
currentState.gameStageUpdate(GameStages.OPT_CARD_E); currentState.gameStageUpdate(GameStages.OPT_CARD_E);
OptionalCardQueue = new LinkedList<>(); optionalCardQueue = new LinkedList<>();
for (Player p :playersList) { for (Player p :playersList) {
long count = p.getBuildingCards().stream().filter(x -> x.getEffectId() == 12).count(); long count = p.getBuildingCards().stream().filter(x -> x.getEffectId() == 12).count();
if (count > 0) { if (count > 0) {
@@ -829,11 +839,11 @@ public class Game implements Serializable {
{ {
continue; continue;
} }
OptionalCardQueue.add(p); optionalCardQueue.add(p);
} }
} }
Player optionalPlayer = OptionalCardQueue.poll(); Player optionalPlayer = optionalCardQueue.poll();
if (optionalPlayer != null) { if (optionalPlayer != null) {
currentState.playerUpdate(optionalPlayer, null); currentState.playerUpdate(optionalPlayer, null);
@@ -847,8 +857,7 @@ public class Game implements Serializable {
orderLogicCard.pushNoEffect(entry.getKey()); orderLogicCard.pushNoEffect(entry.getKey());
disconnectedPlayers.remove(entry.getKey()); disconnectedPlayers.remove(entry.getKey());
} else { } else {
orderLogicCard.players.removeIf(x -> x.equals(entry.getKey())); orderLogicCard.removeFromQueue(entry.getKey());
orderLogicCard.playerList.removeIf(x -> x.player.equals(entry.getKey()));
} }
} }
currentState.playerUpdate(orderLogicCard.pull(), null); currentState.playerUpdate(orderLogicCard.pull(), null);
@@ -927,7 +936,7 @@ public class Game implements Serializable {
*/ */
private void endGame() { private void endGame() {
Queue<EventCard> events; Queue<EventCard> events;
events=Stream.concat(board.lowerListTribe.stream().filter(TribeCard::isEventCard),board.upperListTribe.stream().filter(TribeCard::isEventCard)).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new)); events=Stream.concat(board.getLowerListTribe().stream().filter(TribeCard::isEventCard),board.getUpperListTribe().stream().filter(TribeCard::isEventCard)).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new));
ArrayList<EventCard>sustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new)); ArrayList<EventCard>sustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new));
events.removeAll(sustenance); events.removeAll(sustenance);
events.forEach(event->event.activateEvent(playersList)); events.forEach(event->event.activateEvent(playersList));
@@ -985,7 +994,7 @@ public class Game implements Serializable {
currentState = new CurrentState(); currentState = new CurrentState();
playersList = new ArrayList<>(); playersList = new ArrayList<>();
OptionalCardQueue = new LinkedList<>(); optionalCardQueue = new LinkedList<>();
return true; return true;
} }
@@ -29,20 +29,48 @@ public class Board implements Serializable {
* The upper row of tribe cards. It contains a total of * The upper row of tribe cards. It contains a total of
* {@code nTotem + 4} tribe cards, which may include both character and event cards. * {@code nTotem + 4} tribe cards, which may include both character and event cards.
*/ */
public List<TribeCard> upperListTribe; private List<TribeCard> upperListTribe;
/** /**
* The lower row of the tribe card. During the first round, there will be (num. of players + 1) character cards. * The lower row of the tribe card. During the first round, there will be (num. of players + 1) character cards.
* During the following rounds, lower row will be emptied and populated with upper row's cards. * During the following rounds, lower row will be emptied and populated with upper row's cards.
* When an Event card gets in the lower row, the event effect will be activated at the end of the round. * When an Event card gets in the lower row, the event effect will be activated at the end of the round.
*/ */
public List<TribeCard> lowerListTribe; private List<TribeCard> lowerListTribe;
/** Contains all the building cards of the upper list. When a new era starts, all its building cards are placed here */ /** Contains all the building cards of the upper list. When a new era starts, all its building cards are placed here. */
public List<BuildingCard> upperListBuilding; private List<BuildingCard> upperListBuilding;
/** Contains all the building cards of the lower list. When a new era starts, the old era's buildings are moved from the upper to the lower list */ /** Contains all the building cards of the lower list. When a new era starts, the old era's buildings are moved from the upper to the lower list. */
public List<BuildingCard> lowerListBuilding; private List<BuildingCard> lowerListBuilding;
/**
* Returns the upper row of tribe cards.
*
* @return the live upper tribe card list.
*/
public List<TribeCard> getUpperListTribe() { return upperListTribe; }
/**
* Returns the lower row of tribe cards.
*
* @return the live lower tribe card list.
*/
public List<TribeCard> getLowerListTribe() { return lowerListTribe; }
/**
* Returns the upper row of building cards.
*
* @return the live upper building card list.
*/
public List<BuildingCard> getUpperListBuilding() { return upperListBuilding; }
/**
* Returns the lower row of building cards.
*
* @return the live lower building card list.
*/
public List<BuildingCard> getLowerListBuilding() { return lowerListBuilding; }
private final ArrayList<List<BuildingCard>> buildingCardsAllEras; private final ArrayList<List<BuildingCard>> buildingCardsAllEras;
@@ -244,6 +272,7 @@ public class Board implements Serializable {
for(int i=0;i<nTotem+4;i++) for(int i=0;i<nTotem+4;i++)
{ {
if (tribeDeck.isEmpty()) break;
TribeCard tempCard = tribeDeck.remove(); TribeCard tempCard = tribeDeck.remove();
if(tempCard.getEra()!=era) if(tempCard.getEra()!=era)
{ {
@@ -151,10 +151,10 @@ public class CurrentState implements Serializable {
/** /**
* Updates the current game stage. * Updates the current game stage.
* *
* @param GameStage the new game stage. * @param stage the new game stage.
*/ */
public void gameStageUpdate(GameStages gameStage){ public void gameStageUpdate(GameStages stage){
this.gameStage = gameStage; this.gameStage = stage;
} }
// endregion setters // endregion setters
@@ -179,12 +179,12 @@ public class CurrentState implements Serializable {
// region Functions // region Functions
/** /**
* Updates the current player and slot. * Updates the current player, slot, and available draws.
* If the specified slot is {@code null}, the numbers of upper and lower cards are both set to 0. * If {@code slot} is {@code null}, both {@link #nUpper} and {@link #nLower} are reset to 0.
* Otherwise, the numbers of upper and lower cards are updated using the values of the specified slot. * Otherwise they are set from the slot's values.
* *
* @param player the new current player. * @param player the new current player.
* @param slot the new current slot. * @param slot the new current slot, or {@code null} when no slot is active.
*/ */
public void playerUpdate(Player player, Slot slot){ public void playerUpdate(Player player, Slot slot){
this.player = player; this.player = player;
@@ -36,7 +36,7 @@ public enum GameStages {
RES_EVENT("Event"), RES_EVENT("Event"),
/** /**
* Stage in which end-of-round or end-of-game operations are processed. * Stage in which end-of-game scoring and ranking are computed.
*/ */
ENDING("Ending"), ENDING("Ending"),
@@ -1,10 +0,0 @@
package it.polimi.ingsw.gc14.Model;
/** Standalone entry point used for local model testing. */
public class Main {
/** @param args unused. */
public static void main(String[] args) {
}
}
@@ -107,7 +107,7 @@ public class MiniModel implements Serializable {
this.slotPlayerMap = slotPlayerMap; this.slotPlayerMap = slotPlayerMap;
this.orderLogicCard = orderLogicCard; this.orderLogicCard = orderLogicCard;
this.currentState = currentState; this.currentState = currentState;
this.players = new HashMap<>(); this.players = new LinkedHashMap<>();
this.availableTotems = availableTotems; this.availableTotems = availableTotems;
this.standingPlayers = new ArrayList<>(); this.standingPlayers = new ArrayList<>();
this.upperListTribeCards = upperListTribeCards; this.upperListTribeCards = upperListTribeCards;
@@ -20,12 +20,22 @@ public abstract class OrderLogicCard implements Serializable {
/** /**
* The queue of {@link Player Players} associated with this order logic card. * The queue of {@link Player Players} associated with this order logic card.
*/ */
public Queue<Player> players; private Queue<Player> players;
/** /**
* The list of {@link Player Players} associated with this order logic card. * The list of {@link OrderPlayer} entries tracking turn order and played status.
* Protected so subclasses can read it for display purposes (e.g., {@link #toString()}).
*/ */
public List<OrderPlayer> playerList; protected List<OrderPlayer> playerList;
/**
* Returns an unmodifiable view of the player order list.
*
* @return the list of {@link OrderPlayer} entries in turn order.
*/
public List<OrderPlayer> getPlayerList() {
return Collections.unmodifiableList(playerList);
}
/** Total number of players in this game. */ /** Total number of players in this game. */
protected final int nPlayers; protected final int nPlayers;
@@ -33,15 +43,19 @@ public abstract class OrderLogicCard implements Serializable {
/** /**
* Creates an order logic card with the specified list of players. * Creates an order logic card with the specified list of players.
* The input list is shuffled before being inserted into the queue. *
* <p>The input list is shuffled in place to establish a random initial turn order.
* This is intentional: the caller's list (typically {@code Game.playersList}) is
* reordered so that the game's canonical player sequence reflects the randomised order.
* *
* @param players the list of players associated with this order logic card. * @param players the list of players associated with this order logic card.
* <strong>The list is mutated (shuffled) by this constructor.</strong>
*/ */
public OrderLogicCard(ArrayList<Player> players) { public OrderLogicCard(ArrayList<Player> players) {
Collections.shuffle(players); Collections.shuffle(players);
this.players = new LinkedList<>(players); this.players = new LinkedList<>(players);
nPlayers = players.size(); nPlayers = players.size();
this.playerList=new ArrayList<>(players.stream().map(x->new OrderPlayer(x,false)).toList()); this.playerList = new ArrayList<>(players.stream().map(x -> new OrderPlayer(x, false)).toList());
} }
/** /**
@@ -50,16 +64,13 @@ public abstract class OrderLogicCard implements Serializable {
* *
* @param player the player to be pushed into the queue. * @param player the player to be pushed into the queue.
*/ */
public void push(Player player){ public void push(Player player) {
effect(player,players.size()); effect(player, players.size());
if(players.size()==0) if (players.size() == 0) {
{
playerList.clear(); playerList.clear();
} }
playerList.add(new OrderPlayer(player,false)); playerList.add(new OrderPlayer(player, false));
players.add(player); players.add(player);
} }
/** /**
@@ -70,10 +81,10 @@ public abstract class OrderLogicCard implements Serializable {
* *
* @param player the player to be pushed into the queue. * @param player the player to be pushed into the queue.
*/ */
public void pushNoEffect(Player player){ public void pushNoEffect(Player player) {
players.removeIf(x->player.getUserName().equals(x.getUserName())); players.removeIf(x -> player.getUserName().equals(x.getUserName()));
playerList.removeIf(x->player.getUserName().equals(x.player.getUserName())); playerList.removeIf(x -> player.getUserName().equals(x.getPlayer().getUserName()));
playerList.add(new OrderPlayer(player,false)); playerList.add(new OrderPlayer(player, false));
players.add(player); players.add(player);
} }
@@ -85,11 +96,10 @@ public abstract class OrderLogicCard implements Serializable {
* *
* @return the first player in the queue, or {@code null} if the queue is empty. * @return the first player in the queue, or {@code null} if the queue is empty.
*/ */
public Player pull(){ public Player pull() {
for(OrderPlayer p:playerList){ for (OrderPlayer p : playerList) {
if(p.played==false) if (!p.isPlayed()) {
{ p.markAsPlayed();
p.played=true;
break; break;
} }
} }
@@ -122,10 +132,30 @@ public abstract class OrderLogicCard implements Serializable {
* *
* @param player the player to whom the building effect is applied. * @param player the player to whom the building effect is applied.
*/ */
protected void buildingEffect(Player player) protected void buildingEffect(Player player) {
{ long count = player.getBuildingCards().stream().filter(x -> x.getEffectId() == 3).count();
for(BuildingCard b : player.getBuildingCards().stream().filter(x->x.getEffectId()==3).toList()) player.addFood((int) count);
player.addFood(1); }
/**
* Returns whether the given player is currently present in the turn queue.
*
* @param player the player to look up.
* @return {@code true} if the player is in the queue; {@code false} otherwise.
*/
public boolean containsInQueue(Player player) {
return players.contains(player);
}
/**
* Removes the given player from both the turn queue and the order list.
* No-op if the player is not present.
*
* @param player the player to remove.
*/
public void removeFromQueue(Player player) {
players.removeIf(x -> x.equals(player));
playerList.removeIf(x -> x.getPlayer().equals(player));
} }
/** /**
@@ -137,11 +167,10 @@ public abstract class OrderLogicCard implements Serializable {
* username is present in the order list. * username is present in the order list.
* @see Player * @see Player
*/ */
public int getPosition(String username) public int getPosition(String username) {
{
int pos = 0; int pos = 0;
for (OrderPlayer p : playerList) { for (OrderPlayer p : playerList) {
if (p.player.getUserName().equals(username)) if (p.getPlayer().getUserName().equals(username))
return pos; return pos;
pos++; pos++;
} }
@@ -70,10 +70,10 @@ public class Order2 extends OrderLogicCard {
for(int i=0;i<2;i++) for(int i=0;i<2;i++)
{ {
try { try {
if(playerList.get(i).played) if(playerList.get(i).isPlayed())
stringUp.add(""); stringUp.add("");
else else
stringUp.add(playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName()); stringUp.add(playerList.get(i).getPlayer().getTotem() != null ? playerList.get(i).getPlayer().getTotem().toString() : playerList.get(i).getPlayer().getUserName());
} }
catch (IndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
stringUp.add(""); stringUp.add("");
@@ -74,10 +74,10 @@ public class Order3 extends OrderLogicCard {
for(int i=0;i<3;i++) for(int i=0;i<3;i++)
{ {
try { try {
if(playerList.get(i).played) if(playerList.get(i).isPlayed())
stringUp.add(""); stringUp.add("");
else else
stringUp.add(i + ". " + (playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName())); stringUp.add(i + ". " + (playerList.get(i).getPlayer().getTotem() != null ? playerList.get(i).getPlayer().getTotem().toString() : playerList.get(i).getPlayer().getUserName()));
} }
catch (IndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
stringUp.add(""); stringUp.add("");
@@ -80,10 +80,10 @@ public class Order4 extends OrderLogicCard {
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
{ {
try { try {
if(playerList.get(i).played) if(playerList.get(i).isPlayed())
stringUp.add(""); stringUp.add("");
else else
stringUp.add(i + ". " + (playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName())); stringUp.add(i + ". " + (playerList.get(i).getPlayer().getTotem() != null ? playerList.get(i).getPlayer().getTotem().toString() : playerList.get(i).getPlayer().getUserName()));
} }
catch (IndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
stringUp.add(""); stringUp.add("");
@@ -81,10 +81,10 @@ public class Order5 extends OrderLogicCard {
for(int i=0;i<5;i++) for(int i=0;i<5;i++)
{ {
try { try {
if(playerList.get(i).played) if(playerList.get(i).isPlayed())
stringUp.add(""); stringUp.add("");
else else
stringUp.add(i + ". " + (playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName())); stringUp.add(i + ". " + (playerList.get(i).getPlayer().getTotem() != null ? playerList.get(i).getPlayer().getTotem().toString() : playerList.get(i).getPlayer().getUserName()));
} }
catch (IndexOutOfBoundsException e) { catch (IndexOutOfBoundsException e) {
stringUp.add(""); stringUp.add("");
@@ -15,12 +15,37 @@ public class OrderPlayer implements Serializable {
/** /**
* The player associated with this order entry. * The player associated with this order entry.
*/ */
public Player player; private final Player player;
/** /**
* Indicates whether the player has already played. * Indicates whether the player has already played.
*/ */
public boolean played; private boolean played;
/**
* Returns the player associated with this order entry.
*
* @return the player.
*/
public Player getPlayer() {
return player;
}
/**
* Returns whether the player has already played in this order sequence.
*
* @return {@code true} if the player has played; {@code false} otherwise.
*/
public boolean isPlayed() {
return played;
}
/**
* Marks this player as having played in the current order sequence.
*/
public void markAsPlayed() {
this.played = true;
}
/** /**
* Creates an order entry for the specified player. * Creates an order entry for the specified player.
@@ -39,13 +39,13 @@ public abstract class PlayableCard implements Serializable {
/** /**
* Creates a playable card with the specified era. * Creates a playable card with the specified era.
* *
* @param Era the era of the playable card. * @param era the era of the playable card.
* @throws IllegalArgumentException if {@code Era <= 0} or {@code Era >= 4}. * @throws IllegalArgumentException if {@code era <= 0} or {@code era >= 4}.
*/ */
public PlayableCard (int Era) throws IllegalArgumentException{ public PlayableCard(int era) throws IllegalArgumentException {
idIMG="-1"; idIMG = "-1";
if (Era>0 && Era<4) { if (era > 0 && era < 4) {
this.era = Era; this.era = era;
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@@ -55,22 +55,22 @@ public abstract class PlayableCard implements Serializable {
* Creates a playable card with the specified image id and era. * Creates a playable card with the specified image id and era.
* *
* @param idIMG the image identifier of the playable card. * @param idIMG the image identifier of the playable card.
* @param Era the era of the playable card. * @param era the era of the playable card.
* @throws IllegalArgumentException if {@code Era <= 0} or {@code Era >= 4}. * @throws IllegalArgumentException if {@code era <= 0} or {@code era >= 4}.
*/ */
public PlayableCard (String idIMG,int Era) throws IllegalArgumentException{ public PlayableCard(String idIMG, int era) throws IllegalArgumentException {
this.idIMG = idIMG; this.idIMG = idIMG;
if (Era>0 && Era<4) { if (era > 0 && era < 4) {
this.era = Era; this.era = era;
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
} }
/** /**
* Returns the string representation of this playable card. * Returns a string representation of this playable card.
* *
* @return the string representation of this playable card. * @return a string representation of this playable card.
*/ */
@Override @Override
public String toString() { public String toString() {
@@ -78,14 +78,11 @@ public abstract class PlayableCard implements Serializable {
} }
/** /**
* Prints a string representation of this {@code PlayableCard}. This specific variation is used in the {@code Game}'s * Returns a compact string representation used when rendering the board in the TUI.
* toString to print a more detailed version (in this specific case the two methods are equal). *
* @return {@code String} - a string representation of this {@code PlayableCard}. * @return a compact board representation of this card.
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/ */
public String toStringBoard() public String toStringBoard() {
{
return ":"; return ":";
} }
} }
@@ -20,7 +20,7 @@ public class Player implements Serializable {
/** /**
* The maximum length allowed for the username string. * The maximum length allowed for the username string.
*/ */
private static final int MAX_VALUE = 32; private static final int MAX_USERNAME_LENGTH = 32;
/** /**
* Identifier for the {@code Player} when displaying the game through the GUI. * Identifier for the {@code Player} when displaying the game through the GUI.
@@ -135,11 +135,8 @@ public class Player implements Serializable {
// region Setters // region Setters
/** /**
* Adds {@code Value} amount of {@code Food} to the Player. * Adds {@code value} amount of Food to the Player.
* @param value The amount of {@code Food} to be added. * @param value The amount of Food to be added. Should be non-negative.
* Should be positive for expected results
* (otherwise the method will subtract the absolute
* value of {@code Value}).
* @see #foodValue * @see #foodValue
*/ */
public void addFood(int value){ public void addFood(int value){
@@ -156,20 +153,15 @@ public class Player implements Serializable {
} }
/** /**
* Removes {@code Value} amount of {@code Food} from the Player. * Removes {@code value} amount of Food from the Player.
* Note: {@link #foodValue} cannot be negative, so the method returns * {@link #foodValue} cannot go negative: returns {@code false} if
* {@code false} if {@code Value} is greater than the amount of {@code Food} * {@code value} exceeds the current food and leaves the value unchanged.
* the Player possesses, and {@code true} otherwise.
* *
* @param value The amount of {@code Food} to be removed. * @param value The amount of Food to be removed. Should be non-negative.
* Should be positive for expected results * @return {@code true} if the Food is successfully removed, {@code false} otherwise.
* (otherwise the method will add the absolute
* value of {@code Value}).
* @return {@code Boolean} - {@code true} if the Food is successfully removed,
* {@code false} otherwise.
* @see #foodValue * @see #foodValue
*/ */
public Boolean removeFood(int value){ public boolean removeFood(int value){
if(value > this.foodValue){ if(value > this.foodValue){
return false; return false;
} }
@@ -178,28 +170,20 @@ public class Player implements Serializable {
} }
/** /**
* Adds {@code Value} amount of {@code Prestige} to the Player. * Adds {@code value} amount of Prestige to the Player.
* @param value The amount of {@code Prestige} to be added. * @param value The amount of Prestige to be added. Should be non-negative.
* Should be positive for expected results
* (otherwise the method will subtract the absolute
* value of {@code Value}).
* @see #prestigeValue * @see #prestigeValue
*/ */
public void addPrestige(int value){ public void addPrestige(int value){
this.prestigeValue += value; this.prestigeValue += value;
} }
/** /**
* Removes {@code Value} amount of {@code Prestige} to the Player. * Removes {@code value} amount of Prestige from the Player.
* @param value The amount of {@code Prestige} to be removed. * @param value The amount of Prestige to be removed. Should be non-negative.
* Should be positive for expected results
* (otherwise the method will add the absolute
* value of {@code Value}).
* @see #prestigeValue * @see #prestigeValue
*/ */
public void removePrestige(int value){ public void removePrestige(int value){
this.prestigeValue -= value; this.prestigeValue -= value;
} }
@@ -211,15 +195,15 @@ public class Player implements Serializable {
* Constructor for the class {@code Player}. Each Player is uniquely identified by the {@link #userName}. * Constructor for the class {@code Player}. Each Player is uniquely identified by the {@link #userName}.
* *
* @param userName Unique String identifier for a Player. * @param userName Unique String identifier for a Player.
* @throws IllegalArgumentException when {@code UserName} is empty or exceeds {@link #MAX_VALUE}, * @throws IllegalArgumentException when {@code userName} is empty or exceeds {@link #MAX_USERNAME_LENGTH},
* with message: * with message:
* <pre>{@code UserName is empty or exceeds maximum permitted length.}</pre> * <pre>{@code UserName is empty or exceeds maximum permitted length.}</pre>
* *
* @see #userName * @see #userName
* @see #MAX_VALUE * @see #MAX_USERNAME_LENGTH
*/ */
public Player(String userName) throws IllegalArgumentException { public Player(String userName) throws IllegalArgumentException {
if(userName.isEmpty() || userName.length() > MAX_VALUE) { if(userName.isEmpty() || userName.length() > MAX_USERNAME_LENGTH) {
throw new IllegalArgumentException("UserName is empty or exceeds maximum permitted length."); throw new IllegalArgumentException("UserName is empty or exceeds maximum permitted length.");
} }
this.userName = userName; this.userName = userName;
@@ -80,9 +80,6 @@ public class Slot implements Serializable {
} }
// End getters // End getters
// Setters
// End setters
// Constructors // Constructors
/** /**
@@ -157,15 +154,15 @@ public class Slot implements Serializable {
/** /**
* Prints a string representation of this {@code Slot}. This specific variation is used in the {@code Game}'s * Returns a compact string representation of this {@code Slot} for the TUI.
* toString to print a more detailed version for the TUI implementation. * <p>Includes:
* <p>includes: * <ul>
* <li>{@link #slotId SlotId} * <li>{@link #slotId}</li>
* <li>{@link #NUpper NUpper} * <li>{@link #nUpper} (shown as symbols)</li>
* <li>{@link #NLower NLower} * <li>{@link #nLower} (shown as symbols)</li>
* <li>{@link #Food Food} * <li>{@link #food} (if non-zero)</li>
* </p> * </ul>
* @return {@code String} - a string representation of this {@code Slot}. * @return a compact TUI string representation of this {@code Slot}.
* @see it.polimi.ingsw.gc14.Model.Game Game * @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board * @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/ */
@@ -179,8 +176,6 @@ public class Slot implements Serializable {
return s.toString(); return s.toString();
} }
// End Constructors
// Functions // Functions
@Override @Override
@@ -129,7 +129,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
System.out.println("Reconnected player: " + username); System.out.println("Reconnected player: " + username);
startWatchdog(username); startWatchdog(username);
Game game = controller.getModel(); Game game = controller.getModel();
callback.onGameInit(new MiniModel(game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(), game.getPlayers(), game.getAvailableTotems(), game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnectedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new)))); callback.onGameInit(new MiniModel(game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(), game.getPlayers(), game.getAvailableTotems(), game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.getDisconnectedPlayers().entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))));
System.out.println("Model sent: " + username); System.out.println("Model sent: " + username);
actionQueue.add(new ReconnectPlayer(username)); actionQueue.add(new ReconnectPlayer(username));
return null; return null;
@@ -266,7 +266,7 @@ public class TCPServer {
game.getCurrentState(), game.getCurrentState(),
game.getPlayers(), game.getPlayers(),
game.getAvailableTotems(), game.getAvailableTotems(),
game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnectedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new)) game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.getDisconnectedPlayers().entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))
)); ));
Thread thread = new Thread(handler); Thread thread = new Thread(handler);
@@ -98,7 +98,7 @@ public class ServerLauncher {
game.getPlayers(), game.getAvailableTotems(), game.getPlayers(), game.getAvailableTotems(),
game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListTribeCards(), game.getLowerListTribeCards(),
game.getUpperListBuilding(), game.getLowerListBuilding(), game.getUpperListBuilding(), game.getLowerListBuilding(),
game.disconnectedPlayers.entrySet().stream() game.getDisconnectedPlayers().entrySet().stream()
.filter(Map.Entry::getValue) .filter(Map.Entry::getValue)
.map(e -> e.getKey().getUserName()) .map(e -> e.getKey().getUserName())
.collect(Collectors.toCollection(ArrayList::new)) .collect(Collectors.toCollection(ArrayList::new))
@@ -161,7 +161,7 @@ public class ServerLauncher {
Game game = saveManager.load(); Game game = saveManager.load();
if (game == null) return; if (game == null) return;
long disconnectedCount = game.disconnectedPlayers.entrySet().stream() long disconnectedCount = game.getDisconnectedPlayers().entrySet().stream()
.filter(Map.Entry::getValue).count(); .filter(Map.Entry::getValue).count();
if (disconnectedCount >= game.getNPlayers() - 1) { if (disconnectedCount >= game.getNPlayers() - 1) {
@@ -173,7 +173,7 @@ public class ServerLauncher {
gameController.setModel(game); gameController.setModel(game);
playerList.setLimit(game.getNPlayers()); playerList.setLimit(game.getNPlayers());
for (Map.Entry<Player, Boolean> entry : game.disconnectedPlayers.entrySet()) { for (Map.Entry<Player, Boolean> entry : game.getDisconnectedPlayers().entrySet()) {
if (entry.getValue()) { if (entry.getValue()) {
playerList.put(entry.getKey().getUserName(), false); playerList.put(entry.getKey().getUserName(), false);
} }
@@ -608,16 +608,16 @@ public class MainFXMLController {
overlay.setPickOnBounds(false); overlay.setPickOnBounds(false);
overlay.setMouseTransparent(true); overlay.setMouseTransparent(true);
for (int i = 0; i < controller.miniModel.orderLogicCard.playerList.size(); i++) { for (int i = 0; i < controller.miniModel.orderLogicCard.getPlayerList().size(); i++) {
OrderPlayer op = controller.miniModel.orderLogicCard.playerList.get(i); OrderPlayer op = controller.miniModel.orderLogicCard.getPlayerList().get(i);
// Carica immagine totem come in createSlot // Carica immagine totem come in createSlot
ImageView totem = new ImageView(loadImage( ImageView totem = new ImageView(loadImage(
"/GUIImages/Totems/totem_" + op.player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png" "/GUIImages/Totems/totem_" + op.getPlayer().getTotem().toString().toLowerCase(Locale.ROOT) + ".png"
)); ));
totem.setPreserveRatio(true); totem.setPreserveRatio(true);
if (op.played) { if (op.isPlayed()) {
totem.setVisible(false); totem.setVisible(false);
} }
@@ -263,8 +263,8 @@ class GameControllerTest {
assertTrue(controller.disconnectedPlayer(current.getUserName())); assertTrue(controller.disconnectedPlayer(current.getUserName()));
assertTrue(game.disconnectedPlayers.containsKey(current)); assertTrue(game.getDisconnectedPlayers().containsKey(current));
assertTrue(game.disconnectedPlayers.get(current)); assertTrue(game.getDisconnectedPlayers().get(current));
} }
@Test @Test
@@ -75,7 +75,7 @@ class BoardTest {
Board bd3 = new Board(3); Board bd3 = new Board(3);
Board bd4 = new Board(4); Board bd4 = new Board(4);
Board bd5 = new Board(5); Board bd5 = new Board(5);
for(TribeCard tribe : bd2.upperListTribe) for(TribeCard tribe : bd2.getUpperListTribe())
{ {
System.out.println(tribe.getIdIMG() +" "+tribe.toStringBoard()); System.out.println(tribe.getIdIMG() +" "+tribe.toStringBoard());
assertNotEquals("-1",tribe.getIdIMG()); assertNotEquals("-1",tribe.getIdIMG());
@@ -102,12 +102,12 @@ class BoardTest {
assertEquals(96 - (numPlayer+4) - (numPlayer+1), bd.getTribeDeckSize()); // Verifica che dal mazzo TribeDeck venga pescato il numero corretto di carte assertEquals(96 - (numPlayer+4) - (numPlayer+1), bd.getTribeDeckSize()); // Verifica che dal mazzo TribeDeck venga pescato il numero corretto di carte
assertEquals(numPlayer+1, bd.lowerListTribe.size()); // Verifica che la dimensione della lista inferiore sia corretta assertEquals(numPlayer+1, bd.getLowerListTribe().size()); // Verifica che la dimensione della lista inferiore sia corretta
assertTrue(bd.lowerListTribe.stream().noneMatch(card -> card.isEventCard())); // Verifica che non ci siano EventCard dentro alla lista inferiore assertTrue(bd.getLowerListTribe().stream().noneMatch(card -> card.isEventCard())); // Verifica che non ci siano EventCard dentro alla lista inferiore
assertEquals(numPlayer+4, bd.upperListTribe.size()); // Verifica che la dimensione della lista superiore sia corretta assertEquals(numPlayer+4, bd.getUpperListTribe().size()); // Verifica che la dimensione della lista superiore sia corretta
assertEquals(2, bd.upperListBuilding.size()); // Verifica che ci sia il giusto numero di buildings (2 edifici per 3+ giocatori) assertEquals(2, bd.getUpperListBuilding().size()); // Verifica che ci sia il giusto numero di buildings (2 edifici per 3+ giocatori)
} }
@Test @Test
@@ -116,7 +116,7 @@ class BoardTest {
Board bd = new Board(0); Board bd = new Board(0);
Queue<EventCard> eventQueue = new LinkedList<>(); Queue<EventCard> eventQueue = new LinkedList<>();
for (TribeCard card : bd.lowerListTribe) { for (TribeCard card : bd.getLowerListTribe()) {
if (card.isEventCard()) { if (card.isEventCard()) {
eventQueue.add((EventCard) card); eventQueue.add((EventCard) card);
} }
@@ -130,13 +130,13 @@ class BoardTest {
void removeUpperTribeCard() { void removeUpperTribeCard() {
Board bd = new Board(3); Board bd = new Board(3);
List<TribeCard> before = new ArrayList<>( bd.upperListTribe); List<TribeCard> before = new ArrayList<>( bd.getUpperListTribe());
TribeCard cardToRemove = before.get(0); TribeCard cardToRemove = before.get(0);
assertEquals(cardToRemove, before.remove(0)); assertEquals(cardToRemove, before.remove(0));
assertTrue( bd.removeUpperTribeCard(cardToRemove)); assertTrue( bd.removeUpperTribeCard(cardToRemove));
assertEquals(before, bd.upperListTribe); assertEquals(before, bd.getUpperListTribe());
} }
@Test @Test
@@ -144,13 +144,13 @@ class BoardTest {
void removeLowerTribeCard() { void removeLowerTribeCard() {
Board bd = new Board(3); Board bd = new Board(3);
List<TribeCard> before = new ArrayList<>(bd.lowerListTribe); List<TribeCard> before = new ArrayList<>(bd.getLowerListTribe());
TribeCard cardToRemove = before.get(0); TribeCard cardToRemove = before.get(0);
assertEquals(cardToRemove, before.remove(0)); assertEquals(cardToRemove, before.remove(0));
assertTrue( bd.removeLowerTribeCard(cardToRemove)); assertTrue( bd.removeLowerTribeCard(cardToRemove));
assertEquals(before, bd.lowerListTribe); assertEquals(before, bd.getLowerListTribe());
} }
@Test @Test
@@ -158,13 +158,13 @@ class BoardTest {
void removeUpperBuildingCard() { void removeUpperBuildingCard() {
Board bd = new Board(3); Board bd = new Board(3);
List<BuildingCard> before = new ArrayList<>(bd.upperListBuilding); List<BuildingCard> before = new ArrayList<>(bd.getUpperListBuilding());
BuildingCard cardToRemove = before.get(0); BuildingCard cardToRemove = before.get(0);
assertEquals(cardToRemove, before.remove(0)); assertEquals(cardToRemove, before.remove(0));
assertTrue( bd.removeUpperBuildingCard(cardToRemove)); assertTrue( bd.removeUpperBuildingCard(cardToRemove));
assertEquals(before, bd.upperListBuilding); assertEquals(before, bd.getUpperListBuilding());
} }
@Test @Test
@@ -176,11 +176,11 @@ class BoardTest {
bd.nextRound(); // Skip to era 2 bd.nextRound(); // Skip to era 2
} }
List<BuildingCard> before = new ArrayList<>( bd.lowerListBuilding); List<BuildingCard> before = new ArrayList<>( bd.getLowerListBuilding());
BuildingCard cardToRemove = before.get(0); BuildingCard cardToRemove = before.get(0);
assertEquals(cardToRemove, before.remove(0)); assertEquals(cardToRemove, before.remove(0));
assertTrue(bd.removeLowerBuildingCard(cardToRemove)); assertTrue(bd.removeLowerBuildingCard(cardToRemove));
assertEquals(before, bd.lowerListBuilding); assertEquals(before, bd.getLowerListBuilding());
} }
@Test @Test
@@ -188,13 +188,13 @@ class BoardTest {
void nextRound() { void nextRound() {
int numPlayer = 3; int numPlayer = 3;
Board bd = new Board(numPlayer); Board bd = new Board(numPlayer);
assertTrue(!bd.lowerListTribe.isEmpty()); assertTrue(!bd.getLowerListTribe().isEmpty());
List<TribeCard> upperListBefore = new ArrayList<>(bd.upperListTribe); List<TribeCard> upperListBefore = new ArrayList<>(bd.getUpperListTribe());
bd.nextRound(); bd.nextRound();
assertEquals(upperListBefore, bd.lowerListTribe); // Verifica che la lista superiore è stata spostata sotto assertEquals(upperListBefore, bd.getLowerListTribe()); // Verifica che la lista superiore è stata spostata sotto
assertNotEquals(upperListBefore, bd.upperListTribe); // Verifica che la lista superiore sia stata cambiata assertNotEquals(upperListBefore, bd.getUpperListTribe()); // Verifica che la lista superiore sia stata cambiata
assertEquals(numPlayer+4, bd.upperListTribe.size()); // Verifica che la nuova dimensione della lista superiore sia corretta assertEquals(numPlayer+4, bd.getUpperListTribe().size()); // Verifica che la nuova dimensione della lista superiore sia corretta
} }
@Test @Test
@@ -209,31 +209,31 @@ class BoardTest {
// Era 2, nTotem <= 3 // Era 2, nTotem <= 3
numPlayer = 3; numPlayer = 3;
Board bd1 = new Board(numPlayer); Board bd1 = new Board(numPlayer);
upperListBefore = new ArrayList<>(bd1.upperListBuilding); upperListBefore = new ArrayList<>(bd1.getUpperListBuilding());
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
bd1.nextRound(); // Skip to era 2 bd1.nextRound(); // Skip to era 2
} }
assertEquals(2, bd1.getEra()); assertEquals(2, bd1.getEra());
assertEquals(upperListBefore, bd1.lowerListBuilding); assertEquals(upperListBefore, bd1.getLowerListBuilding());
assertNotEquals(upperListBefore, bd1.upperListBuilding); assertNotEquals(upperListBefore, bd1.getUpperListBuilding());
assertEquals(2, bd1.upperListBuilding.size()); assertEquals(2, bd1.getUpperListBuilding().size());
assertTrue(bd1.upperListBuilding.stream().allMatch(x->x.getEra()==2)); assertTrue(bd1.getUpperListBuilding().stream().allMatch(x->x.getEra()==2));
assertTrue(bd1.lowerListBuilding.stream().allMatch(x->x.getEra()==1)); assertTrue(bd1.getLowerListBuilding().stream().allMatch(x->x.getEra()==1));
// Era 2, nTotem > 3 // Era 2, nTotem > 3
numPlayer = 4; numPlayer = 4;
Board bd2 = new Board(numPlayer); Board bd2 = new Board(numPlayer);
upperListBefore = new ArrayList<>(bd2.upperListBuilding); upperListBefore = new ArrayList<>(bd2.getUpperListBuilding());
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
bd2.nextRound(); // Skip to era 2 bd2.nextRound(); // Skip to era 2
} }
assertEquals(2, bd2.getEra()); assertEquals(2, bd2.getEra());
assertEquals(upperListBefore, bd2.lowerListBuilding); assertEquals(upperListBefore, bd2.getLowerListBuilding());
assertNotEquals(upperListBefore, bd2.upperListBuilding); assertNotEquals(upperListBefore, bd2.getUpperListBuilding());
assertEquals(3, bd2.upperListBuilding.size()); assertEquals(3, bd2.getUpperListBuilding().size());
assertTrue(bd2.upperListBuilding.stream().allMatch(x->x.getEra()==2)); assertTrue(bd2.getUpperListBuilding().stream().allMatch(x->x.getEra()==2));
assertTrue(bd2.lowerListBuilding.stream().allMatch(x->x.getEra()==1)); assertTrue(bd2.getLowerListBuilding().stream().allMatch(x->x.getEra()==1));
// Era 3, nTotem == 2 // Era 3, nTotem == 2
numPlayer = 2; numPlayer = 2;
@@ -241,16 +241,16 @@ class BoardTest {
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
bd3.nextRound(); // Skip to era 2 bd3.nextRound(); // Skip to era 2
} }
upperListBefore = new ArrayList<>(bd3.upperListBuilding); // We need to take the list of the era 2 upperListBefore = new ArrayList<>(bd3.getUpperListBuilding()); // We need to take the list of the era 2
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
bd3.nextRound(); // Skip to era 3 bd3.nextRound(); // Skip to era 3
} }
assertEquals(3, bd3.getEra()); assertEquals(3, bd3.getEra());
assertEquals(upperListBefore, bd3.lowerListBuilding); assertEquals(upperListBefore, bd3.getLowerListBuilding());
assertNotEquals(upperListBefore, bd3.upperListBuilding); assertNotEquals(upperListBefore, bd3.getUpperListBuilding());
assertEquals(3, bd3.upperListBuilding.size()); assertEquals(3, bd3.getUpperListBuilding().size());
assertTrue(bd3.upperListBuilding.stream().allMatch(x->x.getEra()==3)); assertTrue(bd3.getUpperListBuilding().stream().allMatch(x->x.getEra()==3));
assertTrue(bd3.lowerListBuilding.stream().allMatch(x->x.getEra()==2)); assertTrue(bd3.getLowerListBuilding().stream().allMatch(x->x.getEra()==2));
// Era 3, nTotem == 5 // Era 3, nTotem == 5
@@ -259,16 +259,16 @@ class BoardTest {
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
bd4.nextRound(); // Skip to era 2 bd4.nextRound(); // Skip to era 2
} }
upperListBefore = new ArrayList<>(bd4.upperListBuilding); // We need to take the list of the era 2 upperListBefore = new ArrayList<>(bd4.getUpperListBuilding()); // We need to take the list of the era 2
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
bd4.nextRound(); // Skip to era 3 bd4.nextRound(); // Skip to era 3
} }
assertEquals(3, bd4.getEra()); assertEquals(3, bd4.getEra());
assertEquals(upperListBefore, bd4.lowerListBuilding); assertEquals(upperListBefore, bd4.getLowerListBuilding());
assertNotEquals(upperListBefore, bd4.upperListBuilding); assertNotEquals(upperListBefore, bd4.getUpperListBuilding());
assertEquals(5, bd4.upperListBuilding.size()); assertEquals(5, bd4.getUpperListBuilding().size());
assertTrue(bd4.upperListBuilding.stream().allMatch(x->x.getEra()==3)); assertTrue(bd4.getUpperListBuilding().stream().allMatch(x->x.getEra()==3));
assertTrue(bd4.lowerListBuilding.stream().allMatch(x->x.getEra()==2)); assertTrue(bd4.getLowerListBuilding().stream().allMatch(x->x.getEra()==2));
// Era 3, nTotem != 2, 5 // Era 3, nTotem != 2, 5
@@ -277,16 +277,16 @@ class BoardTest {
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
bd5.nextRound(); // Skip to era 2 bd5.nextRound(); // Skip to era 2
} }
upperListBefore = new ArrayList<>(bd5.upperListBuilding); // We need to take the list of the era 2 upperListBefore = new ArrayList<>(bd5.getUpperListBuilding()); // We need to take the list of the era 2
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
bd5.nextRound(); // Skip to era 3 bd5.nextRound(); // Skip to era 3
} }
assertEquals(3, bd5.getEra()); assertEquals(3, bd5.getEra());
assertEquals(upperListBefore, bd5.lowerListBuilding); assertEquals(upperListBefore, bd5.getLowerListBuilding());
assertNotEquals(upperListBefore, bd5.upperListBuilding); assertNotEquals(upperListBefore, bd5.getUpperListBuilding());
assertEquals(4, bd5.upperListBuilding.size()); assertEquals(4, bd5.getUpperListBuilding().size());
assertTrue(bd5.upperListBuilding.stream().allMatch(x->x.getEra()==3)); assertTrue(bd5.getUpperListBuilding().stream().allMatch(x->x.getEra()==3));
assertTrue(bd5.lowerListBuilding.stream().allMatch(x->x.getEra()==2)); assertTrue(bd5.getLowerListBuilding().stream().allMatch(x->x.getEra()==2));
} }
@@ -1341,8 +1341,8 @@ class GameTest {
assertTrue(game.disconnectedPlayer(current)); assertTrue(game.disconnectedPlayer(current));
assertTrue(game.disconnectedPlayers.containsKey(current)); assertTrue(game.getDisconnectedPlayers().containsKey(current));
assertTrue(game.disconnectedPlayers.get(current)); assertTrue(game.getDisconnectedPlayers().get(current));
assertNotEquals(current, game.getCurrentState().getCurrentPlayer()); assertNotEquals(current, game.getCurrentState().getCurrentPlayer());
} }
@@ -1367,10 +1367,10 @@ class GameTest {
Player current = game.getCurrentState().getCurrentPlayer(); Player current = game.getCurrentState().getCurrentPlayer();
assertTrue(game.disconnectedPlayer(current)); assertTrue(game.disconnectedPlayer(current));
assertTrue(game.disconnectedPlayers.containsKey(current)); assertTrue(game.getDisconnectedPlayers().containsKey(current));
assertTrue(game.reconnectPlayer(current)); assertTrue(game.reconnectPlayer(current));
assertFalse(game.disconnectedPlayers.containsKey(current)); assertFalse(game.getDisconnectedPlayers().containsKey(current));
} }
@Test @Test
@@ -1382,11 +1382,11 @@ class GameTest {
Player current = game.getCurrentState().getCurrentPlayer(); Player current = game.getCurrentState().getCurrentPlayer();
assertTrue(game.disconnectedPlayer(current)); assertTrue(game.disconnectedPlayer(current));
assertFalse(game.disconnectedPlayers.isEmpty()); assertFalse(game.getDisconnectedPlayers().isEmpty());
game.clearDisconnected(); game.clearDisconnected();
assertTrue(game.disconnectedPlayers.isEmpty()); assertTrue(game.getDisconnectedPlayers().isEmpty());
} }
@Test @Test