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

Class Class, % Method, % Branch, % Line, %
CurrentState 100% (1/1) 93.3% (14/15) 100% (2/2) 64.3% (27/42)


 package it.polimi.ingsw.gc14.Model.GamePackage;
 
 import it.polimi.ingsw.gc14.Model.Player;
 import it.polimi.ingsw.gc14.Model.Slot;
 import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
 import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
 import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
 
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Represents the current state of the game.
  * A CurrentState object stores the current player, slot, era, round,
  * remaining upper and lower cards, and the current game stage.
  */
 public class CurrentState implements Serializable {
 
     /**
      * The current player associated with the game state.
      */
     private Player player;
 
     /**
      * Returns the current player.
      *
      * @return the current player.
      */
     public Player getCurrentPlayer(){
         return player;
     }
 
     /**
      * The current slot associated with the game state.
      */
     private Slot slot;
 
     /**
      * Returns the current slot.
      *
      * @return the current slot.
      */
     public Slot getSlot(){
         return slot;
     }
 
     /**
      * The current era of the game.
      */
     private int era;
 
     /**
      * Returns the current era of the game.
      *
      * @return the current era of the game.
      */
     public int getEra(){
         return era;
     }
 
     /**
      * The current round of the game.
      */
     private int round;
 
     /**
      * Returns the current round of the game.
      *
      * @return the current round of the game.
      */
     public int getRound(){
         return round;
     }
 
     /**
      * The number of upper cards currently available.
      */
     private int nUpper;
 
     /**
      * Returns the number of upper cards currently available.
      *
      * @return the number of upper cards currently available.
      */
     public int getNUpper(){
         return nUpper;
     }
 
     /**
      * The number of lower cards currently available.
      */
     private int nLower;
 
     /**
      * Returns the number of lower cards currently available.
      *
      * @return the number of lower cards currently available.
      */
     public int getNLower(){
         return nLower;
     }
 
     /**
      * The current stage of the game.
      */
     private GameStages gameStage;
 
     /**
      * Returns the current stage of the game.
      *
      * @return the current stage of the game.
      */
     public GameStages getGameStage(){
         return gameStage;
     }
 
 
 
     /**
      * Increments the current era by 1.
      */
     public void eraUpdate(){
         era++;
     }
 
     /**
      * Increments the current round by 1.
      */
     public void roundUpdate(){
         round++;
     }
 
     /**
      * Decrements the number of upper cards by 1.
      */
     public void upperDrawn(){
         nUpper--;
     }
 
     /**
      * Decrements the number of lower cards by 1.
      */
     public void lowerDrawn(){
         nLower--;
     }
 
     /**
      * Updates the current game stage.
      *
      * @param stage the new game stage.
      */
     public void gameStageUpdate(GameStages stage){
         this.gameStage = stage;
     }
 
 
     /**
      * Creates a new CurrentState object with default initial values.
      * The initial player and slot are {@code null}, the era and round are set to 1,
      * the number of upper and lower cards is set to 0, and the game stage is set to {@code WAITING}.
      */
     public CurrentState(){
         this.player = null;
         this.slot = null;
         this.era = 1;
         this.round = 1;
         this.nUpper = 0;
         this.nLower = 0;
         this.gameStage = GameStages.WAITING;
     }
 
 
     /**
      * Updates the current player, slot, and available draws.
      * If {@code slot} is {@code null}, both {@link #nUpper} and {@link #nLower} are reset to 0.
      * Otherwise, they are set from the slot's values.
      *
      * @param player the new current player.
      * @param slot the new current slot, or {@code null} when no slot is active.
      */
     public void playerUpdate(Player player, Slot slot){
         this.player = player;
         this.slot = slot;
         if(slot == null){
             this.nUpper = 0;
             this.nLower = 0;
         }
         else{
             this.nUpper = slot.getNUpper();
             this.nLower = slot.getNLower();
         }
 
     }
 
     /**
      * Returns a formatted ASCII table representation of the current game state.
      * Columns: Player, Round, Era, GameStage.
      *
      * @return a {@code String} containing the ASCII table.
      */
     @Override
     public String toString(){
         var table= new AsciiTable(BorderStyle.ROUNDED,4);
         List<String>header= new ArrayList<>();
         header.add("Player");
         header.add("Round");
         header.add("Era");
         header.add("GameStage");
         table.addRow(header);
         table.addSeparator();
         List<String>values= new ArrayList<>();
         values.add(player.getUserName());
         values.add(Integer.toString(round));
         values.add(Integer.toString(era));
         values.add(gameStage.toString());
         table.addRow(values);
         return table.build();
     }
 }