358 lines
12 KiB
HTML
358 lines
12 KiB
HTML
|
|
|
|
|
|
<!DOCTYPE html>
|
|
<html id="htmlId">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
|
<title>Coverage Report > BuildingCard</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</a>
|
|
</div>
|
|
|
|
<h1>Coverage Summary for Class: BuildingCard (it.polimi.ingsw.gc14.Model.Cards)</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">BuildingCard</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
100%
|
|
</span>
|
|
<span class="absValue">
|
|
(1/1)
|
|
</span>
|
|
</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
92.9%
|
|
</span>
|
|
<span class="absValue">
|
|
(13/14)
|
|
</span>
|
|
</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
100%
|
|
</span>
|
|
<span class="absValue">
|
|
(25/25)
|
|
</span>
|
|
</td>
|
|
<td class="coverageStat">
|
|
<span class="percent">
|
|
97.7%
|
|
</span>
|
|
<span class="absValue">
|
|
(42/43)
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<br/>
|
|
<br/>
|
|
|
|
|
|
<pre>
|
|
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Model.Cards;
|
|
|
|
import it.polimi.ingsw.gc14.Model.Cards.Building.BuildingEffect;
|
|
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
|
import it.polimi.ingsw.gc14.Model.PlayableCard;
|
|
import it.polimi.ingsw.gc14.Model.Player;
|
|
|
|
import java.io.Serializable;
|
|
|
|
/**
|
|
* Represents a generic building card in the game.
|
|
*
|
|
* <p>A building card is a playable card with a price and a specific building
|
|
* effect. Concrete building cards extend this class to define their own
|
|
* behavior.
|
|
*/
|
|
public class BuildingCard extends PlayableCard implements Cloneable , BuildingEffect, Serializable {
|
|
|
|
/**
|
|
* The price of this building card.
|
|
*/
|
|
private final int price;
|
|
|
|
/**
|
|
* Returns the price of this building card.
|
|
*
|
|
* @return the price of this building card.
|
|
*/
|
|
public int getPrice() {
|
|
<b class="fc"> return price;</b>
|
|
}
|
|
|
|
/**
|
|
* Indicates whether this building card has already been bought.
|
|
*/
|
|
private boolean bought;
|
|
|
|
/**
|
|
* The type of effect associated with this building card.
|
|
*/
|
|
protected EffectType effectType;
|
|
|
|
/**
|
|
* The identifier of the effect associated with this building card.
|
|
*/
|
|
protected int effectId;
|
|
|
|
/**
|
|
* The prestige value of this building card.
|
|
*/
|
|
private final int prestigeValue;
|
|
|
|
/**
|
|
* Returns the prestige value of this building card.
|
|
*
|
|
* @return the prestige value of this building card.
|
|
*/
|
|
public int getPrestigeValue() {
|
|
<b class="fc"> return prestigeValue;</b>
|
|
}
|
|
|
|
/**
|
|
* Returns the identifier of the effect associated with this building card.
|
|
*
|
|
* @return the effect identifier of this building card.
|
|
*/
|
|
public int getEffectId() {
|
|
<b class="fc"> return effectId;</b>
|
|
}
|
|
|
|
/**
|
|
* Returns the type of effect associated with this building card.
|
|
*
|
|
* @return the effect type of this building card.
|
|
*/
|
|
public EffectType getEffectType() {
|
|
<b class="fc"> return effectType;</b>
|
|
}
|
|
|
|
/**
|
|
* Creates a building card with the specified era, price, and prestige value.
|
|
*
|
|
* @param era the era of the building card.
|
|
* @param price the price of the building card.
|
|
* @param prestigeValue the prestige value of the building card.
|
|
* @throws IllegalArgumentException if {@code price <= 0} or {@code prestigeValue < 0}
|
|
*/
|
|
protected BuildingCard(int era,int price,int prestigeValue) throws IllegalArgumentException{
|
|
<b class="fc"> super(era);</b>
|
|
<b class="fc"> if (price > 0) {</b>
|
|
<b class="fc"> this.price = price;</b>
|
|
} else {
|
|
<b class="fc"> throw new IllegalArgumentException();</b>
|
|
}
|
|
<b class="fc"> if (prestigeValue >= 0) {</b>
|
|
<b class="fc"> this.prestigeValue = prestigeValue;</b>
|
|
} else {
|
|
<b class="fc"> throw new IllegalArgumentException();</b>
|
|
}
|
|
|
|
<b class="fc"> bought = false;</b>
|
|
}
|
|
|
|
/**
|
|
* Creates a building card with the specified image identifier, era, price,
|
|
* and prestige value.
|
|
*
|
|
* @param idIMG the image identifier of the building card.
|
|
* @param era the era of the building card.
|
|
* @param price the price of the building card.
|
|
* @param prestigeValue the prestige value of the building card.
|
|
* @throws IllegalArgumentException if {@code price <= 0} or {@code prestigeValue < 0}
|
|
*/
|
|
protected BuildingCard(String idIMG,int era,int price,int prestigeValue) throws IllegalArgumentException{
|
|
<b class="fc"> super(idIMG,era);</b>
|
|
<b class="fc"> if (price > 0) {</b>
|
|
<b class="fc"> this.price = price;</b>
|
|
} else {
|
|
<b class="fc"> throw new IllegalArgumentException();</b>
|
|
}
|
|
<b class="fc"> if (prestigeValue >= 0) {</b>
|
|
<b class="fc"> this.prestigeValue = prestigeValue;</b>
|
|
} else {
|
|
<b class="fc"> throw new IllegalArgumentException();</b>
|
|
}
|
|
|
|
<b class="fc"> bought = false;</b>
|
|
}
|
|
|
|
|
|
/**
|
|
* Creates a building card with the specified effect identifier, era, price,
|
|
* and prestige value.
|
|
* The effect type is determined from the given effect identifier.
|
|
*
|
|
* @param effectId the identifier of the effect associated with the building card.
|
|
* @param era the era of the building card.
|
|
* @param price the price of the building card.
|
|
* @param prestigeValue the prestige value of the building card.
|
|
* @throws IllegalArgumentException if the effect identifier is not valid,
|
|
* if {@code price <= 0}, or if {@code prestigeValue < 0}
|
|
*/
|
|
public BuildingCard(int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
|
|
<b class="fc"> this(era, price, prestigeValue);</b>
|
|
<b class="fc"> this.effectType = effectTypeFromId(effectId);</b>
|
|
<b class="fc"> this.effectId = effectId;</b>
|
|
}
|
|
|
|
/**
|
|
* Creates a building card with the specified image id, effect identifier, era,
|
|
* price, and prestige value.
|
|
*
|
|
* <p>The effect type is determined from the given effect identifier.
|
|
*
|
|
* @param idIMG the image identifier of the building card.
|
|
* @param effectId the identifier of the effect associated with the building card.
|
|
* @param era the era of the building card.
|
|
* @param price the price of the building card.
|
|
* @param prestigeValue the prestige value of the building card.
|
|
* @throws IllegalArgumentException if the effect identifier is not valid,
|
|
* if {@code price <= 0}, or if {@code prestigeValue < 0}.
|
|
*/
|
|
public BuildingCard(String idIMG, int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
|
|
<b class="fc"> this(idIMG, era, price, prestigeValue);</b>
|
|
<b class="fc"> this.effectType = effectTypeFromId(effectId);</b>
|
|
<b class="fc"> this.effectId = effectId;</b>
|
|
}
|
|
/**
|
|
* Maps a building effect identifier to its corresponding {@link EffectType}.
|
|
*
|
|
* @param effectId the effect identifier to resolve.
|
|
* @return the {@link EffectType} for the given identifier.
|
|
* @throws IllegalArgumentException if {@code effectId} does not correspond to any known effect type.
|
|
*/
|
|
private static EffectType effectTypeFromId(int effectId) {
|
|
<b class="fc"> switch (effectId) {</b>
|
|
<b class="fc"> case 2, 9, 7, 6, 5: return EffectType.ON_EVENT;</b>
|
|
<b class="fc"> case 3: return EffectType.ON_END_TURN;</b>
|
|
<b class="fc"> case 12: return EffectType.ON_ROUND_END;</b>
|
|
<b class="fc"> default: throw new IllegalArgumentException();</b>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates and returns a copy of this building card.
|
|
*
|
|
* @return a clone of this building card.
|
|
*/
|
|
@Override
|
|
public BuildingCard clone()
|
|
{
|
|
<b class="fc"> return new BuildingCard(getIdIMG(),effectId,getEra(),getPrice(),getPrestigeValue());</b>
|
|
}
|
|
|
|
/**
|
|
* Attempts to buy this building card for the specified player.
|
|
*
|
|
* <p>The effective cost is reduced by the total reduction value provided
|
|
* by the player's Builder cards, without dropping below zero. The purchase
|
|
* succeeds only if the card has not already been bought and the player can
|
|
* pay the resulting amount of Food. If successful, the card is added to
|
|
* the player's building cards and marked as bought.
|
|
*
|
|
* @param player the player attempting to buy the building card.
|
|
* @return {@code true} if the building card is successfully bought,
|
|
* {@code false} otherwise.
|
|
*/
|
|
public boolean buy(Player player) {
|
|
<b class="fc"> int discount = player.getBuilders().stream().mapToInt(x -> x.getReductionValue()).sum();</b>
|
|
|
|
<b class="fc"> if(discount > this.price){</b>
|
|
<b class="fc"> discount = this.price;</b>
|
|
}
|
|
|
|
<b class="fc"> if(bought || !player.removeFood(this.price - discount))</b>
|
|
<b class="fc"> return false;</b>
|
|
<b class="fc"> player.getBuildingCards().add(this);</b>
|
|
<b class="fc"> bought=true;</b>
|
|
<b class="fc"> return true;</b>
|
|
}
|
|
|
|
/**
|
|
* Default implementation of the building effect.
|
|
*
|
|
* <p>This method does not perform any operation and can be overridden
|
|
* by specific building cards that define an active effect.
|
|
*
|
|
* @param player the player to whom the effect may be applied.
|
|
*/
|
|
<b class="fc"> public void applyEffect(Player player) {}</b>
|
|
|
|
@Override
|
|
public String toStringBoard() {
|
|
<b class="fc"> return "ID:" + getEffectId() + " \uD83C\uDF56:" + getPrice() + " \uD83C\uDFC5:" + getPrestigeValue();</b>
|
|
}
|
|
|
|
@Override
|
|
public String toStringPlayer() {
|
|
<b class="nc"> return "ID:" + getEffectId();</b>
|
|
}
|
|
}
|
|
</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>
|