Coverage Summary for Class: MiniModel (it.polimi.ingsw.gc14.Model)

Class Class, % Method, % Branch, % Line, %
MiniModel 0% (0/1) 0% (0/18) 0% (0/14) 0% (0/36)


 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.GamePackage.CurrentState;
 import it.polimi.ingsw.gc14.Network.NetworkEvent;
 
 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 {
 
     /** Upper row of tribe cards currently on the board. */
     public ArrayList<TribeCard> upperListTribeCards;
     /** Lower row of tribe cards currently on the board. */
     public ArrayList<TribeCard> lowerListTribeCards;
     /** Upper row of building cards currently on the board. */
     public ArrayList<BuildingCard> upperListBuildingCards;
     /** Lower row of building cards currently on the board. */
     public ArrayList<BuildingCard> lowerListBuildingCards;
     /** Usernames of players currently disconnected from the game. */
     public ArrayList<String> disconnectedPlayers;
     /** The most recent network event applied to this model. */
     public NetworkEvent lastEvent;
 
     /**
      * 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 final 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;
 
 
     /**
      * Constructs a complete mini model from the current server-side game data.
      *
      * @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.
      * @param upperListTribeCards    the upper row of tribe cards on the board.
      * @param lowerListTribeCards    the lower row of tribe cards on the board.
      * @param upperListBuildingCards the upper row of building cards on the board.
      * @param lowerListBuildingCards the lower row of building cards on the board.
      * @param disconnectedPlayers    the list of usernames of currently disconnected players.
      */
     public MiniModel(Map<Slot, Player> slotPlayerMap,
                      OrderLogicCard orderLogicCard,
                      CurrentState currentState,
                      List<Player> players,
                      List<Totems> availableTotems,ArrayList<TribeCard> upperListTribeCards,ArrayList<TribeCard>lowerListTribeCards,ArrayList<BuildingCard> upperListBuildingCards,ArrayList<BuildingCard>lowerListBuildingCards, ArrayList<String> disconnectedPlayers) {
 
         this.slotPlayerMap = slotPlayerMap;
         this.orderLogicCard = orderLogicCard;
         this.currentState = currentState;
         this.players = new LinkedHashMap<>();
         this.availableTotems = availableTotems;
         this.standingPlayers = new ArrayList<>();
         this.upperListTribeCards = upperListTribeCards;
         this.lowerListTribeCards = lowerListTribeCards;
         this.upperListBuildingCards = upperListBuildingCards;
         this.lowerListBuildingCards = lowerListBuildingCards;
         this.disconnectedPlayers = disconnectedPlayers;
         setPlayers(players);
     }
 
     /**
      * Sets the last network event applied to the game state.
      *
      * @param lastEvent the most recent event received from the server.
      */
     public void setLastEvent(NetworkEvent lastEvent) {
         this.lastEvent = lastEvent;
     }
 
 
     /**
      * 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);
         }
     }
 
     /**
      * Sets the final standing of the players.
      *
      * @param standingPlayers the final ordered list of players.
      */
     public void setStandingPlayers(List<Player> standingPlayers) {
         this.standingPlayers = standingPlayers;
     }
 
     /**
      * Replaces the upper row of tribe cards on the board.
      *
      * @param cards the new upper tribe card list.
      */
     public void setUpperListTribeCards(ArrayList<TribeCard> cards) {
         this.upperListTribeCards = cards;
     }
 
     /**
      * Replaces the lower row of tribe cards on the board.
      *
      * @param cards the new lower tribe card list.
      */
     public void setLowerListTribeCards(ArrayList<TribeCard> cards) {
         this.lowerListTribeCards = cards;
     }
 
     /**
      * Replaces the upper row of building cards on the board.
      *
      * @param cards the new upper building card list.
      */
     public void setUpperListBuildingCards(ArrayList<BuildingCard> cards) {
         this.upperListBuildingCards = cards;
     }
 
     /**
      * Replaces the lower row of building cards on the board.
      *
      * @param cards the new lower building card list.
      */
     public void setLowerListBuildingCards(ArrayList<BuildingCard> cards) {
         this.lowerListBuildingCards = cards;
     }
 
     /**
      * Removes the card at the given position from the upper tribe card list.
      *
      * @param pos the zero-based index of the card to remove.
      */
     public void removeUpperTribeCard(int pos) {
         if (upperListTribeCards != null) upperListTribeCards.remove(pos);
     }
 
     /**
      * Removes the card at the given position from the lower tribe card list.
      *
      * @param pos the zero-based index of the card to remove.
      */
     public void removeLowerTribeCard(int pos) {
         if (lowerListTribeCards != null) lowerListTribeCards.remove(pos);
     }
 
     /**
      * Removes the card at the given position from the upper building card list.
      *
      * @param pos the zero-based index of the card to remove.
      */
     public void removeUpperBuildingCard(int pos) {
         if (upperListBuildingCards != null) upperListBuildingCards.remove(pos);
     }
 
     /**
      * Removes the card at the given position from the lower building card list.
      *
      * @param pos the zero-based index of the card to remove.
      */
     public void removeLowerBuildingCard(int pos) {
         if (lowerListBuildingCards != null) lowerListBuildingCards.remove(pos);
     }
 
     /**
      * 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()) {
             if (player.getUserName().equals(username)) {
                 return i;
             }
             i++;
         }
         return -1;
     }
 
     /**
      * Sets the list of usernames of currently disconnected players.
      *
      * @param disconnectedPlayers the list of disconnected player usernames.
      */
     public void setDisconnectedPlayers (ArrayList<String> disconnectedPlayers){
         this.disconnectedPlayers=disconnectedPlayers;
     }
 }