Class CardImpl

java.lang.Object
ca.uqam.info.model.CardImpl
All Implemented Interfaces:
ca.uqam.info.mgl7010.max.skyjo.model.Card

public class CardImpl extends Object implements 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
    Constructor
    Description
     
    CardImpl(int value, ca.uqam.info.mgl7010.max.skyjo.model.CardType type)
    Constructs a new CardImpl with the specified type and value.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Compares this card to another object for equality.
    ca.uqam.info.mgl7010.max.skyjo.model.Card
    Getter the Card
    Getter to know if the card is reaveald
    ca.uqam.info.mgl7010.max.skyjo.model.CardType
    Returns the type of this card.
    int
    Returns the numeric value of this card.
    int
    Returns a hash code value for this card.
    void
    setReaveald(Boolean reaveald)
    Setter to set if the card is reaveal
    Returns a string representation of the card with exactly 2 characters.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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 inclusive
      type - 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:
      getType in interface ca.uqam.info.mgl7010.max.skyjo.model.Card
      Returns:
      the card type, never null
      See Also:
      • CardType
    • 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:
      getValue in interface ca.uqam.info.mgl7010.max.skyjo.model.Card
      Returns:
      the card value between -2 and 12
    • setReaveald

      public void setReaveald(Boolean reaveald)
      Setter to set if the card is reaveal
      Parameters:
      reaveald - as if the card is reaveald
    • getReaveald

      public Boolean getReaveald()
      Getter to know if the card is reaveald
      Returns:
      boolean
    • getCard

      public ca.uqam.info.mgl7010.max.skyjo.model.Card getCard()
      Getter the Card
      Returns:
      Card
    • toString

      public String 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"
      Overrides:
      toString in class Object
      Returns:
      string representation with exactly 2 characters, never null
    • equals

      public boolean equals(Object obj)
      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
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare with, may be null
      Returns:
      true if the objects are equal, false otherwise
      See Also:
    • 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
      Overrides:
      hashCode in class Object
      Returns:
      hash code value for this card
      See Also: