Fix: public access now are private with setter/getter

This commit is contained in:
2026-06-09 21:06:51 +02:00
parent 3318801913
commit cbf6cb3c5b
43 changed files with 351 additions and 336 deletions
@@ -126,7 +126,7 @@ public class Building0 extends BuildingCard {
*/
@Override
public void applyEffect(Player player) throws IllegalArgumentException {
if(!player.buildingCards.contains(this))
if(!player.getBuildingCards().contains(this))
throw new IllegalArgumentException();
int min_temp=player.getNType(CharacterType.INVENTOR);
for(CharacterType type : CharacterType.values())
@@ -64,7 +64,7 @@ public class Building10 extends BuildingCard {
*/
@Override
public void applyEffect(Player player) throws IllegalArgumentException {
if(!player.buildingCards.contains(this))
if(!player.getBuildingCards().contains(this))
throw new IllegalArgumentException();
HashMap<CharacterType,Integer> map = new HashMap<CharacterType,Integer>();
@@ -92,7 +92,7 @@ public class Building11 extends BuildingCard {
*/
@Override
public void applyEffect(Player player) throws IllegalArgumentException {
if(!player.buildingCards.contains(this))
if(!player.getBuildingCards().contains(this))
throw new IllegalArgumentException();
player.addPrestige(player.getNType(getIcon()) * this.getPrestigeMul());
}
@@ -56,7 +56,7 @@ public class Building13 extends BuildingCard{
*/
@Override
public void applyEffect(Player player) throws IllegalArgumentException {
if(!player.buildingCards.contains(this))
if(!player.getBuildingCards().contains(this))
throw new IllegalArgumentException();
player.addPrestige(25);
}
@@ -74,7 +74,7 @@ public class Building4 extends BuildingCard {
{
map.put(i,0);
}
for(Inventor inv : player.inventors)
for(Inventor inv : player.getInventors())
{
map.merge(inv.Icon(),1,Integer::sum);
}
@@ -129,14 +129,14 @@ public class Building4 extends BuildingCard {
*/
@Override
public void applyEffect(Player player) throws IllegalArgumentException {
if(!player.buildingCards.contains(this))
if(!player.getBuildingCards().contains(this))
throw new IllegalArgumentException();
HashMap<Integer,Integer> map = new HashMap<>();
for(int i=0;i<10;i++)
{
map.put(i,0);
}
for(Inventor inv : player.inventors)
for(Inventor inv : player.getInventors())
{
map.merge(inv.Icon(),1,Integer::sum);
}
@@ -57,9 +57,9 @@ public class Building8 extends BuildingCard {
*/
@Override
public void applyEffect(Player player) throws IllegalArgumentException {
if(!player.buildingCards.contains(this))
if(!player.getBuildingCards().contains(this))
throw new IllegalArgumentException();
for (Builder builder : player.builders) {
for (Builder builder : player.getBuilders()) {
player.addPrestige(builder.getPrestigeValue());
}
}
@@ -243,7 +243,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
// sum reduction value builder=> sconto
public boolean buy(Player player) {
int discount = 0;
discount = player.builders.stream().mapToInt(x -> x.getReductionValue()).sum();
discount = player.getBuilders().stream().mapToInt(x -> x.getReductionValue()).sum();
if(discount > this.price){
discount = this.price;
@@ -251,7 +251,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
if(bought || !player.removeFood(this.price - discount))
return false;
player.buildingCards.add(this);
player.getBuildingCards().add(this);
bought=true;
return true;
}
@@ -81,8 +81,8 @@ public class Artist extends Character {
*/
@Override
public void insert(Player player) {
player.artists.add(this);
player.buildingCards.stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
player.getArtists().add(this);
player.getBuildingCards().stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
}
}
@@ -175,7 +175,7 @@ public class Builder extends Character {
* @param player the player who receives the card.
*/
public void insert(Player player) {
player.builders.add(this);
player.buildingCards.stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
player.getBuilders().add(this);
player.getBuildingCards().stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
}
}
@@ -80,7 +80,7 @@ public class Gatherer extends Character {
* @param player the player who receives the card.
*/
public void insert(Player player) {
player.gatherers.add(this);
player.buildingCards.stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
player.getGatherers().add(this);
player.getBuildingCards().stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
}
}
@@ -136,11 +136,11 @@ public class Hunter extends Character {
*/
@Override
public void insert(Player player) {
player.hunters.add(this);
player.getHunters().add(this);
if(this.getIcon()){
player.addFood(player.hunters.size());
player.addFood(player.getHunters().size());
}
player.buildingCards.stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
player.getBuildingCards().stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
}
}
@@ -135,8 +135,8 @@ public class Inventor extends Character {
*/
@Override
public void insert(Player player) {
player.inventors.add(this);
player.buildingCards.stream().filter(b -> b.getEffectId() == 4).forEach(b4 -> b4.applyEffect(player));
player.buildingCards.stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
player.getInventors().add(this);
player.getBuildingCards().stream().filter(b -> b.getEffectId() == 4).forEach(b4 -> b4.applyEffect(player));
player.getBuildingCards().stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
}
}
@@ -124,7 +124,7 @@ public class Shaman extends Character {
@Override
public void insert(Player player)
{
player.shamans.add(this);
player.buildingCards.stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
player.getShamans().add(this);
player.getBuildingCards().stream().filter(x->x.getEffectId()==0).forEach(x->x.applyEffect(player));
}
}
@@ -79,7 +79,7 @@ public class CavePaintings extends EventCard {
for (Player player : playerList){
int NArtists = player.getNType(CharacterType.ARTIST);
int NBuildings = 0;
ArrayList<BuildingCard> buildingCards = player.buildingCards;
ArrayList<BuildingCard> buildingCards = player.getBuildingCards();
for(BuildingCard card : buildingCards){
if(card.getEffectId() == 9){
@@ -58,7 +58,7 @@ public class Hunt extends EventCard {
int tmpFoodMultiplier = foodMultiplier;
int tmpPrestigeMultiplier = prestigeMultiplier;
ArrayList <BuildingCard> buildingList = player.buildingCards;
ArrayList <BuildingCard> buildingList = player.getBuildingCards();
int hunterCounter=player.getNType(CharacterType.HUNTER);
for (BuildingCard buildingCard : buildingList) {
@@ -70,8 +70,8 @@ public class ShamanicRitual extends EventCard {
int tmpCount = 0;
for (Player player : playerList) {
tmpIcons = player.shamans.stream().mapToInt(sh -> sh.getIcon()).sum();
tmpCount = (int) player.buildingCards.stream().filter(b -> b.getEffectId() == 5).count();
tmpIcons = player.getShamans().stream().mapToInt(sh -> sh.getIcon()).sum();
tmpCount = (int) player.getBuildingCards().stream().filter(b -> b.getEffectId() == 5).count();
if (tmpCount >= 1) {
tmpIcons = tmpIcons+(3*tmpCount);
}
@@ -86,7 +86,7 @@ public class ShamanicRitual extends EventCard {
for (Player player : maxIconsPlayer) {
if (player.buildingCards.stream().anyMatch(b -> b.getEffectId() == 6) && maxIconsPlayer.size() == 1) {
if (player.getBuildingCards().stream().anyMatch(b -> b.getEffectId() == 6) && maxIconsPlayer.size() == 1) {
player.addPrestige(prestigeToAdd * 2);
} else {
player.addPrestige(prestigeToAdd);
@@ -94,7 +94,7 @@ public class ShamanicRitual extends EventCard {
}
for (Player player : minIconsPlayer) {
if (!(player.buildingCards.stream().anyMatch(b -> b.getEffectId() == 2))) {
if (!(player.getBuildingCards().stream().anyMatch(b -> b.getEffectId() == 2))) {
player.removePrestige(prestigeToRemove);
}
}
@@ -72,7 +72,7 @@ public class Sustenance extends EventCard {
int NGatherers = player.getNType(CharacterType.GATHERER);
int NCharDiscount = 0;
for(BuildingCard b : player.buildingCards){
for(BuildingCard b : player.getBuildingCards()){
if(b.getEffectId() == 1){
CharacterType c = ((Building1)b).getIcon();
NCharDiscount += player.getNType(c);
@@ -59,7 +59,7 @@ public class Game implements Serializable {
*/
public List<Totems>getAvailableTotems() {
List<Totems> totems=new ArrayList<>(List.of(Totems.values()));
playersList.forEach(player -> {if(player.totem!=null)totems.remove(player.totem);});
playersList.forEach(player -> {if(player.getTotem()!=null)totems.remove(player.getTotem());});
return totems;
}
@@ -92,7 +92,7 @@ public class Game implements Serializable {
{
return false;
}
player.totem=totem;
player.setTotem(totem);
Player nextPlayer= totemChoiceQueue.poll();
if(nextPlayer==null)
@@ -104,7 +104,7 @@ public class Game implements Serializable {
{
while(disconnetedPlayers.containsKey(nextPlayer)&& disconnetedPlayers.get(nextPlayer))
{
nextPlayer.totem=getAvailableTotems().get(new Random().nextInt(0,getAvailableTotems().size()));
nextPlayer.setTotem(getAvailableTotems().get(new Random().nextInt(0,getAvailableTotems().size())));
nextPlayer=totemChoiceQueue.poll();
if(nextPlayer==null)
{
@@ -154,7 +154,7 @@ public class Game implements Serializable {
}
else {
if (totemChoiceQueue.isEmpty()) {
player.totem = getAvailableTotems().get(new Random().nextInt(getAvailableTotems().size()));
player.setTotem(getAvailableTotems().get(new Random().nextInt(getAvailableTotems().size())));
} else {
totemChoiceQueue.add(player);
}
@@ -807,7 +807,7 @@ public class Game implements Serializable {
OptionalCardQueue = new LinkedList<>();
for (Player p :playersList) {
long count = p.buildingCards.stream().filter(x -> x.getEffectId() == 12).count();
long count = p.getBuildingCards().stream().filter(x -> x.getEffectId() == 12).count();
if (count > 0) {
if(disconnetedPlayers.containsKey(p)&& disconnetedPlayers.get(p))
{
@@ -929,22 +929,22 @@ public class Game implements Serializable {
sustenance.forEach(event->event.activateEvent(playersList));
playersList.forEach(p->{
int temp= p.builders.stream().mapToInt(Builder::getPrestigeValue).sum();
int temp= p.getBuilders().stream().mapToInt(Builder::getPrestigeValue).sum();
p.addPrestige(temp);
});
playersList.forEach(p->{
int temp=(int) p.inventors.stream().mapToInt(Inventor::Icon).distinct().count();
int temp=(int) p.getInventors().stream().mapToInt(Inventor::Icon).distinct().count();
p.addPrestige(temp*p.getNType(CharacterType.INVENTOR));
});
playersList.forEach(p->{
p.addPrestige(10 * (p.getNType(CharacterType.ARTIST)/2));
});
playersList.forEach(p->{
int temp= p.buildingCards.stream().mapToInt(BuildingCard::getPrestigeValue).sum();
int temp= p.getBuildingCards().stream().mapToInt(BuildingCard::getPrestigeValue).sum();
p.addPrestige(temp);
});
playersList.forEach(
p -> p.buildingCards.stream().filter(x -> x.getEffectType() == EffectType.FINAL).
p -> p.getBuildingCards().stream().filter(x -> x.getEffectType() == EffectType.FINAL).
forEach(x -> x.applyEffect(p))
);
currentState.GameStageUpdate(GameStages.ENDED);
@@ -123,7 +123,7 @@ public abstract class OrderLogicCard implements Serializable {
*/
protected void buildingEffect(Player player)
{
for(BuildingCard b : player.buildingCards.stream().filter(x->x.getEffectId()==3).toList())
for(BuildingCard b : player.getBuildingCards().stream().filter(x->x.getEffectId()==3).toList())
player.addFood(1);
}
@@ -24,7 +24,7 @@ public class Player implements Serializable {
* Identifier for the {@code Player} when displaying the game through the GUI.
* @see Totems
*/
public Totems totem;
private Totems totem;
// region Getters
/**
@@ -42,6 +42,10 @@ public class Player implements Serializable {
return UserName;
}
public Totems getTotem() {
return totem;
}
/**
* Counts the total {@link it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character Character Cards}
* the player currently possesses.
@@ -69,40 +73,21 @@ public class Player implements Serializable {
case GATHERER -> gatherers.size();
};
}
/**
* The List containing all {@link BuildingCard Building Cards} the player currently possesses.
*/
public ArrayList <BuildingCard> buildingCards;
private ArrayList<BuildingCard> buildingCards;
private ArrayList<Artist> artists;
private ArrayList<Builder> builders;
private ArrayList<Inventor> inventors;
private ArrayList<Gatherer> gatherers;
private ArrayList<Shaman> shamans;
private ArrayList<Hunter> hunters;
/**
* The List containing all {@link Artist Artist Character Cards} the player currently possesses.
*/
public ArrayList <Artist> artists;
/**
* The List containing all {@link Builder Builder Character Cards} the player currently possesses.
*/
public ArrayList <Builder> builders;
/**
* The List containing all {@link Inventor Inventor Character Cards} the player currently possesses.
*/
public ArrayList <Inventor> inventors;
/**
* The List containing all {@link Gatherer Gatherer Character Cards} the player currently possesses.
*/
public ArrayList <Gatherer> gatherers;
/**
* The List containing all {@link Shaman Shaman Character Cards} the player currently possesses.
*/
public ArrayList <Shaman> shamans;
/**
* The List containing all {@link Hunter Hunter Character Cards} the player currently possesses.
*/
public ArrayList <Hunter> hunters;
public ArrayList<BuildingCard> getBuildingCards() { return buildingCards; }
public ArrayList<Artist> getArtists() { return artists; }
public ArrayList<Builder> getBuilders() { return builders; }
public ArrayList<Inventor> getInventors() { return inventors; }
public ArrayList<Gatherer> getGatherers() { return gatherers; }
public ArrayList<Shaman> getShamans() { return shamans; }
public ArrayList<Hunter> getHunters() { return hunters; }
/**
* The current amount of {@code Food} the Player possesses.
@@ -147,6 +132,10 @@ public class Player implements Serializable {
this.FoodValue += Value;
}
public void setTotem(Totems totem) {
this.totem = totem;
}
/**
* Removes {@code Value} amount of {@code Food} from the Player.
* Note: {@link #FoodValue} cannot be negative, so the method returns
@@ -231,6 +220,19 @@ public class Player implements Serializable {
// endregion constructors
// region Functions
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Player)) return false;
return UserName.equals(((Player) obj).UserName);
}
@Override
public int hashCode() {
return UserName.hashCode();
}
/**
* Prints the {@code Player}'s attributes for the {@code Board}'s representation.
* Uses the {@code UNICODE} border style.
@@ -189,5 +189,18 @@ public class Slot implements Serializable {
// End Constructors
// Functions
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Slot)) return false;
return slotId == ((Slot) obj).slotId;
}
@Override
public int hashCode() {
return Character.hashCode(slotId);
}
// End functions
}
@@ -164,7 +164,7 @@ public class LeaderboardFXMLController {
// Totem
ImageView totem = new ImageView(loadImage(
"/GUIImages/Totems/totem_" + player.totem.toString().toLowerCase(Locale.ROOT) + ".png"));
"/GUIImages/Totems/totem_" + player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png"));
totem.setFitHeight(55);
totem.setPreserveRatio(true);
@@ -198,14 +198,14 @@ public class LeaderboardFXMLController {
HBox stats = new HBox(14);
stats.setAlignment(Pos.CENTER);
stats.getChildren().add(createStatItem("/GUIImages/Icons/Food.png", String.valueOf(player.getFoodValue()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Artist.png", String.valueOf(player.artists.size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Gatherer.png", String.valueOf(player.gatherers.size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Inventor.png", String.valueOf(player.inventors.size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Builder.png", String.valueOf(player.builders.size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Shaman.png", String.valueOf(player.shamans.size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Hunter.png", String.valueOf(player.hunters.size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Building.png", String.valueOf(player.buildingCards.size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Food.png", String.valueOf(player.getFoodValue()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Artist.png", String.valueOf(player.getArtists().size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Gatherer.png", String.valueOf(player.getGatherers().size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Inventor.png", String.valueOf(player.getInventors().size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Builder.png", String.valueOf(player.getBuilders().size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Shaman.png", String.valueOf(player.getShamans().size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Hunter.png", String.valueOf(player.getHunters().size()), 26));
stats.getChildren().add(createStatItem("/GUIImages/Icons/Building.png", String.valueOf(player.getBuildingCards().size()), 26));
return stats;
}
@@ -256,7 +256,7 @@ public class LeaderboardFXMLController {
HBox header = new HBox(10);
header.setAlignment(Pos.CENTER);
ImageView totem = new ImageView(loadImage(
"/GUIImages/Totems/totem_" + player.totem.toString().toLowerCase(Locale.ROOT) + ".png"));
"/GUIImages/Totems/totem_" + player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png"));
totem.setFitHeight(30);
totem.setPreserveRatio(true);
Label nameLabel = new Label(player.getUserName());
@@ -333,13 +333,13 @@ public class LeaderboardFXMLController {
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
Player p = controller.miniModel.players.get(username);
return switch (type) {
case "artists" -> new ArrayList<>(p.artists);
case "gatherers" -> new ArrayList<>(p.gatherers);
case "inventors" -> new ArrayList<>(p.inventors);
case "builders" -> new ArrayList<>(p.builders);
case "shamans" -> new ArrayList<>(p.shamans);
case "hunters" -> new ArrayList<>(p.hunters);
case "buildingCards" -> new ArrayList<>(p.buildingCards);
case "artists" -> new ArrayList<>(p.getArtists());
case "gatherers" -> new ArrayList<>(p.getGatherers());
case "inventors" -> new ArrayList<>(p.getInventors());
case "builders" -> new ArrayList<>(p.getBuilders());
case "shamans" -> new ArrayList<>(p.getShamans());
case "hunters" -> new ArrayList<>(p.getHunters());
case "buildingCards" -> new ArrayList<>(p.getBuildingCards());
default -> new ArrayList<>();
};
}
@@ -200,7 +200,7 @@ public class MainFXMLController {
HBox headerRow = new HBox(8);
headerRow.setAlignment(Pos.CENTER);
ImageView totem = new ImageView(loadImage("/GUIImages/Totems/totem_"
+ player.totem.toString().toLowerCase(Locale.ROOT) + ".png"));
+ player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png"));
totem.setFitHeight(20);
totem.setPreserveRatio(true);
Label usernameLabel = new Label(player.getUserName());
@@ -313,7 +313,7 @@ public class MainFXMLController {
Player player = controller.miniModel.slotPlayerMap.get(slot);
if (player != null && controller.miniModel.getPositionByUsername(player.getUserName()) != -1) {
ImageView totem = new ImageView(loadImage("/GUIImages/Totems/totem_" + player.totem.toString().toLowerCase(Locale.ROOT) + ".png"));
ImageView totem = new ImageView(loadImage("/GUIImages/Totems/totem_" + player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png"));
totem.fitHeightProperty().bind(img.fitHeightProperty().multiply(0.332));
totem.setPreserveRatio(true);
StackPane.setAlignment(totem, Pos.TOP_LEFT);
@@ -472,13 +472,13 @@ public class MainFXMLController {
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
Player p = controller.miniModel.players.get(username);
return switch (type) {
case "artists" -> new ArrayList<>(p.artists);
case "gatherers" -> new ArrayList<>(p.gatherers);
case "inventors" -> new ArrayList<>(p.inventors);
case "builders" -> new ArrayList<>(p.builders);
case "shamans" -> new ArrayList<>(p.shamans);
case "hunters" -> new ArrayList<>(p.hunters);
case "building" -> new ArrayList<>(p.buildingCards);
case "artists" -> new ArrayList<>(p.getArtists());
case "gatherers" -> new ArrayList<>(p.getGatherers());
case "inventors" -> new ArrayList<>(p.getInventors());
case "builders" -> new ArrayList<>(p.getBuilders());
case "shamans" -> new ArrayList<>(p.getShamans());
case "hunters" -> new ArrayList<>(p.getHunters());
case "building" -> new ArrayList<>(p.getBuildingCards());
default -> new ArrayList<>();
};
}
@@ -578,7 +578,7 @@ public class MainFXMLController {
// Carica immagine totem come in createSlot
ImageView totem = new ImageView(loadImage(
"/GUIImages/Totems/totem_" + op.player.totem.toString().toLowerCase(Locale.ROOT) + ".png"
"/GUIImages/Totems/totem_" + op.player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png"
));
totem.setPreserveRatio(true);
@@ -631,13 +631,13 @@ public class MainFXMLController {
myHand.setAlignment(Pos.CENTER);
Player me = controller.miniModel.players.get(controller.myUsername);
drawMyHandList(me.artists);
drawMyHandList(me.gatherers);
drawMyHandList(me.inventors);
drawMyHandList(me.builders);
drawMyHandList(me.shamans);
drawMyHandList(me.hunters);
drawMyHandList(me.buildingCards);
drawMyHandList(me.getArtists());
drawMyHandList(me.getGatherers());
drawMyHandList(me.getInventors());
drawMyHandList(me.getBuilders());
drawMyHandList(me.getShamans());
drawMyHandList(me.getHunters());
drawMyHandList(me.getBuildingCards());
}