Fix: missing JavaDoc comments and parameter tags

This commit is contained in:
MatteoPellegrino05
2026-05-06 18:49:45 +02:00
parent 35654f6823
commit c7d8af48cc
36 changed files with 161 additions and 97 deletions
-1
View File
@@ -1,7 +1,6 @@
<component name="InspectionProjectProfileManager"> <component name="InspectionProjectProfileManager">
<profile version="1.0"> <profile version="1.0">
<option name="myName" value="Project Default" /> <option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="MissingJavadoc" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="MissingJavadoc" enabled="true" level="WARNING" enabled_by_default="true" />
</profile> </profile>
</component> </component>
@@ -170,6 +170,17 @@ public class ClientLauncherTUI {
} }
} }
/**
* Lets the user choose one of the available active IPv4 network interfaces.
*
* <p>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 { public static String chooseNetworkInterface(Scanner scanner) throws Exception {
List<String> ips = new ArrayList<>(); List<String> ips = new ArrayList<>();
@@ -1,7 +1,5 @@
package it.polimi.ingsw.gc14.Model.Cards.Building; package it.polimi.ingsw.gc14.Model.Cards.Building;
/**
* Represents the possible effect types of building cards.
/** /**
* Represents the possible effect types of building cards. * Represents the possible effect types of building cards.
*/ */
@@ -24,10 +24,12 @@ public class Building0 extends BuildingCard {
private int numSet; private int numSet;
/** /**
* Constructor of the building * Constructor of the building.
* @param era The game era of the building. *
* @param price The price (in food) of the building. * @param idImage the image identifier of the building.
* @param prestigeValue The number of Prestige Points gained from this building at the end of the game. * @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) { public Building0(String idImage,int era,int price,int prestigeValue) {
super(idImage,era,price,prestigeValue); super(idImage,era,price,prestigeValue);
@@ -33,12 +33,15 @@ public class Building1 extends BuildingCard {
effectId = 1; effectId = 1;
this.icon = icon; this.icon = icon;
} }
/** /**
* Constructor of the building. * Constructor of the building.
* @param era The game era of the building. *
* @param price The price (in food) of the building. * @param idIMG the image identifier of the building.
* @param prestigeValue The number of Prestige Points gained from this building at the end of the game. * @param era the game era of the building.
* @param icon The character type used by the building effect. * @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) { public Building1(String idIMG,int era, int price,int prestigeValue, CharacterType icon) {
super(idIMG,era,price,prestigeValue); super(idIMG,era,price,prestigeValue);
@@ -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 era the era of the building card.
* @param price the price of the building card. * @param price the price of the building card.
* @param prestigeValue the prestige value of the building card. * @param prestigeValue the prestige value of the building card.
@@ -50,10 +50,12 @@ public class Building11 extends BuildingCard {
this.icon = icon; this.icon = icon;
this.PrestigeMul = prestigeMul; 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. * character type icon, and prestige multiplier.
* *
* @param idIMG the image identifier of the building card.
* @param era the era of the building card. * @param era the era of the building card.
* @param price the price of the building card. * @param price the price of the building card.
* @param prestigeValue the prestige value of the building card. * @param prestigeValue the prestige value of the building card.
@@ -23,9 +23,11 @@ public class Building13 extends BuildingCard{
effectType= EffectType.FINAL; effectType= EffectType.FINAL;
effectId=13; 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 era the era of the building card.
* @param price the price of the building card. * @param price the price of the building card.
* @param prestigeValue the prestige value of the building card. * @param prestigeValue the prestige value of the building card.
@@ -36,10 +36,12 @@ public class Building4 extends BuildingCard {
} }
/** /**
* Constructor of the building * Constructor of the building.
* @param era The game era of the building. *
* @param price The price (in food) of the building. * @param idIMG the image identifier of the building.
* @param prestigeValue The number of Prestige Points gained from this building at the end of the game. * @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) { public Building4(String idIMG,int era, int price,int prestigeValue) {
super(idIMG,era,price,prestigeValue); super(idIMG,era,price,prestigeValue);
@@ -24,10 +24,12 @@ public class Building8 extends BuildingCard {
} }
/** /**
* Constructor of the building * Constructor of the building.
* @param era The game era of the building. *
* @param price The price (in food) of the building. * @param idIMG the image identifier of the building.
* @param prestigeValue The number of Prestige Points gained from this building at the end of the game. * @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) { public Building8(String idIMG,int era, int price,int prestigeValue) {
super(idIMG,era,price,prestigeValue); super(idIMG,era,price,prestigeValue);
@@ -170,16 +170,18 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
} }
/** /**
* Creates a building card with the specified effect identifier, era, price, * Creates a building card with the specified image id, effect identifier, era,
* and prestige value. * price, and prestige value.
* The effect type is determined from the given effect identifier.
* *
* <p>The effect type is determined from the given effect identifier.
*
* @param idIMG the image identifier of the building card.
* @param effectId the identifier of the effect associated with the building card. * @param effectId the identifier of the effect associated with the building card.
* @param era the era of the building card. * @param era the era of the building card.
* @param price the price of the building card. * @param price the price of the building card.
* @param prestigeValue the prestige value of the building card. * @param prestigeValue the prestige value of the building card.
* @throws IllegalArgumentException if the effect identifier is not valid, * @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{ public BuildingCard(String idIMG,int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{
this.effectId = effectId; this.effectId = effectId;
@@ -50,10 +50,12 @@ public abstract class TribeCard extends PlayableCard implements Serializable {
public TribeCard(int Era,boolean isEventCard) { public TribeCard(int Era,boolean isEventCard) {
this(Era,isEventCard,0); 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. * 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 Era the era of the tribe card.
* @param isEventCard whether the card is an event 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. * and minimum number of players.
* *
* @param idIMG the image identifier of the tribe card.
* @param Era the era of the tribe card. * @param Era the era of the tribe card.
* @param isEventCard whether the card is an event card. * @param isEventCard whether the card is an event card.
* @param nMin the minimum number of players required for the card. * @param nMin the minimum number of players required for the card.
@@ -34,9 +34,11 @@ public abstract class Character extends TribeCard implements Cloneable {
super(Era,false ); super(Era,false );
this.type = type; 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 Era the era of the character card.
* @param type the type 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); super(Era,false ,nMin);
this.type = type; 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. * and minimum number of players.
* *
* @param idIMG the image identifier of the character card.
* @param Era the era of the character card. * @param Era the era of the character card.
* @param type the type of the character card. * @param type the type of the character card.
* @param nMin the minimum number of players required for the card. * @param nMin the minimum number of players required for the card.
@@ -1,7 +1,5 @@
package it.polimi.ingsw.gc14.Model.Cards.TribeCards; 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. * Represents the different types of character cards available in the game.
*/ */
@@ -34,6 +34,7 @@ public class Artist extends Character {
/** /**
* Creates an Artist character card with the specified era. * Creates an Artist character card with the specified era.
* *
* @param idIMG
* @param Era the era of the Artist card * @param Era the era of the Artist card
*/ */
public Artist(String idIMG,int Era) { public Artist(String idIMG,int Era) {
@@ -43,6 +44,7 @@ public class Artist extends Character {
/** /**
* 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 Era and minimum number of players required to play it.
* *
* @param idIMG
* @param Era the era of the Artist card * @param Era the era of the Artist card
* @param nMin the minimum number of players required for the card * @param nMin the minimum number of players required for the card
*/ */
@@ -89,6 +89,7 @@ public class Builder extends Character {
* Creates a Builder character card with the specified era, reduction value, * Creates a Builder character card with the specified era, reduction value,
* and prestige value. * and prestige value.
* *
* @param idIMG the image identifier of the Builder card.
* @param Era the era of the Builder card. * @param Era the era of the Builder card.
* @param reductionValue the reduction value of the Builder card. * @param reductionValue the reduction value of the Builder card.
* @param prestigeValue the prestige 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, * Creates a Builder character card with the specified era, reduction value,
* prestige value, and minimum number of players. * 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 Era the era of the Builder card.
* @param reductionValue the reduction value of the Builder card. * @param reductionValue the reduction value of the Builder card.
* @param prestigeValue the prestige value of the Builder card. * @param prestigeValue the prestige value of the Builder card.
@@ -34,15 +34,18 @@ public class Gatherer extends Character {
/** /**
* Creates a Gatherer character card with the specified era. * 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) { public Gatherer(String idIMG,int Era) {
super(idIMG,Era, CharacterType.GATHERER); 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 Era the era of the Gatherer card.
* @param nMin the minimum number of players required for the card. * @param nMin the minimum number of players required for the card.
*/ */
@@ -51,9 +51,11 @@ public class Hunter extends Character {
super(Era, CharacterType.HUNTER,nMin); super(Era, CharacterType.HUNTER,nMin);
this.icon = icon; 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 Era the era of the Hunter card.
* @param icon the icon value 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. * and minimum number of players.
* *
* @param idIMG the image identifier of the Hunter card.
* @param Era the era of the Hunter card. * @param Era the era of the Hunter card.
* @param icon the icon value of the Hunter card. * @param icon the icon value of the Hunter card.
* @param nMin the minimum number of players required for the card. * @param nMin the minimum number of players required for the card.
@@ -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 Era the era of the Inventor card.
* @param icon the icon value of the Inventor card. * @param icon the icon value of the Inventor card.
* @throws IllegalArgumentException if {@code icon < 0} or {@code icon > 9}. * @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. * and minimum number of players.
* *
* @param idIMG the image identifier of the Inventor card.
* @param Era the era of the Inventor card. * @param Era the era of the Inventor card.
* @param icon the icon value of the Inventor card. * @param icon the icon value of the Inventor card.
* @param nMin the minimum number of players required for the card. * @param nMin the minimum number of players required for the card.
@@ -83,6 +85,7 @@ public class Inventor extends Character {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
this.icon = icon; this.icon = icon;
} }
/** /**
* Returns the string representation of this Inventor card. * Returns the string representation of this Inventor card.
* *
@@ -52,9 +52,11 @@ public class Shaman extends Character {
super(Era, CharacterType.SHAMAN,nMin); super(Era, CharacterType.SHAMAN,nMin);
this.icon = icon; 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 Era the era of the Shaman card.
* @param icon the icon value 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. * and minimum number of players.
* *
* @param idIMG the image identifier of the Shaman card.
* @param Era the era of the Shaman card. * @param Era the era of the Shaman card.
* @param icon the icon value of the Shaman card. * @param icon the icon value of the Shaman card.
* @param nMin the minimum number of players required for the card. * @param nMin the minimum number of players required for the card.
@@ -41,9 +41,11 @@ public abstract class EventCard extends TribeCard {
super(Era,true); super(Era,true);
this.type = type; 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 Era the era of the event card.
* @param type the type of the event card. * @param type the type of the event card.
*/ */
@@ -1,7 +1,5 @@
package it.polimi.ingsw.gc14.Model.Cards.TribeCards; 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. * Represents the different types of event cards available in the game.
*/ */
@@ -47,9 +47,11 @@ public class CavePaintings extends EventCard {
this.NPrestigeRem = NPrestigeRem; this.NPrestigeRem = NPrestigeRem;
this.NPrestigeMul = NPrestigeMul; 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 Era the era of the event card.
* @param NLower the minimum number of Artist cards required to avoid the prestige penalty. * @param NLower the minimum number of Artist cards required to avoid the prestige penalty.
* @param NPrestigeRem the amount of Prestige removed if the player has fewer Artist cards than {@code NLower}. * @param NPrestigeRem the amount of Prestige removed if the player has fewer Artist cards than {@code NLower}.
@@ -30,11 +30,13 @@ public class Hunt extends EventCard {
this.foodMultiplier = 1; this.foodMultiplier = 1;
this.prestigeMultiplier = prestigeMultiplier; this.prestigeMultiplier = prestigeMultiplier;
} }
/** /**
* Creates a new Hunt event card. * Creates a new Hunt event card.
* *
* @param Era the era of the card * @param idIMG the image identifier of the Hunt event card.
* @param prestigeMultiplier prestige points multiplicator used during the event * @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) { public Hunt(String idIMG,int Era, int prestigeMultiplier) {
super(idIMG,Era, EventType.HUNT); super(idIMG,Era, EventType.HUNT);
@@ -45,7 +47,6 @@ public class Hunt extends EventCard {
/** /**
* Activates the event card "Hunt". * Activates the event card "Hunt".
* Each player takes 1 Food and gains Prestige Points for each Hunter in their tribe. * Each player takes 1 Food and gains Prestige Points for each Hunter in their tribe.
*
* Buildings influence: * Buildings influence:
* Building 7: the player takes 1 Food and 1 additional Prestige Point for each Hunter. * Building 7: the player takes 1 Food and 1 additional Prestige Point for each Hunter.
* *
@@ -34,12 +34,14 @@ public class ShamanicRitual extends EventCard {
this.prestigeToRemove = prestigeToRemove; this.prestigeToRemove = prestigeToRemove;
} }
/** /**
* Creates a new ShamanicRitual event card. * Creates a new ShamanicRitual event card.
* *
* @param Era the era of the card * @param idIMG the image identifier of the ShamanicRitual event card.
* @param prestigeToAdd prestige points awarded to the player with the most icons * @param Era the era of the card.
* @param prestigeToRemove prestige points removed from the player with the fewest icons * @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) { public ShamanicRitual(String idIMG,int Era, int prestigeToAdd, int prestigeToRemove) {
super(idIMG,Era, EventType.SHAMANIC_RITUAL); 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. * 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. * 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. * If all players have the same amount of icons, they all gain and lose Prestige Points.
*
* Buildings influence: * Buildings influence:
* Building 2: if you have the lowest number of icons, you don't lose Prestige Points * 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 * Building 5: during the Shamanic Ritual, you gain 3 icons
@@ -39,9 +39,11 @@ public class Sustenance extends EventCard {
super(Era, EventType.SUSTENANCE); super(Era, EventType.SUSTENANCE);
this.PrestigeDebt = PrestigeDebt; 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 Era the era of the event card.
* @param PrestigeDebt the prestige penalty multiplier for unpaid Food units. * @param PrestigeDebt the prestige penalty multiplier for unpaid Food units.
*/ */
@@ -63,7 +63,13 @@ public class Game implements Serializable {
* The mapping between slots and the players assigned to them. * The mapping between slots and the players assigned to them.
*/ */
private HashMap<Slot,Player> slotMap; private HashMap<Slot,Player> slotMap;
public HashMap<Slot,Player> getSlotMap() {return slotMap;};
/**
* Returns the map of slots assigned to players.
*
* @return the map that associates each slot with the corresponding player.
*/
public HashMap<Slot,Player> getSlotMap() {return slotMap;}
/** /**
* The configured number of players for this game. * The configured number of players for this game.
@@ -718,22 +724,14 @@ public class Game implements Serializable {
currentState.GameStageUpdate(GameStages.RES_EVENT); currentState.GameStageUpdate(GameStages.RES_EVENT);
if (currentState.getRound() < 10) { if (currentState.getRound() < 10) {
nextRound(); nextRound();
currentState.PlayerUpdate(orderLogicCard.pull(), null); currentState.PlayerUpdate(orderLogicCard.pull(), null);
currentState.GameStageUpdate(GameStages.SLOT_CHOICE); currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
} else { } else {
currentState.GameStageUpdate(GameStages.ENDING); currentState.GameStageUpdate(GameStages.ENDING);
endGame(); endGame();
} }
return;
/**
* Checks whether there are any drawable lower tribe cards on the board,
* i.e. lower tribe cards that are not event cards.
*
* @return {@code true} if at least one non-event lower tribe card is available, {@code false} otherwise.
*/
} }
} }
@@ -1,7 +1,5 @@
package it.polimi.ingsw.gc14.Model.GamePackage; package it.polimi.ingsw.gc14.Model.GamePackage;
/**
* Represents the possible stages of a game.
/** /**
* Represents the possible stages of a game. * Represents the possible stages of a game.
*/ */
@@ -8,7 +8,16 @@ import java.io.Serializable;
*/ */
public abstract class PlayableCard implements Serializable { public abstract class PlayableCard implements Serializable {
/**
* The image identifier of the playable card.
*/
private String idIMG; private String idIMG;
/**
* Returns the image identifier of this playable card.
*
* @return the image identifier of this playable card.
*/
public String getIdIMG() { public String getIdIMG() {
return idIMG; 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. * @param Era the era of the playable card.
* @throws IllegalArgumentException if {@code Era <= 0} or {@code Era >= 4}. * @throws IllegalArgumentException if {@code Era <= 0} or {@code Era >= 4}.
*/ */
@@ -1,12 +1,5 @@
package it.polimi.ingsw.gc14.Network; package it.polimi.ingsw.gc14.Network;
/**
* Represents the possible actions requested by a client and handled by the
* server during the game.
*
* <p>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 * Represents the different types of network events that can be sent between
* client and server. * client and server.
@@ -30,13 +30,18 @@ public class RMIClient implements IClient {
/** Client game's controller */ /** Client game's controller */
ClientController controller; ClientController controller;
/**
* Local IP address of the RMI client.
*/
private String myIP; private String myIP;
/** /**
* Class constructor. * Class constructor.
* @param controller the client controller used to create the callback *
* @param host the host address of the RMI server * @param controller the client controller used to create the callback.
* @param port the port of the RMI server * @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) { public RMIClient(ClientController controller, String host, int port, String myIP) {
this.controller=controller; this.controller=controller;
@@ -54,11 +54,13 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
/** /**
* Class constructor that initializes the attributes. * Class constructor that initializes the attributes.
* @param controller The game controller *
* @param nPort The RMI port * @param controller the game controller.
* @param actionQueue The action queue * @param nPort the RMI port.
* @param playerList The player's usernames list * @param actionQueue the action queue.
* @throws RemoteException if an RMI error occurs * @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<NetworkEvent> actionQueue,LimitedList<String> playerList,String host) throws RemoteException { public RMIServer(GameController controller, int nPort, BlockingQueue<NetworkEvent> actionQueue,LimitedList<String> playerList,String host) throws RemoteException {
this.controller = controller; this.controller = controller;
@@ -68,9 +70,6 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
this.host = host; this.host = host;
} }
// RMI's exposed methods
/** /**
* Allows a player to join the game. * Allows a player to join the game.
* If the desired number of player is invalid, the request is rejected. * If the desired number of player is invalid, the request is rejected.
@@ -220,8 +219,13 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
// RMI's internal methods // RMI's internal methods
/** /**
* Sends an action to all RMI clients. * Sends an action to the RMI clients.
* @param action The desired action *
* <p>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 { public void notifyAll(NetworkEvent action) throws RemoteException {
for (Map.Entry<String,IClientCallback> entry : clients.entrySet()) { for (Map.Entry<String,IClientCallback> entry : clients.entrySet()) {
@@ -233,7 +237,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
/** /**
* Sends a game model to all RMI clients. * 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 { public void notifyAll(Game model) throws RemoteException {
for (IClientCallback cb : clients.values()) { for (IClientCallback cb : clients.values()) {
@@ -19,6 +19,12 @@ public class ClientHandler implements Runnable {
* The username of the connected client on this handler * The username of the connected client on this handler
*/ */
private final String username; private final String username;
/**
* Returns the username associated with this client.
*
* @return the username associated with this client.
*/
public String getUsername() { public String getUsername() {
return username; return username;
} }
@@ -44,6 +50,7 @@ public class ClientHandler implements Runnable {
/** /**
* Class constructor that initializes the attributes. * 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 clientSocket the socket representing the client's TCP connection.
* @param out the output stream used to send data to the client. * @param out the output stream used to send data to the client.
* @param in the input stream used to receive data from the client. * @param in the input stream used to receive data from the client.
@@ -65,10 +65,8 @@ public class TCPServer {
* Starts the TCP server. * Starts the TCP server.
* If the first event is not AddPlayer, the request is rejected. * If the first event is not AddPlayer, the request is rejected.
* If the desired number of player is invalid, 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 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 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. * If any error occurs, the server sends -1 back to the client. Otherwise, it sends 1.
*/ */
public void start(){ public void start(){
@@ -19,7 +19,6 @@ import java.net.*;
/** /**
* Main server launcher that handles both TCP and RMI connections. * Main server launcher that handles both TCP and RMI connections.
* The workflow is divided into two parts: game creation and game execution. * The workflow is divided into two parts: game creation and game execution.
*
* The process flow for game creation is as follows: * 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 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)} * - 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)}
@@ -31,7 +31,6 @@ public class TUI implements IView {
/** /**
* The {@link Game} model whose state is rendered. * The {@link Game} model whose state is rendered.
* Updated via {@link #update(Game)} whenever the game state changes.
*/ */
private Game model; private Game model;