ch.aplu.jcardgame
Class Hand

java.lang.Object
  extended by ch.aplu.jcardgame.Hand
All Implemented Interfaces:
GGActListener, GGMouseTouchListener, java.util.EventListener

public class Hand
extends java.lang.Object
implements GGMouseTouchListener, GGActListener

Representation of a card set.

You find a general description of the CardGame library in the Card class documentation.

Hands are very useful containers for cards, not only for the cards in a player's hand, but also for storing card piles of any kind on the gambling table. Even when a hand contains a maximum of one card, it is preferable to individual cards, because the transfer from one hand to another is very simple. A hand can be empty (and displayed as such without harm). A hand may also serve as card store without being displayed during the whole game. It is not rare to use between 10 to 20 hands in a 4-player game application.

A hand stores the cards in an card list and most hand modifications will modify this list. A hand may be displayed in the card game (game grid) window in several layouts: stacked (a card pile, only the top card is seen), in a row, in a column and as fan. All hand operation methods will no shown the modifications until draw() is called. (All of them have a boolean doDraw parameter that can be set true to call draw() automatically.)

By default, the mouse touches are not enabled. To enable them, use setTouchEnabled(true). For RowLayout, ColumnLayout and FanLayout the card is automatically pulled on top of other cards when you left click on a visible part of the card (unless disabled by putOnTopEnabled(false)).

See Also:
Card

Nested Class Summary
static class Hand.CardAlignment
          Card alignment used when hand is drawn using drawRow(), drawColumn()
static class Hand.SortType
          Compare type used for the compareTo() implementation.
 
Constructor Summary
Hand(Deck deck)
          Creates a hand instance with game cards from the given deck.
 
Method Summary
 void act()
          For internal use only.
 void addCardListener(CardListener listener)
          Registers a card listener to get event notifications when a card is touched or arrives at its target.
 boolean contains(Card card)
          Returns true, if the a card with same suit and rank is found in the card list of current hand.
 void cut(int nb, boolean doDraw)
          Divides the current hand (as a deck of cards) into two batches and reassembles the batches in reverse order.
 void draw()
          Displays the hand using the current layout.
<R extends java.lang.Enum<R>>
Hand
extractCardsWithRank(R rank)
          Returns a hand containing card clones from card of the current hand that have the given rank.
<T extends java.lang.Enum<T>>
Hand
extractCardsWithSuit(T suit)
          Returns a hand containing card clones from card of the current hand that have the given suit.
 Hand[] extractPairs()
          Returns all hands with pairs (two cards with same rank) found in the current hand.
 Hand[] extractQuads()
          Returns all hands with quads (four cards with same rank) found in the current hand.
 Hand[] extractSequences(int length)
          Returns all sequences found in the current hand with mixed suits with given length (>2).
<T extends java.lang.Enum<T>>
Hand[]
extractSequences(T suit, int length)
          Returns all sequences found in the current hand that have given suit with given length (>2).
 Hand[] extractTrips()
          Returns all hands with trips (three cards with same rank) found in the current hand.
 Card get(int i)
          Returns card reference of the card at index i of the card list or null if the hand is empty.
 Card getCard(int cardNumber)
          Returns card reference of card in this hand with given card number.
<T extends java.lang.Enum<T>,R extends java.lang.Enum<R>>
Card
getCard(T suit, R rank)
          Returns card reference of the card in this hand with given suit and rank.
 java.util.ArrayList<Card> getCardList()
          Returns the card list of the current hand.
<R extends java.lang.Enum<R>>
java.util.ArrayList<Card>
getCardsWithRank(R rank)
          Returns a list containing the card references of all cards with given rank.
<T extends java.lang.Enum<T>>
java.util.ArrayList<Card>
getCardsWithSuit(T suit)
          Returns a list containing the card references of all cards with given suit.
 Card getFirst()
          Returns card reference of the first card or null if the hand is empty.
 Location getHandLocation()
          Returns a clone of the hand location.
 Card getLast()
          Returns card reference of the last card or null if the hand is empty.
 HandLayout getLayout()
          Returns the reference of the current HandLayout.
 int getMaxPosition(Hand.SortType sortType)
          Compares the cards in the card list using the given compare type.
 int getNumberOfCards()
          Returns the number of cards in the current hand.
