diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 455f028..a257030 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,7 +1,6 @@ \ No newline at end of file diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index 5b3b0ab..aa7bb88 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -168,6 +168,17 @@ public class ClientLauncherTUI { } } + /** + * Lets the user choose one of the available active IPv4 network interfaces. + * + *

The method lists all active, non-loopback and non-virtual network + * interfaces with an IPv4 address. If only one interface is available, it is + * selected automatically. + * + * @param scanner the scanner used to read the user's choice. + * @return the selected IPv4 address as a string. + * @throws Exception if no valid network interface is available. + */ public static String chooseNetworkInterface(Scanner scanner) throws Exception { List ips = new ArrayList<>(); diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/EffectType.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/EffectType.java index eaa48f1..ed7ba06 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/EffectType.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/EffectType.java @@ -1,7 +1,5 @@ package it.polimi.ingsw.gc14.Model.Cards.Building; -/** - * Represents the possible effect types of building cards. /** * Represents the possible effect types of building cards. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building0.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building0.java index 58c293e..6d122eb 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building0.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building0.java @@ -24,10 +24,12 @@ public class Building0 extends BuildingCard { private int numSet; /** - * Constructor of the building - * @param era The game era of the building. - * @param price The price (in food) of the building. - * @param prestigeValue The number of Prestige Points gained from this building at the end of the game. + * Constructor of the building. + * + * @param idImage the image identifier of the building. + * @param era the game era of the building. + * @param price the price in food of the building. + * @param prestigeValue the number of Prestige Points gained from this building at the end of the game. */ public Building0(String idImage,int era,int price,int prestigeValue) { super(idImage,era,price,prestigeValue); diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1.java index 70de501..3d182d7 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1.java @@ -33,12 +33,15 @@ public class Building1 extends BuildingCard { effectId = 1; this.icon = icon; } + /** * Constructor of the building. - * @param era The game era of the building. - * @param price The price (in food) of the building. - * @param prestigeValue The number of Prestige Points gained from this building at the end of the game. - * @param icon The character type used by the building effect. + * + * @param idIMG the image identifier of the building. + * @param era the game era of the building. + * @param price the price in food of the building. + * @param prestigeValue the number of Prestige Points gained from this building at the end of the game. + * @param icon the character type used by the building effect. */ public Building1(String idIMG,int era, int price,int prestigeValue, CharacterType icon) { super(idIMG,era,price,prestigeValue); diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building10.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building10.java index 58b8668..21cf0f7 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building10.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building10.java @@ -28,8 +28,9 @@ public class Building10 extends BuildingCard { } /** - * Creates a Building10 card with the specified era, price, and prestige value. + * Creates a Building10 card with the specified image id, 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. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11.java index de25796..25ff457 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11.java @@ -50,10 +50,12 @@ public class Building11 extends BuildingCard { this.icon = icon; this.PrestigeMul = prestigeMul; } + /** - * Creates a Building11 card with the specified era, price, prestige value, + * Creates a Building11 card with the specified image id, era, price, prestige value, * character type icon, and prestige multiplier. * + * @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. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building13.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building13.java index 378b89c..d2fdaf0 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building13.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building13.java @@ -23,9 +23,11 @@ public class Building13 extends BuildingCard{ effectType= EffectType.FINAL; effectId=13; } + /** - * Creates a Building13 card with the specified era, price, and prestige value. + * Creates a Building13 card with the specified image id, 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. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building4.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building4.java index 7c3b0b1..adca5f9 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building4.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building4.java @@ -36,10 +36,12 @@ public class Building4 extends BuildingCard { } /** - * Constructor of the building - * @param era The game era of the building. - * @param price The price (in food) of the building. - * @param prestigeValue The number of Prestige Points gained from this building at the end of the game. + * Constructor of the building. + * + * @param idIMG the image identifier of the building. + * @param era the game era of the building. + * @param price the price in food of the building. + * @param prestigeValue the number of Prestige Points gained from this building at the end of the game. */ public Building4(String idIMG,int era, int price,int prestigeValue) { super(idIMG,era,price,prestigeValue); diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java index 62e6393..be87fa5 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8.java @@ -24,10 +24,12 @@ public class Building8 extends BuildingCard { } /** - * Constructor of the building - * @param era The game era of the building. - * @param price The price (in food) of the building. - * @param prestigeValue The number of Prestige Points gained from this building at the end of the game. + * Constructor of the building. + * + * @param idIMG the image identifier of the building. + * @param era the game era of the building. + * @param price the price in food of the building. + * @param prestigeValue the number of Prestige Points gained from this building at the end of the game. */ public Building8(String idIMG,int era, int price,int prestigeValue) { super(idIMG,era,price,prestigeValue); diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java index 295e5e2..0d97326 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java @@ -170,16 +170,18 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf } /** - * Creates a building card with the specified effect identifier, era, price, - * and prestige value. - * The effect type is determined from the given effect identifier. + * Creates a building card with the specified image id, effect identifier, era, + * price, and prestige value. * + *

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} + * if {@code price <= 0}, or if {@code prestigeValue < 0}. */ public BuildingCard(String idIMG,int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{ this.effectId = effectId; diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java index 0950f46..f7ec819 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCard.java @@ -50,10 +50,12 @@ public abstract class TribeCard extends PlayableCard implements Serializable { public TribeCard(int Era,boolean isEventCard) { this(Era,isEventCard,0); } + /** - * Creates a tribe card with the specified era and event-card flag. + * Creates a tribe card with the specified image id, era and event-card flag. * The minimum number of players is set to 0. * + * @param idIMG the image identifier of the tribe card. * @param Era the era of the tribe card. * @param isEventCard whether the card is an event card. */ @@ -76,9 +78,10 @@ public abstract class TribeCard extends PlayableCard implements Serializable { } /** - * Creates a tribe card with the specified era, event-card flag, + * Creates a tribe card with the specified image id, era, event-card flag, * and minimum number of players. * + * @param idIMG the image identifier of the tribe card. * @param Era the era of the tribe card. * @param isEventCard whether the card is an event card. * @param nMin the minimum number of players required for the card. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java index 0b2eafc..baed2bb 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Character.java @@ -34,9 +34,11 @@ public abstract class Character extends TribeCard implements Cloneable { super(Era,false ); this.type = type; } + /** - * Creates a character card with the specified era and character type. + * Creates a character card with the specified image id, era and character type. * + * @param idIMG the image identifier of the character card. * @param Era the era of the character card. * @param type the type of the character card. */ @@ -58,10 +60,12 @@ public abstract class Character extends TribeCard implements Cloneable { super(Era,false ,nMin); this.type = type; } + /** - * Creates a character card with the specified era, character type, + * Creates a character card with the specified image id, era, character type, * and minimum number of players. * + * @param idIMG the image identifier of the character card. * @param Era the era of the character card. * @param type the type of the character card. * @param nMin the minimum number of players required for the card. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/CharacterType.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/CharacterType.java index d05a6e6..68f3962 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/CharacterType.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/CharacterType.java @@ -1,7 +1,5 @@ package it.polimi.ingsw.gc14.Model.Cards.TribeCards; -/** - * Represents the different types of character cards available in the game. /** * Represents the different types of character cards available in the game. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Artist.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Artist.java index 0a4faba..f31314f 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Artist.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Artist.java @@ -32,19 +32,22 @@ public class Artist extends Character { } /** - * Creates an Artist character card with the specified era. + * Creates an Artist character card with the specified image id and era. * - * @param Era the era of the Artist card + * @param idIMG the image identifier of the Artist card. + * @param Era the era of the Artist card. */ public Artist(String idIMG,int Era) { super(idIMG,Era, CharacterType.ARTIST); } /** - * Creates an Artist character card with the specified Era and minimum number of players required to play it. + * Creates an Artist character card with the specified image id, era and + * minimum number of players required to play it. * - * @param Era the era of the Artist card - * @param nMin the minimum number of players required for the card + * @param idIMG the image identifier of the Artist card. + * @param Era the era of the Artist card. + * @param nMin the minimum number of players required for the card. */ public Artist(String idIMG,int Era,int nMin) { super(idIMG,Era, CharacterType.ARTIST,nMin); diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Builder.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Builder.java index 6025793..58d61eb 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Builder.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Builder.java @@ -89,6 +89,7 @@ public class Builder extends Character { * Creates a Builder character card with the specified era, reduction value, * and prestige value. * + * @param idIMG the image identifier of the Builder card. * @param Era the era of the Builder card. * @param reductionValue the reduction value of the Builder card. * @param prestigeValue the prestige value of the Builder card. @@ -111,6 +112,7 @@ public class Builder extends Character { * Creates a Builder character card with the specified era, reduction value, * prestige value, and minimum number of players. * + * @param idIMG the image identifier of the Builder card. * @param Era the era of the Builder card. * @param reductionValue the reduction value of the Builder card. * @param prestigeValue the prestige value of the Builder card. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Gatherer.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Gatherer.java index ea20e56..4544a54 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Gatherer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Gatherer.java @@ -34,15 +34,18 @@ public class Gatherer extends Character { /** * Creates a Gatherer character card with the specified era. * - * @param Era Gatherers era. + * @param idIMG the image identifier of the Gatherer card. + * @param Era the era of the Gatherer card. */ public Gatherer(String idIMG,int Era) { super(idIMG,Era, CharacterType.GATHERER); } /** - * Creates a Gatherer character card with the specified era and minimum number of players. + * Creates a Gatherer character card with the specified image id, era and + * minimum number of players. * + * @param idIMG the image identifier of the Gatherer card. * @param Era the era of the Gatherer card. * @param nMin the minimum number of players required for the card. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Hunter.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Hunter.java index 263b99c..b34e8b4 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Hunter.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Hunter.java @@ -51,9 +51,11 @@ public class Hunter extends Character { super(Era, CharacterType.HUNTER,nMin); this.icon = icon; } + /** - * Creates a Hunter character card with the specified era and icon value. + * Creates a Hunter character card with the specified image id, era and icon value. * + * @param idIMG the image identifier of the Hunter card. * @param Era the era of the Hunter card. * @param icon the icon value of the Hunter card. */ @@ -63,9 +65,10 @@ public class Hunter extends Character { } /** - * Creates a Hunter character card with the specified era, icon value, + * Creates a Hunter character card with the specified image id, era, icon value, * and minimum number of players. * + * @param idIMG the image identifier of the Hunter card. * @param Era the era of the Hunter card. * @param icon the icon value of the Hunter card. * @param nMin the minimum number of players required for the card. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Inventor.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Inventor.java index 047fa61..15df18f 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Inventor.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Inventor.java @@ -55,8 +55,9 @@ public class Inventor extends Character { } /** - * Creates an Inventor character card with the specified era and icon value. + * Creates an Inventor character card with the specified image id, era and icon value. * + * @param idIMG the image identifier of the Inventor card. * @param Era the era of the Inventor card. * @param icon the icon value of the Inventor card. * @throws IllegalArgumentException if {@code icon < 0} or {@code icon > 9}. @@ -69,9 +70,10 @@ public class Inventor extends Character { } /** - * Creates an Inventor character card with the specified era, icon value, + * Creates an Inventor character card with the specified image id, era, icon value, * and minimum number of players. * + * @param idIMG the image identifier of the Inventor card. * @param Era the era of the Inventor card. * @param icon the icon value of the Inventor card. * @param nMin the minimum number of players required for the card. @@ -83,6 +85,7 @@ public class Inventor extends Character { throw new IllegalArgumentException(); this.icon = icon; } + /** * Returns the string representation of this Inventor card. * diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Shaman.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Shaman.java index 810d669..353e03d 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Shaman.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Characters/Shaman.java @@ -52,9 +52,11 @@ public class Shaman extends Character { super(Era, CharacterType.SHAMAN,nMin); this.icon = icon; } + /** - * Creates a Shaman character card with the specified era and icon value. + * Creates a Shaman character card with the specified image id, era and icon value. * + * @param idIMG the image identifier of the Shaman card. * @param Era the era of the Shaman card. * @param icon the icon value of the Shaman card. */ @@ -64,9 +66,10 @@ public class Shaman extends Character { } /** - * Creates a Shaman character card with the specified era, icon value, + * Creates a Shaman character card with the specified image id, era, icon value, * and minimum number of players. * + * @param idIMG the image identifier of the Shaman card. * @param Era the era of the Shaman card. * @param icon the icon value of the Shaman card. * @param nMin the minimum number of players required for the card. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java index 34b033d..b92e1c0 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java @@ -41,9 +41,11 @@ public abstract class EventCard extends TribeCard { super(Era,true); this.type = type; } + /** - * Creates an event card with the specified era and event type. + * 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 type the type of the event card. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventType.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventType.java index c07f869..1b6720a 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventType.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventType.java @@ -1,7 +1,5 @@ package it.polimi.ingsw.gc14.Model.Cards.TribeCards; -/** - * Represents the different types of event cards available in the game. /** * Represents the different types of event cards available in the game. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintings.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintings.java index f0f7716..5d46432 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintings.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/CavePaintings.java @@ -47,9 +47,11 @@ public class CavePaintings extends EventCard { this.NPrestigeRem = NPrestigeRem; this.NPrestigeMul = NPrestigeMul; } + /** - * Creates a CavePaintings event card with the specified era and effect parameters. + * 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}. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Hunt.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Hunt.java index af57191..a03599b 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Hunt.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Hunt.java @@ -30,11 +30,13 @@ public class Hunt extends EventCard { this.foodMultiplier = 1; this.prestigeMultiplier = prestigeMultiplier; } + /** * Creates a new Hunt event card. * - * @param Era the era of the card - * @param prestigeMultiplier prestige points multiplicator used during the event + * @param idIMG the image identifier of the Hunt event card. + * @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); @@ -45,7 +47,6 @@ public class Hunt extends EventCard { /** * Activates the event card "Hunt". * Each player takes 1 Food and gains Prestige Points for each Hunter in their tribe. - * * Buildings influence: * Building 7: the player takes 1 Food and 1 additional Prestige Point for each Hunter. * diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitual.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitual.java index fcbb7e5..6efc4d1 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitual.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/ShamanicRitual.java @@ -34,12 +34,14 @@ public class ShamanicRitual extends EventCard { this.prestigeToRemove = prestigeToRemove; } + /** * Creates a new ShamanicRitual event card. * - * @param Era the era of the card - * @param prestigeToAdd prestige points awarded to the player with the most icons - * @param prestigeToRemove prestige points removed from the player with the fewest icons + * @param idIMG the image identifier of the ShamanicRitual event card. + * @param Era the era of the card. + * @param prestigeToAdd prestige points awarded to the player with the most icons. + * @param prestigeToRemove prestige points removed from the player with the fewest icons. */ public ShamanicRitual(String idIMG,int Era, int prestigeToAdd, int prestigeToRemove) { super(idIMG,Era, EventType.SHAMANIC_RITUAL); @@ -54,7 +56,6 @@ public class ShamanicRitual extends EventCard { * The player with the fewest icons loses the Prestige Points indicated. * In case of a tie, all players gain or lose the Prestige Points indicated. * If all players have the same amount of icons, they all gain and lose Prestige Points. - * * Buildings influence: * Building 2: if you have the lowest number of icons, you don't lose Prestige Points * Building 5: during the Shamanic Ritual, you gain 3 icons diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java index 1e20492..51856c3 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/Events/Sustenance.java @@ -39,9 +39,11 @@ public class Sustenance extends EventCard { super(Era, EventType.SUSTENANCE); this.PrestigeDebt = PrestigeDebt; } + /** - * Creates a Sustenance event card with the specified era and prestige debt value. + * Creates a Sustenance event card with the specified image id, era and prestige debt value. * + * @param idIMG the image identifier of the Sustenance event card. * @param Era the era of the event card. * @param PrestigeDebt the prestige penalty multiplier for unpaid Food units. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java index 3d3115b..d939baf 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -63,7 +63,13 @@ public class Game implements Serializable { * The mapping between slots and the players assigned to them. */ private HashMap slotMap; - public HashMap getSlotMap() {return slotMap;}; + + /** + * Returns the map of slots assigned to players. + * + * @return the map that associates each slot with the corresponding player. + */ + public HashMap getSlotMap() {return slotMap;} /** * The configured number of players for this game. diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java index 00b4376..1c4c849 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java @@ -1,7 +1,5 @@ package it.polimi.ingsw.gc14.Model.GamePackage; -/** - * Represents the possible stages of a game. /** * Represents the possible stages of a game. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/PlayableCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/PlayableCard.java index b9d40df..ff0e353 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/PlayableCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/PlayableCard.java @@ -8,7 +8,16 @@ import java.io.Serializable; */ public abstract class PlayableCard implements Serializable { + /** + * The image identifier of the playable card. + */ private String idIMG; + + /** + * Returns the image identifier of this playable card. + * + * @return the image identifier of this playable card. + */ public String getIdIMG() { return idIMG; } @@ -43,8 +52,9 @@ public abstract class PlayableCard implements Serializable { } /** - * Creates a playable card with the specified era. + * Creates a playable card with the specified image id and era. * + * @param idIMG the image identifier of the playable card. * @param Era the era of the playable card. * @throws IllegalArgumentException if {@code Era <= 0} or {@code Era >= 4}. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java b/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java index de8cc3d..46a6d15 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java @@ -1,12 +1,5 @@ package it.polimi.ingsw.gc14.Network; -/** - * Represents the possible actions requested by a client and handled by the - * server during the game. - * - *

Each value identifies a specific user action, such as adding a player, - * choosing a slot, drawing a card, picking an optional card, or skipping an - * optional action. /** * Represents the different types of network events that can be sent between * client and server. diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java index 3c5e250..febd764 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java @@ -30,13 +30,18 @@ public class RMIClient implements IClient { /** Client game's controller */ ClientController controller; + /** + * Local IP address of the RMI client. + */ private String myIP; /** * Class constructor. - * @param controller the client controller used to create the callback - * @param host the host address of the RMI server - * @param port the port of the RMI server + * + * @param controller the client controller used to create the callback. + * @param host the host address of the RMI server. + * @param port the port of the RMI server. + * @param myIP the local IP address used by the RMI client. */ public RMIClient(ClientController controller, String host, int port, String myIP) { this.controller=controller; diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java index ec8d61f..66d03d2 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java @@ -51,11 +51,13 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { /** * Class constructor that initializes the attributes. - * @param controller The game controller - * @param nPort The RMI port - * @param actionQueue The action queue - * @param playerList The player's usernames list - * @throws RemoteException if an RMI error occurs + * + * @param controller the game controller. + * @param nPort the RMI port. + * @param actionQueue the action queue. + * @param playerList the players' usernames list. + * @param host the host address of the RMI server. + * @throws RemoteException if an RMI error occurs. */ public RMIServer(GameController controller, int nPort, BlockingQueue actionQueue,LimitedList playerList,String host) throws RemoteException { this.controller = controller; @@ -65,9 +67,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { this.host = host; } - - - // RMI's exposed methods /** * Allows a player to join the game. * If the desired number of player is invalid, the request is rejected. @@ -208,8 +207,13 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { // RMI's internal methods /** - * Sends an action to all RMI clients. - * @param action The desired action + * Sends an action to the RMI clients. + * + *

If the action is an error, it is sent only to the client associated with + * the action username. Otherwise, it is sent to all connected RMI clients. + * + * @param action the network action to send. + * @throws RemoteException if an RMI communication error occurs. */ public void notifyAll(NetworkEvent action) throws RemoteException { for (Map.Entry entry : clients.entrySet()) { @@ -221,7 +225,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { /** * Sends a game model to all RMI clients. - * @param model The desired model + * + * @param model the game model to send to all connected RMI clients. + * @throws RemoteException if an RMI communication error occurs. */ public void notifyAll(Game model) throws RemoteException { for (IClientCallback cb : clients.values()) { diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java index b64b1f2..83b482c 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java @@ -19,6 +19,12 @@ public class ClientHandler implements Runnable { * The username of the connected client on this handler */ private final String username; + + /** + * Returns the username associated with this client. + * + * @return the username associated with this client. + */ public String getUsername() { return username; } @@ -44,6 +50,7 @@ public class ClientHandler implements Runnable { /** * Class constructor that initializes the attributes. * + * @param username the username associated with the client. * @param clientSocket the socket representing the client's TCP connection. * @param out the output stream used to send data to the client. * @param in the input stream used to receive data from the client. diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java index f420dbb..5380e36 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/TCPServer.java @@ -65,10 +65,8 @@ public class TCPServer { * Starts the TCP server. * If the first event is not AddPlayer, the request is rejected. * If the desired number of player is invalid, the request is rejected. - * * If this is the first player to connect, a new game model is created and passed to the controller. Additionally, the playerList's limit is set. * If the controller successfully adds the player, the username is added to {@link #playerList} and the handler is added to {@link #clientHandlers}. - * * If any error occurs, the server sends -1 back to the client. Otherwise, it sends 1. */ public void start(){ diff --git a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java index 0f43343..3d5bdde 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java +++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java @@ -19,7 +19,6 @@ import java.net.*; /** * Main server launcher that handles both TCP and RMI connections. * The workflow is divided into two parts: game creation and game execution. - * * The process flow for game creation is as follows: * - The first client (TCP/RMI) requests to join the game by providing a username and the desired number of players * - The TCP/RMI server checks {@link #playerList} and, if it is empty, sets the number of players according to the first user's request using {@link LimitedList#setLimit(int)} diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java index c509cd6..20bc0cc 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/TUI.java @@ -31,7 +31,6 @@ public class TUI implements IView { /** * The {@link Game} model whose state is rendered. - * Updated via {@link #update(Game)} whenever the game state changes. */ private Game model; diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building0Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building0Test.java index effb1df..f7dbb97 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building0Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building0Test.java @@ -41,23 +41,26 @@ class Building0Test { p1.addFood(10); p2.addFood(10); - assertEquals(true, b0.buy(p1)); - assertEquals(false, b0.buy(p1)); - assertEquals(false, b0.buy(p2)); + assertTrue(b0.buy(p1)); + assertFalse(b0.buy(p1)); + assertFalse(b0.buy(p2)); } @Test @DisplayName("Testing clone method") void testClone() { + String idImage = "building0.png"; int effectID = 0; EffectType effectType = EffectType.CARD_SET; int era = 1; int price = 1; int prestigeValue = 1; - Building0 b0 = new Building0(era, price,prestigeValue); + + Building0 b0 = new Building0(idImage, era, price, prestigeValue); Building0 b1 = (Building0) b0.clone(); + assertEquals(idImage, b1.getIdIMG()); assertEquals(effectID, b1.getEffectId()); assertEquals(effectType, b1.getEffectType()); assertEquals(era, b1.getEra()); @@ -140,7 +143,74 @@ class Building0Test { Player p2 = new Player("test2"); p1.addFood(b0.getPrice()); p2.addFood(b0.getPrice()); - b0.buy(p1); + assertTrue(b0.buy(p1)); assertFalse(b0.buy(p2)); } + + @Test + @DisplayName("Testing constructor with idImage") + void testConstructorWithIdImage() { + String idImage = "building0.png"; + int era = 1; + int price = 10; + int prestigeValue = 5; + + Building0 b0 = new Building0(idImage, era, price, prestigeValue); + + assertEquals(idImage, b0.getIdIMG()); + assertEquals(era, b0.getEra()); + assertEquals(price, b0.getPrice()); + assertEquals(prestigeValue, b0.getPrestigeValue()); + assertEquals(EffectType.CARD_SET, b0.getEffectType()); + assertEquals(0, b0.getEffectId()); + } + + @Test + @DisplayName("Effect should not reward the same set twice") + void applyEffectShouldNotRewardSameSetTwice() { + int era = 1; + Building0 b0 = new Building0(1, 1, 1); + Player p = new Player("test"); + + p.addFood(b0.getPrice()); + assertTrue(b0.buy(p)); + + p.artists.add(new Artist(era)); + p.builders.add(new Builder(era, 0, 0)); + p.gatherers.add(new Gatherer(era)); + p.hunters.add(new Hunter(era, true)); + p.inventors.add(new Inventor(era, 1)); + p.shamans.add(new Shaman(era, 1)); + + b0.applyEffect(p); + assertEquals(5, p.getFoodValue()); + + b0.applyEffect(p); + assertEquals(5, p.getFoodValue()); + } + + @Test + @DisplayName("Effect should reward multiple new sets") + void applyEffectShouldRewardMultipleNewSets() { + int era = 1; + Building0 b0 = new Building0(1, 1, 1); + Player p = new Player("test"); + + p.addFood(b0.getPrice()); + assertTrue(b0.buy(p)); + + for (int k = 0; k < 2; k++) { + p.artists.add(new Artist(era)); + p.builders.add(new Builder(era, 0, 0)); + p.gatherers.add(new Gatherer(era)); + p.hunters.add(new Hunter(era, true)); + p.inventors.add(new Inventor(era, 1)); + p.shamans.add(new Shaman(era, 1)); + } + + b0.applyEffect(p); + + assertEquals(10, p.getFoodValue()); + } + } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building10Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building10Test.java index 6f00bc8..daec29b 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building10Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building10Test.java @@ -6,8 +6,6 @@ import it.polimi.ingsw.gc14.Model.Player; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.ArrayList; - import static org.junit.jupiter.api.Assertions.*; class Building10Test { @@ -28,15 +26,18 @@ class Building10Test { @Test @DisplayName("Testing clone method") void testClone() { + String idIMG = "building10.png"; int effectID = 10; EffectType effectType = EffectType.FINAL; int era = 1; int price = 1; int prestigeValue = 1; - Building10 b0 = new Building10(era, price, prestigeValue); + + Building10 b0 = new Building10(idIMG, era, price, prestigeValue); Building10 b1 = (Building10) b0.clone(); + assertEquals(idIMG, b1.getIdIMG()); assertEquals(effectID, b1.getEffectId()); assertEquals(effectType, b1.getEffectType()); assertEquals(era, b1.getEra()); @@ -45,40 +46,29 @@ class Building10Test { } @Test + @DisplayName("Apply effect should add 6 prestige points for each complete character set") void applyEffect() { Building10 b10 = new Building10(1, 1, 1); Player p = new Player("test"); + p.addFood(b10.getPrice()); - b10.buy(p); + assertTrue(b10.buy(p)); - int Era = 1; - int Nset = 2; + int era = 1; + int nSet = 2; - ArrayList Artists = new ArrayList<>(); - ArrayList Builders = new ArrayList<>(); - ArrayList Gatherers = new ArrayList<>(); - ArrayList Hunters = new ArrayList<>(); - ArrayList Inventors = new ArrayList<>(); - ArrayList Shamans = new ArrayList<>(); - - for(int i = 0; i < Nset; i++) { - Artists.add(new Artist(Era)); - Builders.add(new Builder(Era, 0, 0)); - Gatherers.add(new Gatherer(Era)); - Hunters.add(new Hunter(Era, true)); - Inventors.add(new Inventor(Era, 1)); - Shamans.add(new Shaman(Era, 1)); + for (int i = 0; i < nSet; i++) { + p.artists.add(new Artist(era)); + p.builders.add(new Builder(era, 0, 0)); + p.gatherers.add(new Gatherer(era)); + p.hunters.add(new Hunter(era, true)); + p.inventors.add(new Inventor(era, 1)); + p.shamans.add(new Shaman(era, 1)); } - p.artists.addAll(Artists); - p.builders.addAll(Builders); - p.gatherers.addAll(Gatherers); - p.hunters.addAll(Hunters); - p.inventors.addAll(Inventors); - p.shamans.addAll(Shamans); - b10.applyEffect(p); - assertEquals(Nset * 6, p.getPrestigeValue()); + + assertEquals(nSet * 6, p.getPrestigeValue()); } @Test @@ -91,11 +81,57 @@ class Building10Test { } @Test - void applyEffectMultiplePlayerException() { - Building10 b10 = new Building10(1, 1, 1); - Player p1 = new Player("test1"); - Player p2 = new Player("test2"); - b10.buy(p1); - assertFalse(b10.buy(p2)); + @DisplayName("Buying same card by two different players") + void buyShouldRejectSameCardForDifferentPlayers() { + Building10 b10 = new Building10(1, 1, 1); + Player p1 = new Player("test1"); + Player p2 = new Player("test2"); + + p1.addFood(b10.getPrice()); + p2.addFood(b10.getPrice()); + + assertTrue(b10.buy(p1)); + assertFalse(b10.buy(p2)); + } + + @Test + @DisplayName("Testing constructor with idIMG") + void testConstructorWithIdIMG() { + String idIMG = "building10.png"; + int era = 1; + int price = 10; + int prestigeValue = 5; + + Building10 b10 = new Building10(idIMG, era, price, prestigeValue); + + assertEquals(idIMG, b10.getIdIMG()); + assertEquals(era, b10.getEra()); + assertEquals(price, b10.getPrice()); + assertEquals(prestigeValue, b10.getPrestigeValue()); + assertEquals(EffectType.FINAL, b10.getEffectType()); + assertEquals(10, b10.getEffectId()); + } + + @Test + @DisplayName("Apply effect should not add prestige without complete character sets") + void applyEffectShouldNotAddPrestigeWithoutCompleteSets() { + Building10 b10 = new Building10(1, 1, 1); + Player p = new Player("test"); + + p.addFood(b10.getPrice()); + assertTrue(b10.buy(p)); + + int era = 1; + + p.artists.add(new Artist(era)); + p.builders.add(new Builder(era, 0, 0)); + p.gatherers.add(new Gatherer(era)); + p.hunters.add(new Hunter(era, true)); + p.inventors.add(new Inventor(era, 1)); + // Manca lo Shaman, quindi non c'รจ un set completo. + + b10.applyEffect(p); + + assertEquals(0, p.getPrestigeValue()); } } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java index 89359e5..5316afd 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building11Test.java @@ -24,6 +24,9 @@ class Building11Test { Building11 b0 = new Building11(era, price, prestigeValue, ct, pm); + assertEquals(era, b0.getEra()); + assertEquals(price, b0.getPrice()); + assertEquals(prestigeValue, b0.getPrestigeValue()); assertEquals(EffectType.FINAL, b0.getEffectType()); assertEquals(11, b0.getEffectId()); assertEquals(ct, b0.getIcon()); @@ -33,6 +36,7 @@ class Building11Test { @Test @DisplayName("Testing clone method") void testClone() { + String idIMG = "building11.png"; int effectID = 11; EffectType effectType = EffectType.FINAL; int era = 1; @@ -40,51 +44,59 @@ class Building11Test { int prestigeValue = 1; CharacterType ct = CharacterType.ARTIST; int pm = 5; - Building11 b0 = new Building11(era, price, prestigeValue, ct, pm); + + Building11 b0 = new Building11(idIMG, era, price, prestigeValue, ct, pm); Building11 b1 = (Building11) b0.clone(); + assertEquals(idIMG, b1.getIdIMG()); assertEquals(effectID, b1.getEffectId()); assertEquals(effectType, b1.getEffectType()); assertEquals(era, b1.getEra()); assertEquals(price, b1.getPrice()); assertEquals(prestigeValue, b1.getPrestigeValue()); - assertEquals(ct, b0.getIcon()); - assertEquals(pm, b0.getPrestigeMul()); + assertEquals(ct, b1.getIcon()); + assertEquals(pm, b1.getPrestigeMul()); } @Test - void applyEffectBuyWithoutFood() { - + @DisplayName("Apply effect should throw if card was not bought due to missing food") + void applyEffectShouldThrowIfBuyFailed() { Player p1 = new Player("Xiaomi"); Building11 b1 = new Building11(2, 10, 1, ARTIST, -3); Artist a1 = new Artist(2); - b1.buy(p1); + assertFalse(b1.buy(p1)); + p1.artists.add(a1); - assertThrows(IllegalArgumentException.class, () -> { - b1.applyEffect(p1); - }); + assertThrows(IllegalArgumentException.class, () -> b1.applyEffect(p1)); + p1.addFood(b1.getPrice()); - b1.buy(p1); + assertTrue(b1.buy(p1)); + b1.applyEffect(p1); + assertEquals(-3, p1.getPrestigeValue()); } @Test + @DisplayName("Apply effect should add prestige for two cards of the required type") void applyEffectWithTwoCards() { Player p2 = new Player("Giacomo"); Building11 b2 = new Building11(2, 10, 1, ARTIST, 4); + Artist a2 = new Artist(2); Artist a3 = new Artist(2); + p2.addFood(b2.getPrice()); - b2.buy(p2); + assertTrue(b2.buy(p2)); + p2.artists.add(a2); p2.artists.add(a3); - b2.applyEffect(p2); + assertEquals(8, p2.getPrestigeValue()); } @@ -142,4 +154,42 @@ class Building11Test { b11 = new Building11(era, price, prestigeValue, ct, pm); assertEquals("โŽ•: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0) + " MP: " + pm, b11.toString()); } + + @Test + @DisplayName("Testing constructor with idIMG") + void testConstructorWithIdIMG() { + String idIMG = "building11.png"; + int era = 1; + int price = 10; + int prestigeValue = 5; + CharacterType ct = CharacterType.ARTIST; + int pm = 5; + + Building11 b11 = new Building11(idIMG, era, price, prestigeValue, ct, pm); + + assertEquals(idIMG, b11.getIdIMG()); + assertEquals(era, b11.getEra()); + assertEquals(price, b11.getPrice()); + assertEquals(prestigeValue, b11.getPrestigeValue()); + assertEquals(EffectType.FINAL, b11.getEffectType()); + assertEquals(11, b11.getEffectId()); + assertEquals(ct, b11.getIcon()); + assertEquals(pm, b11.getPrestigeMul()); + } + + @Test + @DisplayName("Apply effect should add zero prestige if player has no cards of the required type") + void applyEffectShouldAddZeroPrestigeWithoutRequiredCards() { + Player p = new Player("test"); + Building11 b11 = new Building11(1, 1, 1, ARTIST, 4); + + p.addFood(b11.getPrice()); + assertTrue(b11.buy(p)); + + b11.applyEffect(p); + + assertEquals(0, p.getPrestigeValue()); + } + + } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building13Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building13Test.java index 7a1ed5c..9a9f4e5 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building13Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building13Test.java @@ -18,6 +18,9 @@ class Building13Test { Building13 b0 = new Building13(era, price, prestigeValue); + assertEquals(era, b0.getEra()); + assertEquals(price, b0.getPrice()); + assertEquals(prestigeValue, b0.getPrestigeValue()); assertEquals(EffectType.FINAL, b0.getEffectType()); assertEquals(13, b0.getEffectId()); } @@ -25,15 +28,18 @@ class Building13Test { @Test @DisplayName("Testing clone method") void testClone() { + String idIMG = "building13.png"; int effectID = 13; EffectType effectType = EffectType.FINAL; int era = 1; int price = 1; int prestigeValue = 1; - Building13 b0 = new Building13(era, price,prestigeValue); + + Building13 b0 = new Building13(idIMG, era, price, prestigeValue); Building13 b1 = (Building13) b0.clone(); + assertEquals(idIMG, b1.getIdIMG()); assertEquals(effectID, b1.getEffectId()); assertEquals(effectType, b1.getEffectType()); assertEquals(era, b1.getEra()); @@ -42,14 +48,18 @@ class Building13Test { } @Test + @DisplayName("Apply effect should add 25 prestige points") void applyEffect() { Player p1 = new Player("gigi"); p1.addPrestige(10); - Building13 b1 = new Building13(1, 10, 1); - p1.addFood(b1.getPrice()); - b1.buy(p1); - b1.applyEffect(p1); + Building13 b13 = new Building13(1, 10, 1); + + p1.addFood(b13.getPrice()); + assertTrue(b13.buy(p1)); + + b13.applyEffect(p1); + assertEquals(35, p1.getPrestigeValue()); } @@ -61,12 +71,36 @@ class Building13Test { b13.applyEffect(p); }); } + @Test - void applyEffectMultiplePlayerException() { + @DisplayName("Buying same card by two different players") + void buyShouldRejectSameCardForDifferentPlayers() { Building13 b13 = new Building13(1, 10, 1); Player p1 = new Player("test1"); Player p2 = new Player("test2"); - b13.buy(p1); + + p1.addFood(b13.getPrice()); + p2.addFood(b13.getPrice()); + + assertTrue(b13.buy(p1)); assertFalse(b13.buy(p2)); } + + @Test + @DisplayName("Testing constructor with idIMG") + void testConstructorWithIdIMG() { + String idIMG = "building13.png"; + int era = 1; + int price = 10; + int prestigeValue = 5; + + Building13 b13 = new Building13(idIMG, era, price, prestigeValue); + + assertEquals(idIMG, b13.getIdIMG()); + assertEquals(era, b13.getEra()); + assertEquals(price, b13.getPrice()); + assertEquals(prestigeValue, b13.getPrestigeValue()); + assertEquals(EffectType.FINAL, b13.getEffectType()); + assertEquals(13, b13.getEffectId()); + } } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java index 0019f12..7257326 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building1Test.java @@ -5,6 +5,7 @@ import it.polimi.ingsw.gc14.Model.Player; import it.polimi.ingsw.gc14.Model.Cards.BuildingCard; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType; import static org.junit.jupiter.api.Assertions.*; @@ -52,19 +53,28 @@ class Building1Test { @Test @DisplayName("Clone") - void Clone(){ - int Era = 1; - int Price = 2; - int Prestige = 3; + void testClone() { + String idIMG = "building1.png"; + int era = 1; + int price = 2; + int prestigeValue = 3; CharacterType ct = CharacterType.INVENTOR; - Building1 b0 = new Building1(Era,Price,Prestige, ct); + + Building1 b0 = new Building1(idIMG, era, price, prestigeValue, ct); BuildingCard bClone = b0.clone(); - assertEquals(Era,b0.getEra()); - assertEquals(Price,b0.getPrice()); - assertEquals(Prestige, bClone.getPrestigeValue()); - assertEquals(ct, b0.getIcon()); + assertTrue(bClone instanceof Building1); + + Building1 clonedBuilding = (Building1) bClone; + + assertEquals(idIMG, clonedBuilding.getIdIMG()); + assertEquals(era, clonedBuilding.getEra()); + assertEquals(price, clonedBuilding.getPrice()); + assertEquals(prestigeValue, clonedBuilding.getPrestigeValue()); + assertEquals(ct, clonedBuilding.getIcon()); + assertEquals(EffectType.ON_EVENT, clonedBuilding.getEffectType()); + assertEquals(1, clonedBuilding.getEffectId()); } @Test @@ -75,7 +85,6 @@ class Building1Test { int price = 1; int prestigeValue = 3; CharacterType ct = CharacterType.ARTIST; - int pm = 5; Building1 b1 = new Building1(era, price, prestigeValue, ct); assertEquals("โŽ•: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); @@ -100,4 +109,24 @@ class Building1Test { b1 = new Building1(era, price, prestigeValue, ct); assertEquals("โŽ•: " + "ID:" + ID + " $:" + price + " PV:" + prestigeValue + " Icon: " + ct.toString().charAt(0), b1.toString()); } + + @Test + @DisplayName("Testing constructor with idIMG") + void testConstructorWithIdIMG() { + String idIMG = "building1.png"; + int era = 1; + int price = 2; + int prestigeValue = 3; + CharacterType icon = CharacterType.INVENTOR; + + Building1 b1 = new Building1(idIMG, era, price, prestigeValue, icon); + + assertEquals(idIMG, b1.getIdIMG()); + assertEquals(era, b1.getEra()); + assertEquals(price, b1.getPrice()); + assertEquals(prestigeValue, b1.getPrestigeValue()); + assertEquals(icon, b1.getIcon()); + assertEquals(EffectType.ON_EVENT, b1.getEffectType()); + assertEquals(1, b1.getEffectId()); + } } \ No newline at end of file diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building4Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building4Test.java index 206599c..71094e0 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building4Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building4Test.java @@ -43,15 +43,18 @@ class Building4Test { @Test @DisplayName("Testing clone method") void testClone() { + String idIMG = "building4.png"; int effectID = 4; EffectType effectType = EffectType.INVENTOR_PAIR; int era = 1; int price = 1; int prestigeValue = 1; - Building4 b0 = new Building4(era, price,prestigeValue); + + Building4 b0 = new Building4(idIMG, era, price, prestigeValue); Building4 b1 = (Building4) b0.clone(); + assertEquals(idIMG, b1.getIdIMG()); assertEquals(effectID, b1.getEffectId()); assertEquals(effectType, b1.getEffectType()); assertEquals(era, b1.getEra()); @@ -100,4 +103,55 @@ class Building4Test { assertThrows(IllegalArgumentException.class, () -> b4.applyEffect(p)); } + + @Test + @DisplayName("Testing constructor with idIMG") + void testConstructorWithIdIMG() { + String idIMG = "building4.png"; + int era = 1; + int price = 10; + int prestigeValue = 5; + + Building4 b4 = new Building4(idIMG, era, price, prestigeValue); + + assertEquals(idIMG, b4.getIdIMG()); + assertEquals(era, b4.getEra()); + assertEquals(price, b4.getPrice()); + assertEquals(prestigeValue, b4.getPrestigeValue()); + assertEquals(EffectType.INVENTOR_PAIR, b4.getEffectType()); + assertEquals(4, b4.getEffectId()); + } + + @Test + @DisplayName("Buying same card by two different players") + void buyShouldRejectSameCardForDifferentPlayers() { + Building4 b4 = new Building4(1, 1, 1); + Player p1 = new Player("test1"); + Player p2 = new Player("test2"); + + p1.addFood(b4.getPrice()); + p2.addFood(b4.getPrice()); + + assertTrue(b4.buy(p1)); + assertFalse(b4.buy(p2)); + } + + @Test + @DisplayName("Effect should reward multiple pairs of same inventor") + void applyEffectShouldRewardMultiplePairsOfSameInventor() { + Player p = new Player("test"); + Building4 b4 = new Building4(1, 1, 1); + + p.addFood(b4.getPrice()); + assertTrue(b4.buy(p)); + + new Inventor(1, 1).insert(p); + new Inventor(1, 1).insert(p); + new Inventor(1, 1).insert(p); + new Inventor(1, 1).insert(p); + + b4.applyEffect(p); + + assertEquals(6, p.getFoodValue()); + } } diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8Test.java index fc6268a..eafe534 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Cards/Building/Effects/Building8Test.java @@ -26,15 +26,18 @@ class Building8Test { @Test @DisplayName("Testing clone method") void testClone() { + String idIMG = "building8.png"; int effectID = 8; EffectType effectType = EffectType.FINAL; int era = 1; int price = 1; int prestigeValue = 1; - Building8 b0 = new Building8(era, price,prestigeValue); + + Building8 b0 = new Building8(idIMG, era, price, prestigeValue); Building8 b1 = (Building8) b0.clone(); + assertEquals(idIMG, b1.getIdIMG()); assertEquals(effectID, b1.getEffectId()); assertEquals(effectType, b1.getEffectType()); assertEquals(era, b1.getEra()); @@ -43,28 +46,25 @@ class Building8Test { } @Test + @DisplayName("Apply effect should add prestige from builders") void applyEffect() { Building8 b8 = new Building8(1, 1, 1); Player p = new Player("test"); + p.addFood(b8.getPrice()); - b8.buy(p); + assertTrue(b8.buy(p)); + + int era = 1; + + Builder builder1 = new Builder(era, 1, 2); + Builder builder2 = new Builder(era, 1, 3); - int Era = 1; - int PrestigeMul = 1; - Builder builder1 = new Builder(Era, 1, PrestigeMul); p.builders.add(builder1); + p.builders.add(builder2); b8.applyEffect(p); - assertEquals(1, p.buildingCards.stream().filter(x -> x.getEffectId() == 8).count()); - assertEquals(PrestigeMul* p.buildingCards.stream().filter(x -> x.getEffectId() == 8).count(), p.getPrestigeValue()); - - p.removePrestige(p.getPrestigeValue()); - Builder b2 = new Builder(Era, 1, PrestigeMul); - p.builders.add(b2); - b8.applyEffect(p); - - assertEquals(PrestigeMul * 2, p.getPrestigeValue()); + assertEquals(5, p.getPrestigeValue()); } @Test @@ -77,4 +77,25 @@ class Building8Test { assertThrows(IllegalArgumentException.class, () -> b8.applyEffect(p)); } + + @Test + @DisplayName("Testing constructor with idIMG") + void testConstructorWithIdIMG() { + String idIMG = "building8.png"; + int era = 1; + int price = 10; + int prestigeValue = 5; + + Building8 b8 = new Building8(idIMG, era, price, prestigeValue); + + assertEquals(idIMG, b8.getIdIMG()); + assertEquals(era, b8.getEra()); + assertEquals(price, b8.getPrice()); + assertEquals(prestigeValue, b8.getPrestigeValue()); + assertEquals(EffectType.FINAL, b8.getEffectType()); + assertEquals(8, b8.getEffectId()); + } + + + } \ No newline at end of file