Files
2026-06-19 22:57:43 +02:00

337 lines
9.2 KiB
HTML

<!DOCTYPE html>
<html id="htmlId">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Coverage Report > CurrentState</title>
<style type="text/css">
@import "../../css/coverage.css";
@import "../../css/idea.min.css";
</style>
<script type="text/javascript" src="../../js/highlight.min.js"></script>
<script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>
<body>
<div class="content">
<div class="breadCrumbs">
Current scope: <a href="../../index.html">all classes</a>
<span class="separator">|</span>
<a href="../index.html">it.polimi.ingsw.gc14.Model.GamePackage</a>
</div>
<h1>Coverage Summary for Class: CurrentState (it.polimi.ingsw.gc14.Model.GamePackage)</h1>
<table class="coverageStats">
<tr>
<th class="name">Class</th>
<th class="coverageStat
">
Class, %
</th>
<th class="coverageStat
">
Method, %
</th>
<th class="coverageStat
">
Branch, %
</th>
<th class="coverageStat
">
Line, %
</th>
</tr>
<tr>
<td class="name">CurrentState</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(1/1)
</span>
</td>
<td class="coverageStat">
<span class="percent">
93.3%
</span>
<span class="absValue">
(14/15)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(2/2)
</span>
</td>
<td class="coverageStat">
<span class="percent">
64.3%
</span>
<span class="absValue">
(27/42)
</span>
</td>
</tr>
</table>
<br/>
<br/>
<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package it.polimi.ingsw.gc14.Model.GamePackage;
&nbsp;
&nbsp;import it.polimi.ingsw.gc14.Model.Player;
&nbsp;import it.polimi.ingsw.gc14.Model.Slot;
&nbsp;import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
&nbsp;import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
&nbsp;import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
&nbsp;
&nbsp;import java.io.Serializable;
&nbsp;import java.util.ArrayList;
&nbsp;import java.util.List;
&nbsp;
&nbsp;/**
&nbsp; * Represents the current state of the game.
&nbsp; * A CurrentState object stores the current player, slot, era, round,
&nbsp; * remaining upper and lower cards, and the current game stage.
&nbsp; */
&nbsp;public class CurrentState implements Serializable {
&nbsp;
&nbsp; /**
&nbsp; * The current player associated with the game state.
&nbsp; */
&nbsp; private Player player;
&nbsp;
&nbsp; /**
&nbsp; * Returns the current player.
&nbsp; *
&nbsp; * @return the current player.
&nbsp; */
&nbsp; public Player getCurrentPlayer(){
<b class="fc">&nbsp; return player;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * The current slot associated with the game state.
&nbsp; */
&nbsp; private Slot slot;
&nbsp;
&nbsp; /**
&nbsp; * Returns the current slot.
&nbsp; *
&nbsp; * @return the current slot.
&nbsp; */
&nbsp; public Slot getSlot(){
<b class="fc">&nbsp; return slot;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * The current era of the game.
&nbsp; */
&nbsp; private int era;
&nbsp;
&nbsp; /**
&nbsp; * Returns the current era of the game.
&nbsp; *
&nbsp; * @return the current era of the game.
&nbsp; */
&nbsp; public int getEra(){
<b class="fc">&nbsp; return era;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * The current round of the game.
&nbsp; */
&nbsp; private int round;
&nbsp;
&nbsp; /**
&nbsp; * Returns the current round of the game.
&nbsp; *
&nbsp; * @return the current round of the game.
&nbsp; */
&nbsp; public int getRound(){
<b class="fc">&nbsp; return round;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * The number of upper cards currently available.
&nbsp; */
&nbsp; private int nUpper;
&nbsp;
&nbsp; /**
&nbsp; * Returns the number of upper cards currently available.
&nbsp; *
&nbsp; * @return the number of upper cards currently available.
&nbsp; */
&nbsp; public int getNUpper(){
<b class="fc">&nbsp; return nUpper;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * The number of lower cards currently available.
&nbsp; */
&nbsp; private int nLower;
&nbsp;
&nbsp; /**
&nbsp; * Returns the number of lower cards currently available.
&nbsp; *
&nbsp; * @return the number of lower cards currently available.
&nbsp; */
&nbsp; public int getNLower(){
<b class="fc">&nbsp; return nLower;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * The current stage of the game.
&nbsp; */
&nbsp; private GameStages gameStage;
&nbsp;
&nbsp; /**
&nbsp; * Returns the current stage of the game.
&nbsp; *
&nbsp; * @return the current stage of the game.
&nbsp; */
&nbsp; public GameStages getGameStage(){
<b class="fc">&nbsp; return gameStage;</b>
&nbsp; }
&nbsp;
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Increments the current era by 1.
&nbsp; */
&nbsp; public void eraUpdate(){
<b class="fc">&nbsp; era++;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Increments the current round by 1.
&nbsp; */
&nbsp; public void roundUpdate(){
<b class="fc">&nbsp; round++;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Decrements the number of upper cards by 1.
&nbsp; */
&nbsp; public void upperDrawn(){
<b class="fc">&nbsp; nUpper--;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Decrements the number of lower cards by 1.
&nbsp; */
&nbsp; public void lowerDrawn(){
<b class="fc">&nbsp; nLower--;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Updates the current game stage.
&nbsp; *
&nbsp; * @param stage the new game stage.
&nbsp; */
&nbsp; public void gameStageUpdate(GameStages stage){
<b class="fc">&nbsp; this.gameStage = stage;</b>
&nbsp; }
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Creates a new CurrentState object with default initial values.
&nbsp; * The initial player and slot are {@code null}, the era and round are set to 1,
&nbsp; * the number of upper and lower cards is set to 0, and the game stage is set to {@code WAITING}.
&nbsp; */
<b class="fc">&nbsp; public CurrentState(){</b>
<b class="fc">&nbsp; this.player = null;</b>
<b class="fc">&nbsp; this.slot = null;</b>
<b class="fc">&nbsp; this.era = 1;</b>
<b class="fc">&nbsp; this.round = 1;</b>
<b class="fc">&nbsp; this.nUpper = 0;</b>
<b class="fc">&nbsp; this.nLower = 0;</b>
<b class="fc">&nbsp; this.gameStage = GameStages.WAITING;</b>
&nbsp; }
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Updates the current player, slot, and available draws.
&nbsp; * If {@code slot} is {@code null}, both {@link #nUpper} and {@link #nLower} are reset to 0.
&nbsp; * Otherwise, they are set from the slot&#39;s values.
&nbsp; *
&nbsp; * @param player the new current player.
&nbsp; * @param slot the new current slot, or {@code null} when no slot is active.
&nbsp; */
&nbsp; public void playerUpdate(Player player, Slot slot){
<b class="fc">&nbsp; this.player = player;</b>
<b class="fc">&nbsp; this.slot = slot;</b>
<b class="fc">&nbsp; if(slot == null){</b>
<b class="fc">&nbsp; this.nUpper = 0;</b>
<b class="fc">&nbsp; this.nLower = 0;</b>
&nbsp; }
&nbsp; else{
<b class="fc">&nbsp; this.nUpper = slot.getNUpper();</b>
<b class="fc">&nbsp; this.nLower = slot.getNLower();</b>
&nbsp; }
&nbsp;
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Returns a formatted ASCII table representation of the current game state.
&nbsp; * Columns: Player, Round, Era, GameStage.
&nbsp; *
&nbsp; * @return a {@code String} containing the ASCII table.
&nbsp; */
&nbsp; @Override
&nbsp; public String toString(){
<b class="nc">&nbsp; var table= new AsciiTable(BorderStyle.ROUNDED,4);</b>
<b class="nc">&nbsp; List&lt;String&gt;header= new ArrayList&lt;&gt;();</b>
<b class="nc">&nbsp; header.add(&quot;Player&quot;);</b>
<b class="nc">&nbsp; header.add(&quot;Round&quot;);</b>
<b class="nc">&nbsp; header.add(&quot;Era&quot;);</b>
<b class="nc">&nbsp; header.add(&quot;GameStage&quot;);</b>
<b class="nc">&nbsp; table.addRow(header);</b>
<b class="nc">&nbsp; table.addSeparator();</b>
<b class="nc">&nbsp; List&lt;String&gt;values= new ArrayList&lt;&gt;();</b>
<b class="nc">&nbsp; values.add(player.getUserName());</b>
<b class="nc">&nbsp; values.add(Integer.toString(round));</b>
<b class="nc">&nbsp; values.add(Integer.toString(era));</b>
<b class="nc">&nbsp; values.add(gameStage.toString());</b>
<b class="nc">&nbsp; table.addRow(values);</b>
<b class="nc">&nbsp; return table.build();</b>
&nbsp; }
&nbsp;}
</code>
</pre>
</div>
<script type="text/javascript">
(function() {
var msie = false, msie9 = false;
/*@cc_on
msie = true;
@if (@_jscript_version >= 9)
msie9 = true;
@end
@*/
if (!msie || msie && msie9) {
hljs.highlightAll()
hljs.initLineNumbersOnLoad();
}
})();
</script>
<div class="footer">
<div style="float:right;">generated on 2026-06-19 22:53</div>
</div>
</body>
</html>