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

264 lines
8.2 KiB
HTML

<!DOCTYPE html>
<html id="htmlId">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Coverage Report > Building0</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.Building.Effects</a>
</div>
<h1>Coverage Summary for Class: Building0 (it.polimi.ingsw.gc14.Model.Cards.Building.Effects)</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">Building0</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">
(6/6)
</span>
</td>
<td class="coverageStat">
<span class="percent">
81.2%
</span>
<span class="absValue">
(13/16)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(30/30)
</span>
</td>
</tr>
</table>
<br/>
<br/>
<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package it.polimi.ingsw.gc14.Model.Cards.Building.Effects;
&nbsp;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
&nbsp;import it.polimi.ingsw.gc14.Model.Player;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
&nbsp;
&nbsp;
&nbsp;
&nbsp;/**
&nbsp; * Building effect that grants 5 food for each new complete set of
&nbsp; * 6 different character types obtained after purchasing this building.
&nbsp; *
&nbsp; * &lt;p&gt;Character sets already completed before the building is purchased
&nbsp; * are stored during initialization and do not provide food.
&nbsp; */
&nbsp;public class Building0 extends BuildingCard {
&nbsp;
&nbsp; /** Food units granted per newly completed character set. */
&nbsp; private static final int FOOD_PER_CHARACTER_SET = 5;
&nbsp;
&nbsp; /**
&nbsp; * Indicates whether the building effect has already been initialized
&nbsp; * after purchase.
&nbsp; */
&nbsp; private boolean purchased;
&nbsp;
&nbsp; /**
&nbsp; * Number of complete character sets already counted by this building effect.
&nbsp; */
&nbsp; private int numSet;
&nbsp;
&nbsp; /**
&nbsp; * Creates a building with the specified image identifier, era, price
&nbsp; * and prestige value.
&nbsp; *
&nbsp; * @param idImage the image identifier of the building.
&nbsp; * @param era the game era of the building.
&nbsp; * @param price the price in food of the building.
&nbsp; * @param prestigeValue the number of Prestige Points granted by this building
&nbsp; * at the end of the game.
&nbsp; */
&nbsp; public Building0(String idImage,int era,int price,int prestigeValue) {
<b class="fc">&nbsp; super(idImage,era,price,prestigeValue);</b>
<b class="fc">&nbsp; effectType=EffectType.CARD_SET;</b>
<b class="fc">&nbsp; effectId=0;</b>
<b class="fc">&nbsp; purchased = false;</b>
<b class="fc">&nbsp; numSet = 0;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Creates a building with the specified era, price and prestige value.
&nbsp; *
&nbsp; * @param era the game era of the building.
&nbsp; * @param price the price in food of the building.
&nbsp; * @param prestigeValue the number of Prestige Points granted by this building
&nbsp; * at the end of the game.
&nbsp; */
&nbsp; public Building0(int era,int price,int prestigeValue) {
<b class="fc">&nbsp; super(era,price,prestigeValue);</b>
<b class="fc">&nbsp; effectType=EffectType.CARD_SET;</b>
<b class="fc">&nbsp; effectId=0;</b>
<b class="fc">&nbsp; purchased = false;</b>
<b class="fc">&nbsp; numSet = 0;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Attempts to purchase the building and initializes its effect if the
&nbsp; * purchase succeeds.
&nbsp; *
&nbsp; * @param player the player who attempts to buy the building.
&nbsp; * @return {@code true} if the building is successfully purchased and initialized,
&nbsp; * {@code false} otherwise.
&nbsp; */
&nbsp; @Override
&nbsp; public boolean buy(Player player)
&nbsp; {
<b class="fc">&nbsp; if(!super.buy(player))</b>
<b class="fc">&nbsp; return false;</b>
<b class="fc">&nbsp; initialize(player);</b>
<b class="fc">&nbsp; return true;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Initializes the building effect by storing the number of complete
&nbsp; * character sets already owned by the player at the moment of purchase.
&nbsp; *
&nbsp; * &lt;p&gt;The initialization is performed only once.
&nbsp; *
&nbsp; * @param player the player who owns the building.
&nbsp; */
&nbsp; public void initialize(Player player)
&nbsp; {
<b class="pc">&nbsp; if(purchased)</b>
&nbsp; {
&nbsp; return;
&nbsp; }
<b class="fc">&nbsp; numSet=player.getNType(CharacterType.INVENTOR);</b>
<b class="fc">&nbsp; for(CharacterType type : CharacterType.values())</b>
&nbsp; {
<b class="pc">&nbsp; if(player.getNType(type)&lt;=numSet)</b>
<b class="fc">&nbsp; numSet=player.getNType(type);</b>
&nbsp; }
<b class="fc">&nbsp; purchased = true;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Creates a new building instance with the same configuration values
&nbsp; * as this card.
&nbsp; *
&nbsp; * &lt;p&gt;The runtime state of the effect, such as initialization status and
&nbsp; * counted character sets, is not copied.
&nbsp; *
&nbsp; * @return a new building card with the same base properties.
&nbsp; */
&nbsp; @Override
&nbsp; public BuildingCard clone() {
<b class="fc">&nbsp; return new Building0(getIdIMG(),getEra(),getPrice(),getPrestigeValue());</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Applies the building effect to the specified player.
&nbsp; *
&nbsp; * &lt;p&gt;The method counts the complete character sets currently owned by the player
&nbsp; * and grants 5 food for each set completed since the last stored value.
&nbsp; *
&nbsp; * @param player the player who owns the building.
&nbsp; * @throws IllegalArgumentException if the specified player does not own this card.
&nbsp; */
&nbsp; public void applyEffect(Player player) throws IllegalArgumentException {
<b class="fc">&nbsp; if(!player.getBuildingCards().contains(this))</b>
<b class="fc">&nbsp; throw new IllegalArgumentException();</b>
<b class="fc">&nbsp; int min_temp=player.getNType(CharacterType.INVENTOR);</b>
<b class="fc">&nbsp; for(CharacterType type : CharacterType.values())</b>
&nbsp; {
<b class="pc">&nbsp; if(player.getNType(type)&lt;=min_temp)</b>
<b class="fc">&nbsp; min_temp=player.getNType(type);</b>
&nbsp; }
<b class="fc">&nbsp; if(min_temp&lt;=numSet)</b>
&nbsp; {
&nbsp; return;
&nbsp; }
<b class="fc">&nbsp; player.addFood(FOOD_PER_CHARACTER_SET *(min_temp-numSet));</b>
<b class="fc">&nbsp; numSet=min_temp;</b>
&nbsp; }
&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>