Class CardImpl
java.lang.Object
ca.uqam.info.model.CardImpl
- All Implemented Interfaces:
ca.uqam.info.mgl7010.max.skyjo.model.Card
Implementation of the Card interface representing a Skyjo card.
Cards are immutable and have a type and value.
This class implements the Card interface and provides concrete
functionality for card operations. All card instances are immutable
meaning their state cannot be changed after creation.
The toString() method is particularly important as it must always
return a string of exactly 2 characters for proper display in the
game visualizer.
- Version:
- 1.10
- Author:
- Mohamed Latif Diallo, Hamza Afif, Ussel Sabbat
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares this card to another object for equality.ca.uqam.info.mgl7010.max.skyjo.model.CardgetCard()Getter the CardGetter to know if the card is reavealdca.uqam.info.mgl7010.max.skyjo.model.CardTypegetType()Returns the type of this card.intgetValue()Returns the numeric value of this card.inthashCode()Returns a hash code value for this card.voidsetReaveald(Boolean reaveald) Setter to set if the card is reavealtoString()Returns a string representation of the card with exactly 2 characters.
-
Constructor Details
-
CardImpl
public CardImpl(int value, ca.uqam.info.mgl7010.max.skyjo.model.CardType type) Constructs a new CardImpl with the specified type and value. The card is immutable once created.- Parameters:
value- the value of the card, must be between -2 and 12 inclusivetype- the type of the card, must not be null- Throws:
IllegalArgumentException- if type is null or value is outside valid range
-
CardImpl
public CardImpl()
-
-
Method Details
-
getType
public ca.uqam.info.mgl7010.max.skyjo.model.CardType getType()Returns the type of this card. The card type determines the visual appearance and category of the card in the game.- Specified by:
getTypein interfaceca.uqam.info.mgl7010.max.skyjo.model.Card- Returns:
- the card type, never null
- See Also:
-
getValue
public int getValue()Returns the numeric value of this card. The value is used for scoring and game mechanics. Valid values range from -2 to 12 inclusive.- Specified by:
getValuein interfaceca.uqam.info.mgl7010.max.skyjo.model.Card- Returns:
- the card value between -2 and 12
-
setReaveald
Setter to set if the card is reaveal- Parameters:
reaveald- as if the card is reaveald
-
getReaveald
-
getCard
public ca.uqam.info.mgl7010.max.skyjo.model.Card getCard()Getter the Card- Returns:
- Card
-
toString
Returns a string representation of the card with exactly 2 characters. This format is required for proper alignment in the game visualizer. Format rules: - Positive numbers (0-12): right-aligned with leading space for single digits - Negative numbers (-2, -1): naturally occupy 2 characters Examples: - Value 0 returns " 0" - Value 5 returns " 5" - Value 12 returns "12" - Value -2 returns "-2" - Value -1 returns "-1" -
equals
Compares this card to another object for equality. Two cards are considered equal if they have the same type and value. Equality contract: - Reflexive: x.equals(x) returns true - Symmetric: x.equals(y) returns true iff y.equals(x) returns true - Transitive: if x.equals(y) and y.equals(z) then x.equals(z) - Consistent: multiple invocations return same result - Handles null: x.equals(null) returns false -
hashCode
public int hashCode()Returns a hash code value for this card. The hash code is computed based on the card's type and value. This ensures consistency with the equals() method. Hash code contract: - Consistent: multiple invocations return same value - Equal objects have equal hash codes - Unequal objects should ideally have different hash codes
-