<R extends java.lang.Enum<R>>
int
getNumberOfCardsWithRank(R rank)
          Returns the number of cards of given rank in the current hand.
<T extends java.lang.Enum<T>>
int
getNumberOfCardsWithSuit(T suit)
          Returns the number of cards of given suit in the current hand.
 java.util.ArrayList<Card[]> getPairs()
          Returns all pairs (two cards with same rank) found in the current hand.
 java.util.ArrayList<Card[]> getQuads()
          Returns all quads (four cards with same rank) found in the current hand.
 int getScore()
          Returns the sum of the card values (card points) of all card in the hand.
 java.util.ArrayList<Card[]> getSequences(int length)
          Returns all sequences found in the current hand with mixed suits with given length (>2).
<T extends java.lang.Enum<T>>
java.util.ArrayList<Card[]>
getSequences(T suit, int length)
          Returns all sequences found in the current hand that have given suit with given length (>2).
 Hand.SortType getSortType()
          Returns the compare type for cards used for sorting.
 TargetArea getTargetArea()
          Returns a reference to the current target area.
 java.util.ArrayList<Card[]> getTrips()
          Returns all trips (three cards with same rank) found in the current hand.
 boolean insert(Card card, boolean doDraw)
          Inserts the given card in the current hand (reference copy) and sets the hand of the given card to the current hand.
 boolean insert(Hand hand, boolean doDraw)
          Inserts all cards of the given hand in the current hand (reference copy) and sets the hand of the cards to the current hand.
 boolean insert(int cardNumber, boolean doDraw)
          Creates a new card with given card number and inserts it in the current hand.
<T extends java.lang.Enum<T>,R extends java.lang.Enum<R>>
boolean
insert(T suit, R rank, boolean doDraw)
          Creates a new card with given suit and rank and inserts it in the current hand.
 boolean isEmpty()
          Returns true, if the card list of the current hand is empty.
 boolean isTouchEnabled()
          Returns the current state of mouse touches.
 void mouseTouched(Actor actor, GGMouse mouse, java.awt.Point spot)
          Implementation of GGMouseTouchListener.
 void putOnTop(Card topCard)
          Draws the given card above each other card (on top) in this hand and rearrages the hand appearence so that all card are shown.
 void putOnTopEnabled(boolean enable)
          Enable/disables automatic putOnTop when the card is left-clicked.
static void randomBatchTransfer(int nb, Hand source, Hand target, boolean doDraw)
          Moves a randomly selected batch of cards from the source hand to the target hand.
 boolean remove(Card card, boolean doDraw)
          Removes card from the current hand.
 boolean remove(int index, boolean doDraw)
          Removes the card at given index from card list.
 void removeAll(boolean doRefresh)
          Removes every card in the current hand and from the game grid.
 void removeFirst(boolean doDraw)
          Removes first card from card list.
 void removeLast(boolean doDraw)
          Removes last card from card list.
 Card reverse(boolean doDraw)
          Reverses the order of the cards in the card list.
 Card reverseSort(Hand.SortType sortType, boolean doDraw)
          Sorts the card list with given sort type and reverses the list.
 void setCardGame(CardGame cardGame)
          Selects the card game instance where to display the hand's card.
 void setSortType(Hand.SortType sortType)
          Sets the compare type of cards used for sorting to one of the enumeration values defined in the SortType enumeration.
 void setTargetArea(TargetArea targetArea)
          Sets the transferring attributes for all cards in the current hand.
 void setTouchEnabled(boolean enable)
          Enables or disables mouse touch events.
 void setVerso(boolean isVerso)
          Sets the isVerso attribute to all cards in the card list.
 void setView(CardGame cardGame, HandLayout handLayout)
          Preparing to display the current hand in a game grid window using the given given layout.
 Card shift(boolean forward, boolean doDraw)
          Shifts (rolls) the card list forward or backward.
 Card shuffle(boolean doDraw)
          Shuffles the card list (random permutation of cards).
 Card sort(Hand.SortType sortType, boolean doDraw)
          Sorts the card list with given sort type.
 java.lang.String toString()
          Returns a string representation of all cards in the hand.
 void transfer(Card card, Hand targetHand, boolean doDraw)
          Transfers the card from the current hand to the given target hand using the currently defined target area.
 void transferNonBlocking(Card card, Hand targetHand, boolean doDraw)
          Same as transfer(card, targetHand, doDraw), but the methods returs immediately.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Hand

