java.lang.Object
it.polimi.ingsw.am13.model.DeckHandler<T>
- Type Parameters:
T
- A subclass ofCard
This class represents a deck and two visible cards
which sit on the Field at all times.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDeckHandler
(LinkedList<T> deck) Creates a newDeck
and the two visible cards by drawing them from the deck. -
Method Summary
Modifier and TypeMethodDescriptionDraws 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 theRetrieves 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.
-
Field Details
-
deck
This attributes contains the deck of cards. -
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
Creates a newDeck
and the two visible cards by drawing them from the deck.- Parameters:
deck
- LinkedList of the deck's cards
-
-
Method Details
-
drawFromDeck
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
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
- ifvisibleIndex
is an invalid index.InvalidDrawCardException
- If the visible card is not present (is null)
-
showFromTable
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
- ifvisibleIndex
is an invalid index.
-
isDeckEmpty
public boolean isDeckEmpty()Checks if this deck is empty.- Returns:
true
if this deck is empty.
-
getDeckTop
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
-
getPickables
List of all visible cards (that are pickable during turn phases). The list is of size 3, with order: top of deck (withgetVisibleSide()==Side.SIDEBACK
), and 2 visible cards (withgetVisibleSide()==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
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
- ???
-