Coverage Summary for Class: CavePaintings (it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
| CavePaintings |
100%
(1/1)
|
100%
(6/6)
|
100%
(8/8)
|
100%
(22/22)
|
package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
import it.polimi.ingsw.gc14.Model.Player;
import java.util.ArrayList;
/**
* Represents a Cave Paintings event card.
*
* <p>This class defines the specific behavior of the Cave Paintings event.
*/
public class CavePaintings extends EventCard {
/**
* The minimum number of Artist cards required to avoid the prestige penalty.
* Also, the bottom number on the card.
*/
private final int nLower;
/**
* The amount of Prestige removed if the player has fewer Artist cards than {@code nLower}.
*/
private final int nPrestigeRem;
/**
* The Prestige multiplier applied if the player has at least {@code nLower} Artist cards.
*/
private final int nPrestigeMul;
/**
* Creates a CavePaintings event card with the specified era and effect parameters.
*
* @param Era the era of the event card.
* @param nLower the minimum number of Artist cards required to avoid the prestige penalty.
* @param nPrestigeRem the amount of Prestige removed if the player has fewer Artist cards than {@code nLower}.
* @param nPrestigeMul the Prestige multiplier applied if the player has at least {@code nLower} Artist cards.
*/
public CavePaintings(int Era, int nLower, int nPrestigeRem, int nPrestigeMul) {
super(Era, EventType.CAVE_PAINTINGS);
this.nLower = nLower;
this.nPrestigeRem = nPrestigeRem;
this.nPrestigeMul = nPrestigeMul;
}
/**
* Creates a CavePaintings event card with the specified image id, era and effect parameters.
*
* @param idIMG the image identifier of the CavePaintings event card.
* @param Era the era of the event card.
* @param nLower the minimum number of Artist cards required to avoid the prestige penalty.
* @param nPrestigeRem the amount of Prestige removed if the player has fewer Artist cards than {@code nLower}.
* @param nPrestigeMul the Prestige multiplier applied if the player has at least {@code nLower} Artist cards.
*/
public CavePaintings(String idIMG,int Era, int nLower, int nPrestigeRem, int nPrestigeMul) {
super(idIMG,Era, EventType.CAVE_PAINTINGS);
this.nLower = nLower;
this.nPrestigeRem = nPrestigeRem;
this.nPrestigeMul = nPrestigeMul;
}
/**
* Activates the CavePaintings event for the specified list of players.
* For each player, the number of Artist cards is computed together with the number
* of owned building cards having effect id equal to 9.
* The player gains Food equal to the number of such buildings multiplied by the number of Artist cards.
* If the player has fewer Artist cards than {@code nLower}, the player loses {@code nPrestigeRem} Prestige.
* Otherwise, the player gains Prestige equal to {@code nPrestigeMul} multiplied by the number of Artist cards.
*
* @param playerList the list of players affected by the event.
*/
@Override
public void activateEvent (ArrayList <Player> playerList){
for (Player player : playerList){
int nArtists = player.getNType(CharacterType.ARTIST);
int nBuildings = 0;
ArrayList<BuildingCard> buildingCards = player.getBuildingCards();
for(BuildingCard card : buildingCards){
if(card.getEffectId() == 9){
nBuildings++;
}
}
player.addFood(nBuildings * nArtists);
if (nArtists < nLower){
player.removePrestige(nPrestigeRem);
}
else{
player.addPrestige(nPrestigeMul * nArtists);
}
}
}
/**
* Creates and returns a copy of this CavePaintings event card.
*
* @return a clone of this CavePaintings event card.
*/
@Override
public EventCard clone()
{
return new CavePaintings(getIdIMG(),getEra(), nLower, nPrestigeRem, nPrestigeMul) ;
}
/**
* Prints a string representation of this {@code TribeCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version.
* <p>NOTE: {@code NUpper} is not a real attribute used in calculations (only {@code nLower} is needed),
* however it's a parameter on the cards' design.
* </p>
* <p>Includes:
* <li>{@link #nLower}
* <li>{@code NUpper}
* <li>{@link #nPrestigeRem}
* <li>{@link #nPrestigeMul}
* </p>
* @return {@code String} - a string representation of this {@code TribeCard}.
* @see it.polimi.ingsw.gc14.Model.Cards.TribeCard TribeCard
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@Override
public String toStringPlayer() {
return "CAVE_PAINTINGS";
}
@Override
public String toStringBoard() {
return "\033[38;5;180mCAVE_PAINTINGS 0-" + (nLower-1) + ":" + nPrestigeRem + " " + nLower + "+:" + nPrestigeMul + "\033[0m";
}
}