Class DeckHandler<T extends Card>

java.lang.Object
it.polimi.ingsw.am13.model.DeckHandler<T>
Type Parameters:
T - A subclass of Card

public class DeckHandler<T extends Card> extends Object
This class represents a deck and two visible cards which sit on the Field at all times.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Deck<T>
    This attributes contains the deck of cards.
    private final List<T>
    It stores the deck's two cards which are visible at all times on the field.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Deck and the two visible cards by drawing them from the deck.
  • Method Summary

    Modifier and Type
    Method
    Description
    Draws the Card at the top of this deck.
    drawFromTable(int visibleIndex)
    Draws a card from the visible ones anc unveils its replacement by drawing it from the
    Retrieves a copy of the first card of the deck without removing it.
    List of all visible cards (that are pickable during turn phases).
     
    boolean
    Checks if this deck is empty.
    pickCard(CardPlayableIF cardPlayable)
    If the specified card is found among the 3 "visible" (top of the deck and the 2 actually visibile), it is picked and returned.
    showFromTable(int visibleIndex)
    Retrieves a copy of the chosen visible card without removing it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • deck

      private final Deck<T extends Card> deck
      This attributes contains the deck of cards.
    • visibleCards

      private final List<T extends Card> visibleCards
      It stores the deck's two cards which are visible at all times on the field. The size is always 2. If deck is not empty, both cards are not-null. If the deck is empty, one or both of the cards can be null. The list is order-preserving (if a card is placed in pos 1, it will remain in pos 1 till it's removed)
  • Constructor Details

    • DeckHandler

      public DeckHandler(LinkedList<T> deck)
      Creates a new Deck and the two visible cards by drawing them from the deck.
      Parameters:
      deck - LinkedList of the deck's cards
  • Method Details

    • drawFromDeck

      public T drawFromDeck() throws InvalidDrawCardException
      Draws the Card at the top of this deck. Manages visibility of card drawn and new possible card visible
      Returns:
      a subclass of Card
      Throws:
      InvalidDrawCardException - if the deck is empty
    • drawFromTable

      public T drawFromTable(int visibleIndex) throws IndexOutOfBoundsException, InvalidDrawCardException
      Draws a card from the visible ones anc unveils its replacement by drawing it from the
      Parameters:
      visibleIndex - It's the spot from which the card is taken It can only be either 0 or 1
      Returns:
      the chosen card
      Throws:
      IndexOutOfBoundsException - if visibleIndex is an invalid index.
      InvalidDrawCardException - If the visible card is not present (is null)
    • showFromTable

      public T showFromTable(int visibleIndex)
      Retrieves a copy of the chosen visible card without removing it. This method should not be used to carry out the game flow.
      Parameters:
      visibleIndex - It's the spot from which the card is taken It can only be either 0 or 1
      Returns:
      the chosen card
      Throws:
      IndexOutOfBoundsException - if visibleIndex is an invalid index.
    • isDeckEmpty

      public boolean isDeckEmpty()
      Checks if this deck is empty.
      Returns:
      true if this deck is empty.
    • getDeckTop

      public T getDeckTop() throws InvalidDrawCardException
      Retrieves a copy of the first card of the deck without removing it. This method should not be used to carry out the game flow.
      Returns:
      the first card of the deck
      Throws:
      InvalidDrawCardException - if the deck is empty
    • getVisibleCards

      public List<T> getVisibleCards()
    • getPickables

      public List<T> getPickables()
      List of all visible cards (that are pickable during turn phases). The list is of size 3, with order: top of deck (with getVisibleSide()==Side.SIDEBACK), and 2 visible cards (with getVisibleSide()==Side.SIDEFRONT). Elements can be null. If the deck is empty but both cards are present, only the first element will be null. Besides first element, also one or both of the other ones can be null (if it remains only one or no cards of this type to be picked)
      Returns:
      A new list of visible cards (top of deck, 2 visible cards). The size is 3
    • pickCard

      public T pickCard(CardPlayableIF cardPlayable) throws InvalidDrawCardException
      If the specified card is found among the 3 "visible" (top of the deck and the 2 actually visibile), it is picked and returned. The method is thought for cards that can be picked and played in a later moment, hence the specified card must be playable.
      Parameters:
      cardPlayable - Card to be picked (if present)
      Returns:
      The card picked if present, null otherwise
      Throws:
      InvalidDrawCardException - ???