public Hand(Deck deck)
Creates a hand instance with game cards from the given deck. The layout is undefined.

Parameters:
deck - the deck where suit, rank and points are defined.
Method Detail

setCardGame

public void setCardGame(CardGame cardGame)
Selects the card game instance where to display the hand's card.

Parameters:
cardGame - the reference to the card game

mouseTouched

public void mouseTouched(Actor actor,
                         GGMouse mouse,
                         java.awt.Point spot)
Implementation of GGMouseTouchListener. For internal use only.

Specified by:
mouseTouched in interface GGMouseTouchListener
Parameters:
actor - the reference of the actor that reports the touch
mouse - the mouse reference to get to get information about the event
spot - the pixel coordinates relative to the mouse touch area where the event occurred

putOnTopEnabled

public void putOnTopEnabled(boolean enable)
Enable/disables automatic putOnTop when the card is left-clicked. Default: enabled, (setTouchEnabled(true) must be called to enable automatic putOnTop.)

Parameters:
enable - if true, the card is automatically put on top when clicked; otherwise the card must be manually put on top using one of the mouse events

putOnTop

public void putOnTop(Card topCard)
Draws the given card above each other card (on top) in this hand and rearrages the hand appearence so that all card are shown. For a stacked layout, nothing happens.

Parameters:
topCard - the card to put on top

addCardListener

public void addCardListener(CardListener listener)
Registers a card listener to get event notifications when a card is touched or arrives at its target.

Parameters:
listener - the CardListener to register

getScore

public int getScore()
Returns the sum of the card values (card points) of all card in the hand.

Returns:
the total amount of points

toString

public java.lang.String toString()
Returns a string representation of all cards in the hand.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the hand

insert

public boolean insert(Hand hand,
                      boolean doDraw)
Inserts all cards of the given hand in the current hand (reference copy) and sets the hand of the cards to the current hand. If a card is already part of the hand, the card in not reinserted.

Parameters:
hand - the hand from where to import the cards
doDraw - if true, the current hand is drawn
Returns:
true, if insertion is successful; false, if one of the cards could not be inserted, but all non-dublicated cards are inserted

insert

public boolean insert(Card card,
                      boolean doDraw)
Inserts the given card in the current hand (reference copy) and sets the hand of the given card to the current hand. If a card is already part of the hand, the card in not reinserted.

Parameters:
card - the card to insert
doDraw - if true, the current hand is drawn (showing the inserted card)
Returns:
true, if insertion is successful; otherwise false

insert

public boolean insert(int cardNumber,
                      boolean doDraw)
Creates a new card with given card number and inserts it in the current hand. If a card with same suit/rank is already part of the hand, the card in not inserted.

Parameters:
cardNumber - the card number of the card to insert
doDraw - if true, the current hand is drawn (showing the inserted card)
Returns:
true, if insertion is successful; otherwise false

insert

public <T extends java.lang.Enum<T>,R extends java.lang.Enum<R>> boolean insert(T suit,
                                                                                R rank,
                                                                                boolean doDraw)
Creates a new card with given suit and rank and inserts it in the current hand. If a card with same suit/rank is already part of the hand, the card in not inserted.

Type Parameters:
T - the Enum type of the suit
R - the Enum type of the rank
Parameters:
suit - the card suit
rank - the card rank
doDraw - if true, the current hand is drawn (showing the inserted card)
Returns:
true, if insertion is successful; otherwise false

removeFirst

public void removeFirst(boolean doDraw)
Removes first card from card list.

Parameters:
doDraw - if true, the current hand is drawn (not showing the card anymore)
See Also:
remove(Card card, boolean doDraw)

removeLast

public void removeLast(boolean doDraw)
Removes last card from card list.

