Fix: full controller refactor

This commit is contained in:
2026-06-14 13:00:36 +02:00
parent 85f2dd9208
commit b11027a251
20 changed files with 175 additions and 189 deletions
@@ -23,7 +23,7 @@ public class Building0 extends BuildingCard {
* Indicates whether the building effect has already been initialized
* after purchase.
*/
boolean purchased ;
private boolean purchased;
/**
* Number of complete character sets already counted by this building effect.
@@ -143,6 +143,6 @@ public class Building0 extends BuildingCard {
}
player.addFood(FOOD_PER_CHARACTER_SET *(min_temp-numSet));
numSet=min_temp;
};
}
}
@@ -15,17 +15,20 @@ import it.polimi.ingsw.gc14.Model.Player;
public class Building11 extends BuildingCard {
/**
* The icon attribute indicates the character type involved in the building effect.
* The character type involved in this building effect.
*/
private CharacterType icon ;
private CharacterType characterType;
/**
* Returns the CharacterType associated with this building card effect.
*
* @return the CharacterType associated with this building card effect.
*/
public CharacterType getIcon() {return icon;}
public CharacterType getIcon() { return characterType; }
/**
* The prestige multiplier applied per matching character card at end of game.
*/
private int prestigeMul;
/**
@@ -49,7 +52,7 @@ public class Building11 extends BuildingCard {
super(era,price,prestigeValue);
effectType = EffectType.FINAL;
effectId = 11;
this.icon = icon;
this.characterType = icon;
this.prestigeMul = prestigeMul;
}
@@ -68,7 +71,7 @@ public class Building11 extends BuildingCard {
super(idIMG,era,price,prestigeValue);
effectType = EffectType.FINAL;
effectId = 11;
this.icon = icon;
this.characterType = icon;
this.prestigeMul = prestigeMul;
}
@@ -105,11 +108,11 @@ public class Building11 extends BuildingCard {
*/
@Override
public String toString() {
return super.toString() + "+" + this.icon.toString().substring(0, 3) + "×" + this.prestigeMul;
return super.toString() + "+" + this.characterType.toString().substring(0, 3) + "×" + this.prestigeMul;
}
@Override
public String toStringPlayer() {
return super.toStringPlayer() + " (\uD83C\uDFC5:" + this.icon.toString().substring(0, 3) + "×" + this.prestigeMul + ")";
return super.toStringPlayer() + " (\uD83C\uDFC5:" + this.characterType.toString().substring(0, 3) + "×" + this.prestigeMul + ")";
}
}
@@ -23,12 +23,12 @@ public class Building4 extends BuildingCard {
* Indicates whether the building effect has already been initialized
* after purchase.
*/
boolean purchased ;
private boolean purchased;
/**
* Number of inventor pairs already counted by this building effect.
*/
int numPair;
private int numPair;
/**
* Creates a building with the specified era, price and prestige value.
@@ -154,5 +154,5 @@ public class Building4 extends BuildingCard {
}
player.addFood(FOOD_PER_INVENTOR_PAIR *(temp-numPair));
numPair = temp;
};
}
}
@@ -140,34 +140,9 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @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{
this(era,price,prestigeValue);
switch (effectId){
case 2:
this.effectType=EffectType.ON_EVENT;
break;
case 3:
this.effectType=EffectType.ON_END_TURN;
break;
case 5:
this.effectType=EffectType.ON_EVENT;
break;
case 6:
this.effectType=EffectType.ON_EVENT;
break;
case 7:
this.effectType=EffectType.ON_EVENT;
break;
case 9:
this.effectType=EffectType.ON_EVENT;
break;
case 12:
this.effectType=EffectType.ON_ROUND_END;
break;
default:
throw new IllegalArgumentException();
}
public BuildingCard(int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
this(era, price, prestigeValue);
this.effectType = effectTypeFromId(effectId);
this.effectId = effectId;
}
@@ -185,37 +160,25 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @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{
this(idIMG,era,price,prestigeValue);
switch (effectId){
case 2:
this.effectType=EffectType.ON_EVENT;
break;
case 3:
this.effectType=EffectType.ON_END_TURN;
break;
case 5:
this.effectType=EffectType.ON_EVENT;
break;
case 6:
this.effectType=EffectType.ON_EVENT;
break;
case 7:
this.effectType=EffectType.ON_EVENT;
break;
case 9:
this.effectType=EffectType.ON_EVENT;
break;
case 12:
this.effectType=EffectType.ON_ROUND_END;
break;
default:
throw new IllegalArgumentException();
}
public BuildingCard(String idIMG, int effectId, int era, int price, int prestigeValue) throws IllegalArgumentException {
this(idIMG, era, price, prestigeValue);
this.effectType = effectTypeFromId(effectId);
this.effectId = effectId;
}
private static EffectType effectTypeFromId(int effectId) {
switch (effectId) {
case 2: return EffectType.ON_EVENT;
case 3: return EffectType.ON_END_TURN;
case 5: return EffectType.ON_EVENT;
case 6: return EffectType.ON_EVENT;
case 7: return EffectType.ON_EVENT;
case 9: return EffectType.ON_EVENT;
case 12: return EffectType.ON_ROUND_END;
default: throw new IllegalArgumentException();
}
}
/**
* Creates and returns a copy of this building card.
*
@@ -240,10 +203,8 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @return {@code true} if the building card is successfully bought,
* {@code false} otherwise.
*/
// sum reduction value builder=> sconto
public boolean buy(Player player) {
int discount = 0;
discount = player.getBuilders().stream().mapToInt(x -> x.getReductionValue()).sum();
int discount = player.getBuilders().stream().mapToInt(x -> x.getReductionValue()).sum();
if(discount > this.price){
discount = this.price;
@@ -265,7 +226,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
* @param player the player to whom the effect may be applied.
*/
@Override
public void applyEffect(Player player){};
public void applyEffect(Player player) {}
/**
* Returns the string representation of this building card.
@@ -274,9 +235,14 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
*/
@Override
public String toString() {
return ":" + " ID:" + getEffectId()+ " \uD83C\uDF56:"+String.valueOf(getPrice())+" \uD83C\uDFC5:"+String.valueOf(getPrestigeValue());
return ":" + " ID:" + getEffectId() + " \uD83C\uDF56:" + getPrice() + " \uD83C\uDFC5:" + getPrestigeValue();
}
/**
* Returns a compact player-view string representation of this building card.
*
* @return a compact string showing the effect identifier.
*/
public String toStringPlayer() {
return "ID:" + getEffectId();
}
@@ -12,8 +12,6 @@ import java.util.ArrayList;
*/
public abstract class EventCard extends TribeCard {
// Getters
/**
* The specific type of this event card.
*/
@@ -26,18 +24,14 @@ public abstract class EventCard extends TribeCard {
*/
public EventType getType() { return type; }
// End getters
// Constructors
/**
* Creates an event card with the specified era and event type.
*
* @param Era the era of the event card.
* @param era the era of the event card.
* @param type the type of the event card.
*/
public EventCard(int Era, EventType type) {
super(Era,true);
public EventCard(int era, EventType type) {
super(era, true);
this.type = type;
}
@@ -45,16 +39,13 @@ public abstract class EventCard extends TribeCard {
* Creates an event card with the specified image id, era and event type.
*
* @param idIMG the image identifier of the event card.
* @param Era the era of the event card.
* @param era the era of the event card.
* @param type the type of the event card.
*/
public EventCard(String idIMG,int Era, EventType type) {
super(idIMG,Era,true);
public EventCard(String idIMG, int era, EventType type) {
super(idIMG, era, true);
this.type = type;
}
// End Constructors
// Function
/**
* Creates and returns a copy of this event card.
@@ -98,5 +89,4 @@ public abstract class EventCard extends TribeCard {
*/
public abstract void activateEvent (ArrayList <Player> playerList);
// End Functions
}
@@ -13,11 +13,13 @@ import java.util.ArrayList;
* @see EventCard
*/
public class Hunt extends EventCard {
/** Food points multiplier used during the event. */
int foodMultiplier;
/** Base food units granted per Hunter. Always 1; increased by Building 7. */
private static final int BASE_FOOD_PER_HUNTER = 1;
/** Prestige Points multiplier used during the event. */
int prestigeMultiplier;
private int prestigeMultiplier;
int getPrestigeMultiplier() { return prestigeMultiplier; }
/**
* Creates a new Hunt event card.
@@ -27,7 +29,6 @@ public class Hunt extends EventCard {
*/
public Hunt(int Era, int prestigeMultiplier) {
super(Era, EventType.HUNT);
this.foodMultiplier = 1;
this.prestigeMultiplier = prestigeMultiplier;
}
@@ -38,24 +39,24 @@ public class Hunt extends EventCard {
* @param Era the era of the card.
* @param prestigeMultiplier the prestige points multiplier used during the event.
*/
public Hunt(String idIMG,int Era, int prestigeMultiplier) {
super(idIMG,Era, EventType.HUNT);
this.foodMultiplier = 1;
public Hunt(String idIMG, int Era, int prestigeMultiplier) {
super(idIMG, Era, EventType.HUNT);
this.prestigeMultiplier = prestigeMultiplier;
}
/**
* Activates the event card "Hunt".
* Each player takes 1 Food and gains Prestige Points for each Hunter in their tribe.
* Each player gains Food and Prestige Points for each Hunter in their tribe,
* multiplied by the respective multipliers (base food per hunter is 1).
* Buildings influence:
* Building 7: the player takes 1 Food and 1 additional Prestige Point for each Hunter.
* Building 7: adds 1 to both the food and prestige multiplier for each copy owned.
*
* @param playerList the list of all players in the game.
*/
@Override
public void activateEvent (ArrayList <Player> playerList){
for (Player player : playerList) {
int tmpFoodMultiplier = foodMultiplier;
int tmpFoodMultiplier = BASE_FOOD_PER_HUNTER;
int tmpPrestigeMultiplier = prestigeMultiplier;
ArrayList <BuildingCard> buildingList = player.getBuildingCards();
@@ -19,10 +19,14 @@ public class ShamanicRitual extends EventCard {
private static final int BUILDING5_BONUS_ICONS = 3;
/** Prestige points awarded to the player with the most shaman icons. */
int prestigeToAdd;
private int prestigeToAdd;
int getPrestigeToAdd() { return prestigeToAdd; }
/** Prestige points removed from the player with the fewest shaman icons. */
int prestigeToRemove;
private int prestigeToRemove;
int getPrestigeToRemove() { return prestigeToRemove; }
/**
* Creates a new ShamanicRitual event card.
@@ -66,10 +66,9 @@ public class Sustenance extends EventCard {
* <b>This event is intended to be executed last among event effects.</b>
*
* @param playerList the list of players affected by the event.
* @throws NullPointerException if {@code playerList} or one of its required elements is {@code null}.
*/
@Override
public void activateEvent (ArrayList <Player> playerList) throws NullPointerException {
public void activateEvent (ArrayList <Player> playerList) {
for(Player player : playerList){
int nChar = player.getTotCharacters();
int nGatherers = player.getNType(CharacterType.GATHERER);