Class Player
java.lang.Object
it.polimi.ingsw.gc14.Model.Player
- All Implemented Interfaces:
Serializable
Default Player class; contains all identifiers and methods needed.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe currentArtistcards in the player's deck.The currentBuildercards in the player's deck.private final ArrayList<BuildingCard> The currentBuilding Cardsin the player's deck.private intThe current amount ofFoodthe Player possesses.The currentGatherercards in the player's deck.The currentHuntercards in the player's deck.The currentInventorcards in the player's deck.private static final intThe maximum length allowed for the username string.private intThe current amount ofPrestigethe Player possesses.The currentShamancards in the player's deck.private TotemsIdentifier for thePlayerwhen displaying the game through the GUI.private final StringUnique string identifier for players; must not benulland must not exceedMAX_USERNAME_LENGTHotherwise anIllegalArgumentExceptionwill be thrown when theconstructoris called. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFood(int value) Addsvalueamount of Food to the Player.voidaddPrestige(int value) Addsvalueamount of Prestige to the Player.booleanChecks equality between thisPlayerand another object.intGetter for the private attributefoodValue.intgetNType(CharacterType type) Counts the total number of cards of the specifiedCharacter Type.intGetter for the private attributeprestigeValue.intCounts the totalCharacter Cardsthe player currently possesses.getTotem()Returns the totem assigned to this player.Getter for the private attributeuserName.inthashCode()booleanremoveFood(int value) Removesvalueamount of Food from the Player.voidremovePrestige(int value) Removesvalueamount of Prestige from the Player.voidSets the totem for this player.toString()Prints thePlayer's attributes for theBoard's representation.
-
Field Details
-
MAX_USERNAME_LENGTH
private static final int MAX_USERNAME_LENGTHThe maximum length allowed for the username string.- See Also:
-
totem
-
userName
Unique string identifier for players; must not benulland must not exceedMAX_USERNAME_LENGTHotherwise anIllegalArgumentExceptionwill be thrown when theconstructoris called. -
buildingCards
The currentBuilding Cardsin the player's deck. -
artists
-
builders
-
inventors
-
gatherers
-
shamans
-
hunters
-
foodValue
private int foodValueThe current amount ofFoodthe Player possesses. Cannot be negative. -
prestigeValue
private int prestigeValueThe current amount ofPrestigethe Player possesses.
-
-
Constructor Details
-
Player
Constructor for the classPlayer. Each Player is uniquely identified by theuserName.- Parameters:
userName- Unique String identifier for a Player.- Throws:
IllegalArgumentException- whenuserNameis empty or exceedsMAX_USERNAME_LENGTH, with message:UserName is empty or exceeds maximum permitted length.- See Also:
-
-
Method Details
-
getUserName
-
getTotem
-
getTotCharacters
public int getTotCharacters()Counts the totalCharacter Cardsthe player currently possesses.- Returns:
int- Total Character Cards.
-
getNType
Counts the total number of cards of the specifiedCharacter Type. Character Type must not benull- Parameters:
type- the Character Type to be Counted.- Returns:
int- Total number of cards of giventype.
-
getBuildingCards
- Returns:
- this player's building cards.
-
getArtists
-
getBuilders
-
getInventors
-
getGatherers
-
getShamans
-
getHunters
-
getFoodValue
public int getFoodValue()Getter for the private attributefoodValue.- Returns:
int- The amount of Food the player possesses.
-
getPrestigeValue
public int getPrestigeValue()Getter for the private attributeprestigeValue.- Returns:
int- The amount of Prestige the Player possesses.
-
addFood
public void addFood(int value) Addsvalueamount of Food to the Player.- Parameters:
value- The amount of Food to be added. Should be non-negative.- See Also:
-
setTotem
Sets the totem for this player.- Parameters:
totem- the totem to assign.
-
removeFood
public boolean removeFood(int value) Removesvalueamount of Food from the Player.foodValuecannot go negative: returnsfalseifvalueexceeds the current food and leaves the value unchanged.- Parameters:
value- The amount of Food to be removed. Should be non-negative.- Returns:
trueif the Food is successfully removed,falseotherwise.- See Also:
-
addPrestige
public void addPrestige(int value) Addsvalueamount of Prestige to the Player.- Parameters:
value- The amount of Prestige to be added. Should be non-negative.- See Also:
-
removePrestige
public void removePrestige(int value) Removesvalueamount of Prestige from the Player.- Parameters:
value- The amount of Prestige to be removed. Should be non-negative.- See Also:
-
equals
Checks equality between thisPlayerand another object. Two players are equal if and only if they share the sameuserName. -
hashCode
-
toString
Prints thePlayer's attributes for theBoard's representation. Uses theUNICODEborder style. Includes:
-