Parameters:
doDraw - if true, the current hand is drawn (not showing the card anymore)
See Also:
remove(Card card, boolean doDraw)

remove

public boolean remove(int index,
                      boolean doDraw)
Removes the card at given index from card list. If i less than zero or greater than maximum index, nothing happens.

Parameters:
index - the index of the card to remove
doDraw - if true, the current hand is drawn (not showing the card anymore)
Returns:
true, if the card was removed from the hand; false, if index is is outside [0..size of card list - 1]
See Also:
remove(Card card, boolean doDraw)

remove

public boolean remove(Card card,
                      boolean doDraw)
Removes card from the current hand. If the card is part of the game grid, removes it also from the game grid, but the card reference is still valid. To show it again, the card actor must be added again to the game grid. (This is automatically done, when the card is reinserted into a hand and draw() is called).

Parameters:
card - the card to remove; if the card is not in the hand, nothing happens
doDraw - if true, the current hand is drawn (not showing the card anymore)
Returns:
true, if the card was removed from the hand; false, if it is not part of the hand

removeAll

public void removeAll(boolean doRefresh)
Removes every card in the current hand and from the game grid. The card list will be empty.

Parameters:
doRefresh - if true, the game grid is refreshed, so that the hand becomes immediately invisible

contains

public boolean contains(Card card)
Returns true, if the a card with same suit and rank is found in the card list of current hand.

Parameters:
card - the card to check
Returns:
true, if a card with same suit and rank is part of the current hand; otherwise false

isEmpty

public boolean isEmpty()
Returns true, if the card list of the current hand is empty.

Returns:
true, if the hand contains no cards; otherwise false

getCardList

public java.util.ArrayList<Card> getCardList()
Returns the card list of the current hand.

Returns:
the array list of all cards in this hand

getNumberOfCards

public int getNumberOfCards()
Returns the number of cards in the current hand.

Returns:
the size of the card list

getNumberOfCardsWithSuit

public <T extends java.lang.Enum<T>> int getNumberOfCardsWithSuit(T suit)
Returns the number of cards of given suit in the current hand.

Parameters:
suit - the suit of the cards
Returns:
the number of cards with specified suit

getNumberOfCardsWithRank

public <R extends java.lang.Enum<R>> int getNumberOfCardsWithRank(R rank)
Returns the number of cards of given rank in the current hand.

Parameters:
rank - the rank of the cards
Returns:
the number of cards with specified rank

get

public Card get(int i)
Returns card reference of the card at index i of the card list or null if the hand is empty. if i is outside the valid array range, returns null.

Returns:
the card reference (not a clone) at index i of the card list or null, if not found

getFirst

public Card getFirst()
Returns card reference of the first card or null if the hand is empty.

Returns:
the card reference (not a clone) at the first position of the card list (show on bottom of all other cards)

getLast

public Card getLast()
Returns card reference of the last card or null if the hand is empty.

Returns:
the card reference (not a clone) at the last position of the card list (shown on top of all other cards)

setVerso

public void setVerso(boolean isVerso)
Sets the isVerso attribute to all cards in the card list. If the cards are visible, they are immediately shown in the requested state.

Parameters:
isVerso - if true, all cards are shown face down; otherwise they are shown face up

setTargetArea

public void setTargetArea(TargetArea targetArea)
Sets the transferring attributes for all cards in the current hand. The cards are moved to the given target location (may be anywhere, not necessarily at the target hand location).

Parameters:
targetArea - the TargetArea used for the transfer

getTargetArea

public TargetArea getTargetArea()
Returns a reference to the current target area.

Returns:
the current target area

act

public void act()
For internal use only. Implements GGActListener to get act() events used for animation.

Specified by:
act in interface GGActListener

sort

public Card sort(Hand.SortType sortType,
                 boolean doDraw)
Sorts the card list with given sort type.

Parameters:
doDraw - if true, the hand is drawn
Returns:
card at last position of the card list (shown on top of other cards); null if hand is empty

reverseSort

public Card reverseSort(Hand.SortType sortType,
                        boolean doDraw)
Sorts the card list with given sort type and reverses the list.

