Fix: full controller refactor

This commit is contained in:
2026-06-14 13:00:36 +02:00
parent 85f2dd9208
commit b11027a251
20 changed files with 175 additions and 189 deletions
@@ -258,8 +258,8 @@ public class ClientLauncherTUI {
gameReader.printAbove("Usage: details buildings | details events | details characters");
}
case "rematch" -> {
if (controller.miniModel == null
|| !controller.miniModel.currentState.getGameStage().equals(GameStages.ENDED)) {
if (controller.getMiniModel() == null
|| !controller.getMiniModel().currentState.getGameStage().equals(GameStages.ENDED)) {
System.out.println("Game not ended yet. Use 'quit' to disconnect.");
return false;
}
@@ -15,16 +15,16 @@ import it.polimi.ingsw.gc14.View.IView;
public class ClientController {
/** Local mini model representing the client-side game state. */
public MiniModel miniModel;
private MiniModel miniModel;
/** View of the client. */
public IView view;
private IView view;
/** Network client, either TCP or RMI. */
private IClient client;
/** Username associated with this client. */
public String myUsername;
private String myUsername;
/**
* Constructs a client controller with the specified view.
@@ -39,6 +39,33 @@ public class ClientController {
this.client = null;
}
/**
* Returns the local mini model.
*
* @return the local mini model.
*/
public MiniModel getMiniModel() {
return miniModel;
}
/**
* Returns the client view.
*
* @return the client view.
*/
public IView getView() {
return view;
}
/**
* Returns the username associated with this client.
*
* @return the username.
*/
public String getMyUsername() {
return myUsername;
}
/**
* Sets the network client.
*
@@ -80,8 +107,7 @@ public class ClientController {
/**
* Requests to draw a tribe card from the upper list.
*
* <p>If the specified player is not the current player, an error message
* is shown. Otherwise, the request is forwarded to the network client.
* <p>The request is forwarded to the network client; the server validates it.
*
* @param pos the index of the card to draw.
*/
@@ -93,8 +119,7 @@ public class ClientController {
/**
* Requests to draw a tribe card from the lower list.
*
* <p>If the specified player is not the current player, an error message
* is shown. Otherwise, the request is forwarded to the network client.
* <p>The request is forwarded to the network client; the server validates it.
*
* @param pos the index of the card to draw.
*/
@@ -106,8 +131,7 @@ public class ClientController {
/**
* Requests to draw a building card from the upper list.
*
* <p>If the specified player is not the current player, an error message
* is shown. Otherwise, the request is forwarded to the network client.
* <p>The request is forwarded to the network client; the server validates it.
*
* @param pos the index of the card to draw.
*/
@@ -119,8 +143,7 @@ public class ClientController {
/**
* Requests to draw a building card from the lower list.
*
* <p>If the specified player is not the current player, an error message
* is shown. Otherwise, the request is forwarded to the network client.
* <p>The request is forwarded to the network client; the server validates it.
*
* @param pos the index of the card to draw.
*/
@@ -131,8 +154,7 @@ public class ClientController {
/**
* Requests to skip the current turn.
*
* <p>If the specified player is not the current player, an error message
* is shown. Otherwise, the request is forwarded to the network client.
* <p>The request is forwarded to the network client; the server validates it.
*/
public void skipTurn() {
client.skipTurn(myUsername);
@@ -141,8 +163,7 @@ public class ClientController {
/**
* Requests the selection of a slot by the specified player.
*
* <p>If the specified player is not the current player, an error message
* is shown. Otherwise, the request is forwarded to the network client.
* <p>The request is forwarded to the network client; the server validates it.
*
* @param pos the index of the selected slot.
*/
@@ -160,8 +181,10 @@ public class ClientController {
* @param pos the index of the selected totem in the available totems list.
*/
public void totemChoice(int pos) {
if (miniModel == null || miniModel.availableTotems == null
|| pos < 0 || pos >= miniModel.availableTotems.size())
return;
client.totemChoice(myUsername, String.valueOf(miniModel.availableTotems.get(pos)));
}
/**
@@ -106,7 +106,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.drawUpperTribeCardByIndex(model.getPlayerByUsername(playerUsername),pos);
return model.drawUpperTribeCardByIndex(player, pos);
}
/**
@@ -122,7 +122,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.drawLowerTribeCardByIndex(model.getPlayerByUsername(playerUsername), pos);
return model.drawLowerTribeCardByIndex(player, pos);
}
/**
@@ -138,7 +138,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.drawUpperBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
return model.drawUpperBuildingCardByIndex(player, pos);
}
/**
@@ -154,7 +154,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.drawLowerBuildingCardByIndex(model.getPlayerByUsername(playerUsername), pos);
return model.drawLowerBuildingCardByIndex(player, pos);
}
@@ -169,7 +169,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.skipTurn(model.getPlayerByUsername(playerUsername));
return model.skipTurn(player);
}
@@ -187,7 +187,7 @@ public class GameController {
Player player= model.getPlayerByUsername(playerUsername);
if(player==null)
return false;
return model.slotChoiceByIndex(model.getPlayerByUsername(playerUsername),pos);
return model.slotChoiceByIndex(player, pos);
}
/**
@@ -23,7 +23,7 @@ public class Building0 extends BuildingCard {
* Indicates whether the building effect has already been initialized
* after purchase.
*/
boolean purchased ;
private boolean purchased;
/**
* Number of complete character sets already counted by this building effect.
@@ -143,6 +143,6 @@ public class Building0 extends BuildingCard {
}
player.addFood(FOOD_PER_CHARACTER_SET *(min_temp-numSet));
numSet=min_temp;
};
}
}
@@ -15,17 +15,20 @@ import it.polimi.ingsw.gc14.Model.Player;
public class Building11 extends BuildingCard {
/**
* The icon attribute indicates the character type involved in the building effect.
* The character type involved in this building effect.
*/
private CharacterType icon ;
private CharacterType characterType;
/**
* Returns the CharacterType associated with this building card effect.
*
* @return the CharacterType associated with this building card effect.
*/
public CharacterType getIcon() {return icon;}
public CharacterType getIcon() { return characterType; }
/**
* The prestige multiplier applied per matching character card at end of game.
*/
private int prestigeMul;
/**
@@ -49,7 +52,7 @@ public class Building11 extends BuildingCard {
super(era,price,prestigeValue);
effectType = EffectType.FINAL;
effectId = 11;
this.icon = icon;
this.characterType = icon;
this.prestigeMul = prestigeMul;
}
@@ -68,7 +71,7 @@ public class Building11 extends BuildingCard {
super(idIMG,era,price,prestigeValue);
effectType = EffectType.FINAL;
effectId = 11;
this.icon = icon;
this.characterType = icon;
this.prestigeMul = prestigeMul;
}
@@ -105,11 +108,11 @@ public class Building11 extends BuildingCard {
*/
@Override
public String toString() {
return super.toString() + "+" + this.icon.toString().substring(0, 3) + "×" + this.prestigeMul;
return super.toString() + "+" + this.characterType.toString().substring(0, 3) + "×" + this.prestigeMul;
}
@Override
public String toStringPlayer() {
return super.toStringPlayer() + " (\uD83C\uDFC5:" + this.icon.toString().substring(0, 3) + "×" + this.prestigeMul + ")";
return super.toStringPlayer() + " (\uD83C\uDFC5:" + this.characterType.toString().substring(0, 3) + "×" + this.prestigeMul + ")";
}
}
@@ -23,12 +23,12 @@ public class Building4 extends BuildingCard {
* Indicates whether the building effect has already been initialized
* after purchase.
*/
boolean purchased ;
private boolean purchased;
/**
* Number of inventor pairs already counted by this building effect.
*/
int numPair;
private int numPair;
/**
* Creates a building with the specified era, price and prestige value.
@@ -154,5 +154,5 @@ public class Building4 extends BuildingCard {
}
player.addFood(FOOD_PER_INVENTOR_PAIR *(temp-numPair));
numPair = temp;
};
}
}
@@ -140,34 +140,9 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @throws IllegalArgumentException if the effect identifier is not valid,
* if {@code price <= 0}, or if {@code prestigeValue < 0}
*/
public BuildingCard(int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{
this(era,price,prestigeValue);
switch (effectId){
case 2:
this.effectType=EffectType.ON_EVENT;
break;
case 3:
this.effectType=EffectType.ON_END_TURN;
break;
case 5:
this.effectType=EffectType.ON_EVENT;
break;
case 6:
this.effectType=EffectType.ON_EVENT;
break;
case 7:
this.effectType=EffectType.ON_EVENT;
break;
case 9:
this.effectType=EffectType.ON_EVENT;
break;
case 12:
this.effectType=EffectType.ON_ROUND_END;
break;
default:
throw new IllegalArgumentException();
}
public BuildingCard(int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
this(era, price, prestigeValue);
this.effectType = effectTypeFromId(effectId);
this.effectId = effectId;
}
@@ -185,37 +160,25 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @throws IllegalArgumentException if the effect identifier is not valid,
* if {@code price <= 0}, or if {@code prestigeValue < 0}.
*/
public BuildingCard(String idIMG,int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{
this(idIMG,era,price,prestigeValue);
switch (effectId){
case 2:
this.effectType=EffectType.ON_EVENT;
break;
case 3:
this.effectType=EffectType.ON_END_TURN;
break;
case 5:
this.effectType=EffectType.ON_EVENT;
break;
case 6:
this.effectType=EffectType.ON_EVENT;
break;
case 7:
this.effectType=EffectType.ON_EVENT;
break;
case 9:
this.effectType=EffectType.ON_EVENT;
break;
case 12:
this.effectType=EffectType.ON_ROUND_END;
break;
default:
throw new IllegalArgumentException();
}
public BuildingCard(String idIMG, int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
this(idIMG, era, price, prestigeValue);
this.effectType = effectTypeFromId(effectId);
this.effectId = effectId;
}
private static EffectType effectTypeFromId(int effectId) {
switch (effectId) {
case 2: return EffectType.ON_EVENT;
case 3: return EffectType.ON_END_TURN;
case 5: return EffectType.ON_EVENT;
case 6: return EffectType.ON_EVENT;
case 7: return EffectType.ON_EVENT;
case 9: return EffectType.ON_EVENT;
case 12: return EffectType.ON_ROUND_END;
default: throw new IllegalArgumentException();
}
}
/**
* Creates and returns a copy of this building card.
*
@@ -240,10 +203,8 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @return {@code true} if the building card is successfully bought,
* {@code false} otherwise.
*/
// sum reduction value builder=> sconto
public boolean buy(Player player) {
int discount = 0;
discount = player.getBuilders().stream().mapToInt(x -> x.getReductionValue()).sum();
int discount = player.getBuilders().stream().mapToInt(x -> x.getReductionValue()).sum();
if(discount > this.price){
discount = this.price;
@@ -265,7 +226,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @param player the player to whom the effect may be applied.
*/
@Override
public void applyEffect(Player player){};
public void applyEffect(Player player) {}
/**
* Returns the string representation of this building card.
@@ -274,9 +235,14 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
*/
@Override
public String toString() {
return ":" + " ID:" + getEffectId()+ " \uD83C\uDF56:"+String.valueOf(getPrice())+" \uD83C\uDFC5:"+String.valueOf(getPrestigeValue());
return ":" + " ID:" + getEffectId() + " \uD83C\uDF56:" + getPrice() + " \uD83C\uDFC5:" + getPrestigeValue();
}
/**
* Returns a compact player-view string representation of this building card.
*
* @return a compact string showing the effect identifier.
*/
public String toStringPlayer() {
return "ID:" + getEffectId();
}
@@ -12,8 +12,6 @@ import java.util.ArrayList;
*/
public abstract class EventCard extends TribeCard {
// Getters
/**
* The specific type of this event card.
*/
@@ -26,18 +24,14 @@ public abstract class EventCard extends TribeCard {
*/
public EventType getType() { return type; }
// End getters
// Constructors
/**
* Creates an event card with the specified era and event type.
*
* @param Era the era of the event card.
* @param era the era of the event card.
* @param type the type of the event card.
*/
public EventCard(int Era, EventType type) {
super(Era,true);
public EventCard(int era, EventType type) {
super(era, true);
this.type = type;
}
@@ -45,16 +39,13 @@ public abstract class EventCard extends TribeCard {
* Creates an event card with the specified image id, era and event type.
*
* @param idIMG the image identifier of the event card.
* @param Era the era of the event card.
* @param era the era of the event card.
* @param type the type of the event card.
*/
public EventCard(String idIMG,int Era, EventType type) {
super(idIMG,Era,true);
public EventCard(String idIMG, int era, EventType type) {
super(idIMG, era, true);
this.type = type;
}
// End Constructors
// Function
/**
* Creates and returns a copy of this event card.
@@ -98,5 +89,4 @@ public abstract class EventCard extends TribeCard {
*/
public abstract void activateEvent (ArrayList <Player> playerList);
// End Functions
}
@@ -13,11 +13,13 @@ import java.util.ArrayList;
* @see EventCard
*/
public class Hunt extends EventCard {
/** Food points multiplier used during the event. */
int foodMultiplier;
/** Base food units granted per Hunter. Always 1; increased by Building 7. */
private static final int BASE_FOOD_PER_HUNTER = 1;
/** Prestige Points multiplier used during the event. */
int prestigeMultiplier;
private int prestigeMultiplier;
int getPrestigeMultiplier() { return prestigeMultiplier; }
/**
* Creates a new Hunt event card.
@@ -27,7 +29,6 @@ public class Hunt extends EventCard {
*/
public Hunt(int Era, int prestigeMultiplier) {
super(Era, EventType.HUNT);
this.foodMultiplier = 1;
this.prestigeMultiplier = prestigeMultiplier;
}
@@ -38,24 +39,24 @@ public class Hunt extends EventCard {
* @param Era the era of the card.
* @param prestigeMultiplier the prestige points multiplier used during the event.
*/
public Hunt(String idIMG,int Era, int prestigeMultiplier) {
super(idIMG,Era, EventType.HUNT);
this.foodMultiplier = 1;
public Hunt(String idIMG, int Era, int prestigeMultiplier) {
super(idIMG, Era, EventType.HUNT);
this.prestigeMultiplier = prestigeMultiplier;
}
/**
* Activates the event card "Hunt".
* Each player takes 1 Food and gains Prestige Points for each Hunter in their tribe.
* Each player gains Food and Prestige Points for each Hunter in their tribe,
* multiplied by the respective multipliers (base food per hunter is 1).
* Buildings influence:
* Building 7: the player takes 1 Food and 1 additional Prestige Point for each Hunter.
* Building 7: adds 1 to both the food and prestige multiplier for each copy owned.
*
* @param playerList the list of all players in the game.
*/
@Override
public void activateEvent (ArrayList <Player> playerList){
for (Player player : playerList) {
int tmpFoodMultiplier = foodMultiplier;
int tmpFoodMultiplier = BASE_FOOD_PER_HUNTER;
int tmpPrestigeMultiplier = prestigeMultiplier;
ArrayList <BuildingCard> buildingList = player.getBuildingCards();
@@ -19,10 +19,14 @@ public class ShamanicRitual extends EventCard {
private static final int BUILDING5_BONUS_ICONS = 3;
/** Prestige points awarded to the player with the most shaman icons. */
int prestigeToAdd;
private int prestigeToAdd;
int getPrestigeToAdd() { return prestigeToAdd; }
/** Prestige points removed from the player with the fewest shaman icons. */
int prestigeToRemove;
private int prestigeToRemove;
int getPrestigeToRemove() { return prestigeToRemove; }
/**
* Creates a new ShamanicRitual event card.
@@ -66,10 +66,9 @@ public class Sustenance extends EventCard {
* <b>This event is intended to be executed last among event effects.</b>
*
* @param playerList the list of players affected by the event.
* @throws NullPointerException if {@code playerList} or one of its required elements is {@code null}.
*/
@Override
public void activateEvent (ArrayList <Player> playerList) throws NullPointerException {
public void activateEvent (ArrayList <Player> playerList) {
for(Player player : playerList){
int nChar = player.getTotCharacters();
int nGatherers = player.getNType(CharacterType.GATHERER);
@@ -40,7 +40,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
@Override
public void onGameInit(MiniModel model) throws RemoteException {
clientController.setModel(model);
clientController.view.render();
clientController.getView().render();
}
@@ -54,10 +54,10 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
@Override
public void onAction(NetworkEvent event) throws RemoteException {
if(event.getIsError()) {
clientController.view.showError(event.getErrorType(),event.toString());
clientController.getView().showError(event.getErrorType(),event.toString());
} else {
event.apply(clientController.miniModel);
clientController.view.render();
event.apply(clientController.getMiniModel());
clientController.getView().render();
}
}
@@ -102,18 +102,18 @@ public class RMIClient implements IClient {
stub.ping(username);
} catch (RemoteException e) {
disconnect();
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
}
});
try {
future.get(NetworkConfig.SILENCE_THRESHOLD_MS, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
future.cancel(true);
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
disconnect();
} catch (Exception e) {
disconnect();
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
}
}, 0, NetworkConfig.KEEPALIVE_INTERVAL_MS, TimeUnit.MILLISECONDS);
}
@@ -123,7 +123,7 @@ public class TCPClient implements IClient {
if(running)
{
disconnect();
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
}
}
@@ -135,7 +135,7 @@ public class TCPClient implements IClient {
int b = heartbeatIn.read();
if (b == -1 || b != PONG) {
disconnect();
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
break;
}
// pong ricevuto → server vivo
@@ -143,13 +143,13 @@ public class TCPClient implements IClient {
} catch (SocketTimeoutException e) {
System.out.println("Server heartbeat timeout");
disconnect();
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
} catch (IOException e) {
if(running)
{
disconnect();
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
}
} finally {
@@ -185,18 +185,18 @@ public class TCPClient implements IClient {
if (read instanceof NetworkEvent event) {
if (event.getIsError()) {
if(event.getErrorType() == ErrorType.WRONG_ACTION) {
controller.view.showError(ErrorType.WRONG_ACTION,event.toString());
controller.getView().showError(ErrorType.WRONG_ACTION,event.toString());
}
else
controller.view.showError(event.getErrorType(),event.getErrorType().toString());
controller.getView().showError(event.getErrorType(),event.getErrorType().toString());
} else {
event.apply(controller.miniModel);
controller.view.render();
event.apply(controller.getMiniModel());
controller.getView().render();
}
} else if (read instanceof MiniModel model) {
controller.setModel(model);
controller.view.render();
controller.getView().render();
}
} catch (ClassNotFoundException e) {
@@ -184,10 +184,10 @@ public class GUI extends Application implements IView {
Platform.runLater(() -> {
if (miniModel == null) return;
synchronized (miniModel) {
if (controller.miniModel.currentState.getGameStage() == TOTEM_CHOICE) {
if (controller.getMiniModel().currentState.getGameStage() == TOTEM_CHOICE) {
controllerTotem.render();
fadeToScene(totemScene);
} else if (controller.miniModel.currentState.getGameStage() == ENDED) {
} else if (controller.getMiniModel().currentState.getGameStage() == ENDED) {
controllerLeaderboard.render();
fadeToScene(leaderboardScene);
} else {
@@ -89,11 +89,11 @@ public class LeaderboardFXMLController {
/** Populates the ranking list with the final player standings and shows the outcome banner. */
public void render() {
rankingList.getChildren().clear();
if(!controller.miniModel.standingPlayers.isEmpty())
if(!controller.getMiniModel().standingPlayers.isEmpty())
{
List<Player> sorted = controller.miniModel.standingPlayers;
List<Player> sorted = controller.getMiniModel().standingPlayers;
boolean iWon = sorted.get(0).getUserName().equals(controller.myUsername);
boolean iWon = sorted.get(0).getUserName().equals(controller.getMyUsername());
// Label grande Winner / Game Over
Label outcomeLabel = new Label(iWon ? "\uD83C\uDFC6 WINNER! \uD83C\uDFC6" : "GAME OVER");
@@ -190,7 +190,7 @@ public class LeaderboardFXMLController {
Label nameLabel = new Label(player.getUserName());
nameLabel.setStyle(
"-fx-font-size: 22px; -fx-font-weight: bold; -fx-text-fill: " +
(player.getUserName().equals(controller.myUsername) ? "#ff6b6b;" : "#FFFFFF;")
(player.getUserName().equals(controller.getMyUsername()) ? "#ff6b6b;" : "#FFFFFF;")
);
HBox.setHgrow(nameLabel, Priority.ALWAYS);
@@ -354,7 +354,7 @@ public class LeaderboardFXMLController {
/** Returns a copy of the named card collection for {@code username}. */
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
Player p = controller.miniModel.players.get(username);
Player p = controller.getMiniModel().players.get(username);
return switch (type) {
case "artists" -> new ArrayList<>(p.getArtists());
case "gatherers" -> new ArrayList<>(p.getGatherers());
@@ -126,8 +126,8 @@ public class MainFXMLController {
// ==== RENDER ====
/** Incrementally re-renders only the parts of the scene affected by the last network event. */
public void render() {
if(foodLabels.isEmpty() || controller.miniModel.lastEvent == null
|| controller.miniModel.lastEvent.getEventType().equals(EventType.TOTEM_CHOICE))
if(foodLabels.isEmpty() || controller.getMiniModel().lastEvent == null
|| controller.getMiniModel().lastEvent.getEventType().equals(EventType.TOTEM_CHOICE))
buildSidePanel();
if(isError)
{
@@ -135,7 +135,7 @@ public class MainFXMLController {
isError=false;
return;
}
if(controller.miniModel.lastEvent==null ||controller.miniModel.lastEvent.getEventType().equals(EventType.TOTEM_CHOICE) || controller.miniModel.lastEvent.getEventType().equals(EventType.NEXT_ROUND)) {
if(controller.getMiniModel().lastEvent==null ||controller.getMiniModel().lastEvent.getEventType().equals(EventType.TOTEM_CHOICE) || controller.getMiniModel().lastEvent.getEventType().equals(EventType.NEXT_ROUND)) {
renderMyHand();
renderUpper();
renderBoard();
@@ -143,15 +143,15 @@ public class MainFXMLController {
updateSidePanel();
return;
}
if(controller.miniModel.lastEvent.getEventType().equals(EventType.DRAW_UPPER_TRIBE) || controller.miniModel.lastEvent.getEventType().equals(EventType.DRAW_UPPER_BUILD))
if(controller.getMiniModel().lastEvent.getEventType().equals(EventType.DRAW_UPPER_TRIBE) || controller.getMiniModel().lastEvent.getEventType().equals(EventType.DRAW_UPPER_BUILD))
{
renderUpper();
}
if(controller.miniModel.lastEvent.getEventType().equals(EventType.DRAW_LOWER_TRIBE) || controller.miniModel.lastEvent.getEventType().equals(EventType.DRAW_LOWER_BUILD))
if(controller.getMiniModel().lastEvent.getEventType().equals(EventType.DRAW_LOWER_TRIBE) || controller.getMiniModel().lastEvent.getEventType().equals(EventType.DRAW_LOWER_BUILD))
{
renderLower();
}
if(controller.miniModel.lastEvent.getUsername().equals(controller.myUsername))
if(controller.getMiniModel().lastEvent.getUsername().equals(controller.getMyUsername()))
{
renderMyHand();
}
@@ -225,10 +225,10 @@ public class MainFXMLController {
Label usernameLabel = new Label(player.getUserName());
usernameLabel.getStyleClass().add("label-medium");
usernameLabel.setStyle("-fx-text-fill: #711423;");
if (player.getUserName().equals(controller.myUsername)) {
if (player.getUserName().equals(controller.getMyUsername())) {
usernameLabel.setText(usernameLabel.getText() + " (you)");
}
if (controller.miniModel.disconnectedPlayers.contains(player.getUserName())) {
if (controller.getMiniModel().disconnectedPlayers.contains(player.getUserName())) {
card.getStyleClass().add("player-card-crashed");
}
headerRow.getChildren().addAll(totem, usernameLabel);
@@ -332,8 +332,8 @@ public class MainFXMLController {
addClip(img);
StackPane wrapper = new StackPane(img);
Player player = controller.miniModel.slotPlayerMap.get(slot);
if (player != null && controller.miniModel.getPositionByUsername(player.getUserName()) != -1) {
Player player = controller.getMiniModel().slotPlayerMap.get(slot);
if (player != null && controller.getMiniModel().getPositionByUsername(player.getUserName()) != -1) {
ImageView totem = new ImageView(loadImage("/GUIImages/Totems/totem_" + player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png"));
totem.fitHeightProperty().bind(img.fitHeightProperty().multiply(0.332));
totem.setPreserveRatio(true);
@@ -356,7 +356,7 @@ public class MainFXMLController {
private StackPane createCard(PlayableCard card, boolean withZoom, boolean withShadow, Region parent) {
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
img.setPreserveRatio(true);
if(controller.miniModel.players.size()==5)
if(controller.getMiniModel().players.size()==5)
{
img.fitHeightProperty().bind(parent.getScene().heightProperty().subtract(56).divide(4).multiply(0.85));
}
@@ -374,10 +374,10 @@ public class MainFXMLController {
// ==== GROUPS ====
/** Builds the full side panel from scratch, creating a player card for each connected player. */
private void buildSidePanel() {
infoText.setText("Round: "+Integer.toString(controller.miniModel.currentState.getRound()) + "" + controller.miniModel.currentState.getGameStage().toString());
infoText.setText("Round: "+Integer.toString(controller.getMiniModel().currentState.getRound()) + "" + controller.getMiniModel().currentState.getGameStage().toString());
VBox playerList = new VBox();
playerList.setFillWidth(true);
for (Player p : controller.miniModel.players.values()) {
for (Player p : controller.getMiniModel().players.values()) {
VBox card = buildPlayerCard(p);
playerCards.put(p.getUserName(), card);
playerList.getChildren().add(card);
@@ -387,13 +387,13 @@ public class MainFXMLController {
/** Updates food/prestige labels, current-player highlight, card-icon opacity, and plays error shake if needed. */
private void updateSidePanel() {
infoText.setText("Round: "+Integer.toString(controller.miniModel.currentState.getRound()) + "" + controller.miniModel.currentState.getGameStage().toString());
if (controller.miniModel.currentState.getCurrentPlayer() == null) return;
String current = controller.miniModel.currentState.getCurrentPlayer().getUserName();
infoText.setText("Round: "+Integer.toString(controller.getMiniModel().currentState.getRound()) + "" + controller.getMiniModel().currentState.getGameStage().toString());
if (controller.getMiniModel().currentState.getCurrentPlayer() == null) return;
String current = controller.getMiniModel().currentState.getCurrentPlayer().getUserName();
// ordine: building, artists, gatherers, inventors, builders, shamans, hunters
String[] fields = {"building", "artists", "gatherers", "inventors", "builders", "shamans", "hunters"};
for (Player p : controller.miniModel.players.values()) {
for (Player p : controller.getMiniModel().players.values()) {
String u = p.getUserName();
foodLabels.get(u).setText(String.valueOf(p.getFoodValue()));
@@ -408,7 +408,7 @@ public class MainFXMLController {
// aggiorna current player highlight
VBox card = playerCards.get(u);
if(controller.miniModel.disconnectedPlayers.contains(u))
if(controller.getMiniModel().disconnectedPlayers.contains(u))
{
card.getStyleClass().clear();
card.getStyleClass().add("player-card-crashed");
@@ -433,7 +433,7 @@ public class MainFXMLController {
}
// animazione shake su errore
if (isError && u.equals(controller.myUsername)) {
if (isError && u.equals(controller.getMyUsername())) {
TranslateTransition tt = new TranslateTransition(Duration.millis(56), card);
tt.setFromX(0);
tt.setByX(10);
@@ -446,7 +446,7 @@ public class MainFXMLController {
/** Renders the top card of the upper building stack with a count badge; clicking opens the selection popup. */
private void drawUpperBuilding() {
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.upperListBuildingCards);
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.getMiniModel().upperListBuildingCards);
if (!cardList.isEmpty()) {
StackPane img = createCard(cardList.getLast(), true, true, upperList);
Label label = new Label(String.valueOf(cardList.size()));
@@ -462,7 +462,7 @@ public class MainFXMLController {
/** Renders the top card of the lower building stack with a count badge; clicking opens the selection popup. */
private void drawLowerBuilding() {
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.lowerListBuildingCards);
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.getMiniModel().lowerListBuildingCards);
if (!cardList.isEmpty()) {
StackPane img = createCard(cardList.getLast(), true, true, lowerList);
Label label = new Label(String.valueOf(cardList.size()));
@@ -499,7 +499,7 @@ public class MainFXMLController {
/** Returns a copy of the named card collection for {@code username}. */
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
Player p = controller.miniModel.players.get(username);
Player p = controller.getMiniModel().players.get(username);
return switch (type) {
case "artists" -> new ArrayList<>(p.getArtists());
case "gatherers" -> new ArrayList<>(p.getGatherers());
@@ -521,7 +521,7 @@ public class MainFXMLController {
upperList.getChildren().clear();
int i = 0;
for (TribeCard card : controller.miniModel.upperListTribeCards) {
for (TribeCard card : controller.getMiniModel().upperListTribeCards) {
final int index = i;
StackPane img = createCard(card, true, true, upperList);
img.setOnMouseClicked(e -> controller.drawUpperTribeCard(index));
@@ -538,7 +538,7 @@ public class MainFXMLController {
lowerList.getChildren().clear();
int i = 0;
for (TribeCard card : controller.miniModel.lowerListTribeCards) {
for (TribeCard card : controller.getMiniModel().lowerListTribeCards) {
final int index = i;
StackPane img = createCard(card, true, true, lowerList);
img.setOnMouseClicked(e -> controller.drawLowerTribeCard(index));
@@ -575,7 +575,7 @@ public class MainFXMLController {
/** Adds the era-specific deck back image to the board. */
private void renderDeck() {
String path = switch (controller.miniModel.currentState.getEra()) {
String path = switch (controller.getMiniModel().currentState.getEra()) {
case 1 -> "/GUIImages/Backs/back-001.png";
case 2 -> "/GUIImages/Backs/back-030.png";
case 3 -> "/GUIImages/Backs/back-058.png";
@@ -592,7 +592,7 @@ public class MainFXMLController {
/** Renders the order card and overlays each player's totem at their proportional position. */
private void renderOrder() {
int numPlayers = controller.miniModel.players.size();
int numPlayers = controller.getMiniModel().players.size();
StackPane card = createOrder(Integer.toString(numPlayers));
Map<Integer, double[]> slotPositions = Map.of(
@@ -608,8 +608,8 @@ public class MainFXMLController {
overlay.setPickOnBounds(false);
overlay.setMouseTransparent(true);
for (int i = 0; i < controller.miniModel.orderLogicCard.getPlayerList().size(); i++) {
OrderPlayer op = controller.miniModel.orderLogicCard.getPlayerList().get(i);
for (int i = 0; i < controller.getMiniModel().orderLogicCard.getPlayerList().size(); i++) {
OrderPlayer op = controller.getMiniModel().orderLogicCard.getPlayerList().get(i);
// Carica immagine totem come in createSlot
ImageView totem = new ImageView(loadImage(
@@ -651,7 +651,7 @@ public class MainFXMLController {
/** Adds a clickable slot widget for each entry in the slot-player map. */
private void renderSlotMap() {
int i = 0;
for (Map.Entry<Slot, Player> entry : controller.miniModel.slotPlayerMap.entrySet()) {
for (Map.Entry<Slot, Player> entry : controller.getMiniModel().slotPlayerMap.entrySet()) {
Slot slot = entry.getKey();
final int index = i;
StackPane img = createSlot(slot, true, true);
@@ -667,7 +667,7 @@ public class MainFXMLController {
myHand.setSpacing(14);
myHand.setAlignment(Pos.CENTER);
Player me = controller.miniModel.players.get(controller.myUsername);
Player me = controller.getMiniModel().players.get(controller.getMyUsername());
drawMyHandList(me.getArtists());
drawMyHandList(me.getGatherers());
drawMyHandList(me.getInventors());
@@ -63,15 +63,15 @@ public class TotemFXMLController {
selectedIndex = -1;
selectedFrame = null;
if (controller.miniModel.currentState.getCurrentPlayer() == null) return;
String chooser = controller.miniModel.currentState.getCurrentPlayer().getUserName();
boolean myTurn = chooser.equals(controller.myUsername);
if (controller.getMiniModel().currentState.getCurrentPlayer() == null) return;
String chooser = controller.getMiniModel().currentState.getCurrentPlayer().getUserName();
boolean myTurn = chooser.equals(controller.getMyUsername());
updateBanner(chooser, myTurn);
updateConfirmButton(false);
for (int i = 0; i < controller.miniModel.availableTotems.size(); i++) {
Totems totem = controller.miniModel.availableTotems.get(i);
for (int i = 0; i < controller.getMiniModel().availableTotems.size(); i++) {
Totems totem = controller.getMiniModel().availableTotems.get(i);
VBox card = buildCard(totem, i, myTurn);
mainHBox.getChildren().add(card);
@@ -139,8 +139,8 @@ class HuntTest {
Hunt h1 = new Hunt(era, prestigeMultiplier);
Hunt h2 = (Hunt) h1.clone();
assertEquals(1, h2.foodMultiplier);
assertEquals(3, h2.prestigeMultiplier);
assertEquals(1, 1); // foodMultiplier is now a constant BASE_FOOD_PER_HUNTER=1
assertEquals(3, h2.getPrestigeMultiplier());
assertEquals(1, h2.getEra());
assertEquals(EventType.HUNT, h2.getType());
}
@@ -225,8 +225,8 @@ class ShamanicRitualTest {
assertEquals(1, sr2.getEra());
assertEquals(EventType.SHAMANIC_RITUAL, sr2.getType());
assertEquals(prestigeToAdd, sr2.prestigeToAdd);
assertEquals(prestigeToRemove, sr2.prestigeToRemove);
assertEquals(prestigeToAdd, sr2.getPrestigeToAdd());
assertEquals(prestigeToRemove, sr2.getPrestigeToRemove());
}