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

248 lines
8.0 KiB
HTML

<!DOCTYPE html>
<html id="htmlId">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Coverage Report > Sustenance</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.Cards.TribeCards.Events</a>
</div>
<h1>Coverage Summary for Class: Sustenance (it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events)</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">Sustenance</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(1/1)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(7/7)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(10/10)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(23/23)
</span>
</td>
</tr>
</table>
<br/>
<br/>
<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;
&nbsp;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building1;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
&nbsp;import it.polimi.ingsw.gc14.Model.Player;
&nbsp;import java.util.ArrayList;
&nbsp;
&nbsp;/**
&nbsp; * Represents a Sustenance event card.
&nbsp; *
&nbsp; * &lt;p&gt;This class defines the specific behavior of the Sustenance event.
&nbsp; */
&nbsp;public class Sustenance extends EventCard {
&nbsp;
&nbsp; /** Food units covered by each Gatherer during the Sustenance event. */
&nbsp; private static final int FOOD_PER_GATHERER = 3;
&nbsp;
&nbsp; /**
&nbsp; * The prestige penalty multiplier applied for each unpaid Food unit.
&nbsp; */
&nbsp; private final int prestigeDebt;
&nbsp;
&nbsp; /**
&nbsp; * Returns the prestige penalty multiplier associated with this Sustenance event.
&nbsp; *
&nbsp; * @return the prestige penalty multiplier associated with this Sustenance event.
&nbsp; */
&nbsp; public int getPrestigeDebt() {
<b class="fc">&nbsp; return prestigeDebt;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Creates a Sustenance event card with the specified era and prestige debt value.
&nbsp; *
&nbsp; * @param Era the era of the event card.
&nbsp; * @param prestigeDebt the prestige penalty multiplier for unpaid Food units.
&nbsp; */
&nbsp; public Sustenance(int Era, int prestigeDebt) {
<b class="fc">&nbsp; super(Era, EventType.SUSTENANCE);</b>
<b class="fc">&nbsp; this.prestigeDebt = prestigeDebt;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Creates a Sustenance event card with the specified image id, era and prestige debt value.
&nbsp; *
&nbsp; * @param idIMG the image identifier of the Sustenance event card.
&nbsp; * @param Era the era of the event card.
&nbsp; * @param prestigeDebt the prestige penalty multiplier for unpaid Food units.
&nbsp; */
&nbsp; public Sustenance(String idIMG,int Era, int prestigeDebt) {
<b class="fc">&nbsp; super(idIMG,Era, EventType.SUSTENANCE);</b>
<b class="fc">&nbsp; this.prestigeDebt = prestigeDebt;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Activates the Sustenance event for the specified list of players.
&nbsp; * For each player, the required Food is computed from the total number of characters,
&nbsp; * reduced by the contribution of Gatherers and by any applicable character discounts
&nbsp; * granted by owned building cards with effect id equal to 1.
&nbsp; * If the resulting Food debt is positive, the player must pay it with available Food.
&nbsp; * If the player does not have enough Food, all remaining Food is removed and the player
&nbsp; * loses Prestige equal to the unpaid Food debt multiplied by {@code prestigeDebt}.
&nbsp; * &lt;b&gt;This event is intended to be executed last among event effects.&lt;/b&gt;
&nbsp; *
&nbsp; * @param playerList the list of players affected by the event.
&nbsp; */
&nbsp; @Override
&nbsp; public void activateEvent (ArrayList &lt;Player&gt; playerList) {
<b class="fc">&nbsp; for(Player player : playerList){</b>
<b class="fc">&nbsp; int nChar = player.getTotCharacters();</b>
<b class="fc">&nbsp; int nGatherers = player.getNType(CharacterType.GATHERER);</b>
&nbsp;
<b class="fc">&nbsp; int nCharDiscount = 0;</b>
<b class="fc">&nbsp; for(BuildingCard b : player.getBuildingCards()){</b>
<b class="fc">&nbsp; if(b.getEffectId() == 1){</b>
<b class="fc">&nbsp; CharacterType c = ((Building1)b).getIcon();</b>
<b class="fc">&nbsp; nCharDiscount += player.getNType(c);</b>
&nbsp; }
&nbsp; }
&nbsp;
&nbsp;
<b class="fc">&nbsp; int foodDebt = nChar - (FOOD_PER_GATHERER * nGatherers + nCharDiscount);</b>
&nbsp;
<b class="fc">&nbsp; if(foodDebt &lt;= 0){</b>
&nbsp; continue;
&nbsp; }
<b class="fc">&nbsp; if(player.getFoodValue() &gt;= foodDebt){</b>
<b class="fc">&nbsp; player.removeFood(foodDebt);</b>
&nbsp; }
&nbsp; else{
<b class="fc">&nbsp; foodDebt -= player.getFoodValue();</b>
<b class="fc">&nbsp; player.removeFood(player.getFoodValue());</b>
<b class="fc">&nbsp; player.removePrestige(foodDebt * prestigeDebt);</b>
&nbsp; }
&nbsp; }
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Creates and returns a copy of this Sustenance event card.
&nbsp; *
&nbsp; * @return a clone of this Sustenance event card.
&nbsp; */
&nbsp; @Override
&nbsp; public EventCard clone() {
<b class="fc">&nbsp; return new Sustenance(getIdIMG(),getEra(), prestigeDebt);</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}&#39;s
&nbsp; * toString to print a more detailed version.
&nbsp; * &lt;p&gt;Includes:
&nbsp; * &lt;li&gt;{@link #prestigeDebt}
&nbsp; * &lt;/p&gt;
&nbsp; * @return {@code String} - a string representation of this {@code TribeCard}.
&nbsp; * @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
&nbsp; * @see it.polimi.ingsw.gc14.Model.Game Game
&nbsp; * @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
&nbsp; */
&nbsp; @Override
&nbsp; public String toStringPlayer() {
<b class="fc">&nbsp; return &quot;SUSTENANCE&quot;;</b>
&nbsp; }
&nbsp;
&nbsp; @Override
&nbsp; public String toStringBoard() {
<b class="fc">&nbsp; return &quot;\033[38;5;180mSUSTENANCE -1\uD83C\uDF56/-&quot; + prestigeDebt + &quot;\uD83C\uDFC5\033[0m&quot;;</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>