Parameters:
sortType - the card compare type used for sorting
doDraw - if true, the hand is drawn
Returns:
card at last position of the card list (shown on top of other cards); null if hand is empty

shift

public Card shift(boolean forward,
                  boolean doDraw)
Shifts (rolls) the card list forward or backward. When shifting forward, the last element is reinserted at the beginning, when shifting backward, the first elementis reinserted at the end. Keep in mind that the order in the card list determines the paint order of the card images (actors at later list positions are drawn on top of others)

Parameters:
forward - if true, shifts to the right (forward); otherwise shifts to the left (backward)
doDraw - if true, the hand is drawn
Returns:
card at last position of the card list (shown on top of other cards); null if hand is empty

reverse

public Card reverse(boolean doDraw)
Reverses the order of the cards in the card list.

Parameters:
doDraw - if true, the hand is drawn
Returns:
card at last position of the card list (shown on top of other cards); null if hand is empty

shuffle

public Card shuffle(boolean doDraw)
Shuffles the card list (random permutation of cards).

Parameters:
doDraw - if true, the hand is drawn
Returns:
card at last position of the card list (shown on top of other; null if hand is empty

setTouchEnabled

public void setTouchEnabled(boolean enable)
Enables or disables mouse touch events. If the mouse events are generally disabled by calling GameGrid.setMouseEnabled(false), no mouse touch events are disabled too.

Parameters:
enable - if true, the mouse touches are enabled; otherwise disabled

isTouchEnabled

public boolean isTouchEnabled()
Returns the current state of mouse touches.

Returns:
true, if the mouse touches are enabled; otherwise false

setSortType

public void setSortType(Hand.SortType sortType)
Sets the compare type of cards used for sorting to one of the enumeration values defined in the SortType enumeration.

Parameters:
sortType - the compare type used for sorting

getSortType

public Hand.SortType getSortType()
Returns the compare type for cards used for sorting.

Returns:
one of the compare types defined in the SortType enumeration

getMaxPosition

public int getMaxPosition(Hand.SortType sortType)
Compares the cards in the card list using the given compare type. Returns the list position of the card with the maximum value. It is assumed that there is exactly one card with maximum value.

Parameters:
sortType - the compare type to apply
Returns:
the index of the card with the maximum value, -1 if the card list is empty

setView

public void setView(CardGame cardGame,
                    HandLayout handLayout)
Preparing to display the current hand in a game grid window using the given given layout. Any layout passed earlier is replaced.

Parameters:
cardGame - the reference of the CardGame where to display the hand
handLayout - the reference to a HandLayout instance; may be null, if the hand is never drawn, but the CardGame reference should be set

draw

public void draw()
Displays the hand using the current layout. Whenever a hand is drawn, the current card actor (if defined) of every card is removed from the game grid, recalculated from its seed actor and added back to the game grid. This is a somewhat time-consuming operation and hands should only be redrawn when needed. If setView() was never called, nothing happens. It may be necessary to draw an empty hand to set the hand location.


extractCardsWithSuit

public <T extends java.lang.Enum<T>> Hand extractCardsWithSuit(T suit)
Returns a hand containing card clones from card of the current hand that have the given suit. The cards are not removed from the current hand, so care must be taken because of card duplication. The cards are returned in rank order.

Type Parameters:
T - the type of the suit
Parameters:
suit - the requested suit
Returns:
a hand of cloned cards with given suit

getCardsWithSuit

public <T extends java.lang.Enum<T>> java.util.ArrayList<Card> getCardsWithSuit(T suit)
Returns a list containing the card references of all cards with given suit. The cards are returned in rank order.

Type Parameters:
T - the type of the suit
Parameters:
suit - the requested suit
Returns:
a list of cloned cards with given suit

extractCardsWithRank

public <R extends java.lang.Enum<R>> Hand extractCardsWithRank(R rank)
Returns a hand containing card clones from card of the current hand that have the given rank. The cards are not removed from the current hand, so care must be taken because of card duplication. The cards are returned in suit order.

Type Parameters:
R - the type of the rank
Parameters:
rank - the requested rank
Returns:
a hand of cloned cards with given rank

getCardsWithRank

public <R extends java.lang.Enum<R>> java.util.ArrayList<Card> getCardsWithRank(R rank)
Returns a list containing the card references of all cards with given rank. The cards are returned in suit order.

Type Parameters:
R - the type of the rank
Parameters:
rank - the requested rank
Returns:
a list of cards with given rank

getSequences

public java.util.ArrayList<Card[]> getSequences(int length)
Returns all sequences found in the current hand with mixed suits with given length (>2). The returned card arrays contains references to the cards in the current hand. The cards in the hands returned are ordered with SortType.RANKPRIORITY.

Cards belonging to a sequence longer than specified are not considered to be part of the shorter sequence.

Parameters:
length - the length of the requested sequence
Returns:
a array of hands with all sequences found; if no sequence is found or length < 3, the array has length = 0 (but is not null)

extractSequences

public Hand[] extractSequences(int length)
Returns all sequences found in the current hand with mixed suits with given length (>2). The returned hands contains cloned cards. The cards are not removed from the current hand, so care must be taken because of card duplication. The cards in the hands returned are ordered with SortType.RANKPRIORITY.

Cards belonging to a sequence longer than specified are not considered to be part of the shorter sequence.

Parameters:
length - the length of the requested sequence
Returns:
an array of hands with all sequences found; if no sequence is found or length < 3, the array has length = 0 (but is not null)

getSequences

public <T extends java.lang.Enum<T>> java.util.ArrayList<Card[]> getSequences(T suit,
                                                                              int length)
Returns all sequences found in the current hand that have given suit with given length (>2). The returned card arrays contains references to the cards in the current hand. The cards in the hands returned are ordered with SortType.RANKPRIORITY.

Cards belonging to a sequence longer than specified are not considered to be part of the shorter sequence.

Type Parameters:
T - the type of the suit
Parameters:
suit - the requested suit
length - the length of the requested sequence
Returns:
an array list of card arrays with all sequences found; if no sequence is found or length < 3, the array has length = 0 (but is not null)

extractSequences

public <T extends java.lang.Enum<T>> Hand[] extractSequences(T suit,
                                                             int length)
Returns all sequences found in the current hand that have given suit with given length (>2). The returned hands contains cloned cards. The original cards are not removed from the current hand, so care must be taken because of card duplication. The cards in the hands returned are ordered with SortType.RANKPRIORITY.

Cards belonging to a sequence longer than specified are not considered to be part of the shorter sequence.

Type Parameters:
T - the type of the suit
Parameters:
suit - the requested suit
length - the length of the requested sequence
Returns:
an array of hands with all sequences found; if no sequence is found or length < 3, the array has length = 0 (but is not null)

getPairs

public java.util.ArrayList<Card[]> getPairs()
Returns all pairs (two cards with same rank) found in the current hand. The returned card arrays have size 2 and contains the card references of the pairs. If the cards are part of a trip or quad they are not returned as part of a pair. The array list elements are in rank order, the cards in each pair are in suit order.

Returns:
an array list of card pairs; if no pair is found, the array list has size = 0 (but is not null)

getTrips

public java.util.ArrayList<Card[]> getTrips()
Returns all trips (three cards with same rank) found in the current hand. The returned card arrays have size 3 and contains the card references of the trips. If the cards are part of a quad they are not returned as part of a trip. The array list elements are in rank order, the cards in each trip are in suit order.

Returns:
an array list of card trips; if no trip is found, the array list has size = 0 (but is not null)

getQuads

public java.util.ArrayList<Card[]> getQuads()
Returns all quads (four cards with same rank) found in the current hand. The returned card arrays have size 4 and contains the card references of the quads. The array list elements are in rank order, the cards in each quad are in suit order.

Returns:
an array list of card quads; if no quad is found, the array list has size = 0 (but is not null)

extractPairs

public Hand[] extractPairs()
Returns all hands with pairs (two cards with same rank) found in the current hand. The returned hands contains cloned cards. The original cards are not removed from the current hand, so care must be taken because of card duplication. The array list elements are in rank order, the cards in each quad are in suit order.

Returns:
an array of hand of card pairs; if no pair is found, the array has size = 0 (but is not null)

extractTrips

public Hand[] extractTrips()
Returns all hands with trips (three cards with same rank) found in the current hand. The returned hands contains cloned cards. The original cards are not removed from the current hand, so care must be taken because of card duplication. The array list elements are in rank order, the cards in each quad are in suit order.

Returns:
an array of hand of card trips; if no trip is found, the array has size = 0 (but is not null)

extractQuads

public Hand[] extractQuads()
Returns all hands with quads (four cards with same rank) found in the current hand. The returned hands contains cloned cards. The original cards are not removed from the current hand, so care must be taken because of card duplication. The array list elements are in rank order, the cards in each quad are in suit order.

Returns:
an array of hand of card quads; if no quad is found, the array has size = 0 (but is not null)

getLayout

public HandLayout getLayout()
Returns the reference of the current HandLayout.

Returns:
the current HandLayout; null, if the layout is not set.

getHandLocation

public Location getHandLocation()
Returns a clone of the hand location.

Returns:
the hand location; null, if the hand location is not yet set (draw() not yet called)

cut

public void cut(int nb,
                boolean doDraw)
Divides the current hand (as a deck of cards) into two batches and reassembles the batches in reverse order.

Parameters:
nb - the number of cards in the first part. If less than one or greater than the number of cards nothing happens
doDraw - if true, the hand is drawn

randomBatchTransfer

public static void randomBatchTransfer(int nb,
                                       Hand source,
                                       Hand target,
                                       boolean doDraw)
Moves a randomly selected batch of cards from the source hand to the target hand. The cards are one-by-one randomly selected in the source hand, removed from the hand and inserted it in the target hand. If nb is greater or equal to the total number of cards in the source hand, all cards are transferred. The target hand is randomly shuffled. If doDraw = false neither the source hand nor the target hand are redrawn, but the removed cards disappears from a visible source hand.

Parameters:
nb - the number of cards to take out. If nb less or equals zero, an empty hand is returned; if nb is greater or equal to the number of cards in the given hand, a hand with all cards is returned
source - the hand where to take the cards
target - the hand where to insert the cards
doDraw - if true, the source hand and the target hand are redrawn

transfer

public void transfer(Card card,
                     Hand targetHand,
                     boolean doDraw)
Transfers the card from the current hand to the given target hand using the currently defined target area. If no target area is defined, the target hand location (that is defined, when the hand is drawn) is used as target location and the card transfer is animated.

For more advanced transferring option, define a target area with appropriate parameters.

The card is removed from from the current hand in inserted into the target hand. If the card is not part of this hand, nothing happens.

The method blocks until the card arrives at the target. Once arrived at the target an atTarget() notification is triggered.

The card is visible during the transfer and remains visible at the target location, even if no draw() of the target hand is invoked.

Parameters:
card - the card to transfer
targetHand - the hand where to transfer the card
doDraw - if true, the current hand and the target hand are drawn
See Also:
TargetArea

transferNonBlocking

public void transferNonBlocking(Card card,
                                Hand targetHand,
                                boolean doDraw)
Same as transfer(card, targetHand, doDraw), but the methods returs immediately. Use the atTarget callback to get a notification when the card arrived at its destination.

Parameters:
card - the card to transfer
targetHand - the hand where to transfer the card
doDraw - if true, the current hand and the target hand are drawn

getCard

public Card getCard(int cardNumber)
Returns card reference of card in this hand with given card number. The card face up or down, depending if the card is shown face-up or face-down in the hand.

Parameters:
cardNumber - the card number of the requested card
Returns:
the card with given card number; null, if card is not part of the hand

getCard

public <T extends java.lang.Enum<T>,R extends java.lang.Enum<R>> Card getCard(T suit,
                                                                              R rank)
Returns card reference of the card in this hand with given suit and rank. The card is face up or down, depending if the card is shown face-up or face-down in the hand.

Type Parameters:
T - the Enum type of the suit
R - the Enum type of the rank
Parameters:
suit - the card suit
rank - the card rank
Returns:
the card with given suit and rank; null, if card is not part of the hand