Add: complete JavaDoc for MiniModel and TCPServer

This commit is contained in:
MatteoPellegrino05
2026-05-18 18:59:31 +02:00
parent e28e7bab6d
commit 4434053138
2 changed files with 376 additions and 125 deletions
@@ -1,37 +1,86 @@
package it.polimi.ingsw.gc14.Model;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
import java.io.Serializable;
import java.util.*;
/**
* Lightweight representation of the game model shared with clients.
*
* <p>The mini model contains only the information required by the client-side
* view and controllers to render the current match state and process incoming
* network updates.
*/
public class MiniModel implements Serializable {
/**
* Current game board.
*/
public Board board;
/**
* Map associating each occupied slot with the corresponding player.
*/
public Map<Slot, Player> slotPlayerMap;
/**
* Card used to manage the player turn order.
*/
public OrderLogicCard orderLogicCard;
/**
* Current state of the game.
*/
public CurrentState currentState;
/**
* Map of players indexed by username.
*/
public Map<String, Player> players;
/**
* List of totems still available for selection.
*/
public List<Totems> availableTotems;
/**
* Final standing of the players at the end of the game.
*/
public List<Player> standingPlayers;
// --- Costruttori ---
/**
* Constructs an empty mini model.
*/
public MiniModel() {
}
/**
* Constructs a mini model containing only the game board.
*
* @param board the current game board.
*/
public MiniModel(Board board) {
this.board = board;
}
public MiniModel(Board board, Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard,
CurrentState currentState, List<Player> players, List<Totems> availableTotems) {
/**
* Constructs a complete mini model from the current server-side game data.
*
* @param board the current game board.
* @param slotPlayerMap the map associating occupied slots with players.
* @param orderLogicCard the card managing player turn order.
* @param currentState the current state of the game.
* @param players the list of players in the match.
* @param availableTotems the list of totems still available for selection.
*/
public MiniModel(Board board,
Map<Slot, Player> slotPlayerMap,
OrderLogicCard orderLogicCard,
CurrentState currentState,
List<Player> players,
List<Totems> availableTotems) {
this.board = board;
this.slotPlayerMap = slotPlayerMap;
this.orderLogicCard = orderLogicCard;
@@ -42,43 +91,90 @@ public class MiniModel implements Serializable {
setPlayers(players);
}
// --- Setter ---
/**
* Sets the current game board.
*
* @param board the board to assign.
*/
public void setBoard(Board board) {
this.board = board;
}
/**
* Sets the list of totems still available for selection.
*
* @param availableTotems the available totems.
*/
public void setAvailableTotems(List<Totems> availableTotems) {
this.availableTotems = availableTotems;
}
/**
* Sets the map associating occupied slots with players.
*
* @param slotPlayerMap the slot-player map to assign.
*/
public void setSlotPlayerMap(Map<Slot, Player> slotPlayerMap) {
this.slotPlayerMap = slotPlayerMap;
}
/**
* Sets the card used to manage the player turn order.
*
* @param orderLogicCard the order logic card to assign.
*/
public void setOrderLogicCard(OrderLogicCard orderLogicCard) {
this.orderLogicCard = orderLogicCard;
}
/**
* Sets the current state of the game.
*
* @param currentState the current game state.
*/
public void setCurrentState(CurrentState currentState) {
this.currentState = currentState;
}
/**
* Replaces or updates the players stored in the mini model.
*
* <p>Each player is indexed by username.
*
* @param players the list of players to store.
*/
public void setPlayers(List<Player> players) {
for (Player player : players) {
this.players.put(player.getUserName(), player);
}
}
/**
* Adds or updates a single player in the mini model.
*
* @param player the player to store.
*/
public void setPlayer(Player player) {
players.put(player.getUserName(), player);
}
/**
* Sets the final standing of the players.
*
* @param standingPlayers the final ordered list of players.
*/
public void setStandingPlayers(ArrayList<Player> standingPlayers) {
this.standingPlayers = standingPlayers;
}
/**
* Returns the position of the player with the specified username
* within the player collection.
*
* @param username the username of the player to search for.
* @return the zero-based position of the player, or {@code -1}
* if no matching username is found.
*/
public int getPositionByUsername(String username) {
int i = 0;
for (Player player : players.values()) {