public class Hand extends java.lang.Object implements GGMouseTouchListener, GGActListener
Card
Modifier and Type | Class and Description |
---|---|
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 and Description |
---|
Hand(Deck deck)
Creates a hand instance with game cards from the given deck.
|
Modifier and Type | Method and Description |
---|---|
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>> |
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>> |
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>> |
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>> |
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>> |
getCardsWithRank(R rank)
Returns a list containing the card references of all cards with given rank.
|
<T extends java.lang.Enum<T>> |
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>> |
getNumberOfCardsWithRank(R rank)
Returns the number of cards of given rank in the current hand.
|
<T extends java.lang.Enum<T>> |
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>> |
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>> |
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.
|
public Hand(Deck deck)
deck
- the deck where suit, rank and points are defined.public void setCardGame(CardGame cardGame)
cardGame
- the reference to the card gamepublic void mouseTouched(Actor actor, GGMouse mouse, java.awt.Point spot)
mouseTouched
in interface GGMouseTouchListener
actor
- the reference of the actor that reports the touchmouse
- the mouse reference to get to get information about the eventspot
- the pixel coordinates relative to the mouse touch area where the event occurredpublic void putOnTopEnabled(boolean enable)
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
eventspublic void putOnTop(Card topCard)
topCard
- the card to put on toppublic void addCardListener(CardListener listener)
listener
- the CardListener to registerpublic int getScore()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean insert(Hand hand, boolean doDraw)
hand
- the hand from where to import the cardsdoDraw
- if true, the current hand is drawnpublic boolean insert(Card card, boolean doDraw)
card
- the card to insertdoDraw
- if true, the current hand is drawn (showing the inserted card)public boolean insert(int cardNumber, boolean doDraw)
cardNumber
- the card number of the card to insertdoDraw
- if true, the current hand is drawn (showing the inserted card)public <T extends java.lang.Enum<T>,R extends java.lang.Enum<R>> boolean insert(T suit, R rank, boolean doDraw)
T
- the Enum type of the suitR
- the Enum type of the ranksuit
- the card suitrank
- the card rankdoDraw
- if true, the current hand is drawn (showing the inserted card)public void removeFirst(boolean doDraw)
doDraw
- if true, the current hand is drawn
(not showing the card anymore)remove(Card card, boolean doDraw)
public void removeLast(boolean doDraw)
doDraw
- if true, the current hand is drawn
(not showing the card anymore)remove(Card card, boolean doDraw)
public boolean remove(int index, boolean doDraw)
index
- the index of the card to removedoDraw
- if true, the current hand is drawn
(not showing the card anymore)remove(Card card, boolean doDraw)
public boolean remove(Card card, boolean doDraw)
card
- the card to remove; if the card is not in the hand, nothing happensdoDraw
- if true, the current hand is drawn
(not showing the card anymore)public void removeAll(boolean doRefresh)
doRefresh
- if true, the game grid is refreshed, so that the
hand becomes immediately invisiblepublic boolean contains(Card card)
card
- the card to checkpublic boolean isEmpty()
public java.util.ArrayList<Card> getCardList()
public int getNumberOfCards()
public <T extends java.lang.Enum<T>> int getNumberOfCardsWithSuit(T suit)
suit
- the suit of the cardspublic <R extends java.lang.Enum<R>> int getNumberOfCardsWithRank(R rank)
rank
- the rank of the cardspublic Card get(int i)
public Card getFirst()
public Card getLast()
public void setVerso(boolean isVerso)
isVerso
- if true, all cards are shown face down; otherwise they are
shown face uppublic void setTargetArea(TargetArea targetArea)
targetArea
- the TargetArea used for the transferpublic TargetArea getTargetArea()
public void act()
act
in interface GGActListener
public Card sort(Hand.SortType sortType, boolean doDraw)
doDraw
- if true, the hand is drawnpublic Card reverseSort(Hand.SortType sortType, boolean doDraw)
sortType
- the card compare type used for sortingdoDraw
- if true, the hand is drawnpublic Card shift(boolean forward, boolean doDraw)
forward
- if true, shifts to the right (forward); otherwise
shifts to the left (backward)doDraw
- if true, the hand is drawnpublic Card reverse(boolean doDraw)
doDraw
- if true, the hand is drawnpublic Card shuffle(boolean doDraw)
doDraw
- if true, the hand is drawnpublic void setTouchEnabled(boolean enable)
enable
- if true, the mouse touches are enabled; otherwise disabledpublic boolean isTouchEnabled()
public void setSortType(Hand.SortType sortType)
sortType
- the compare type used for sortingpublic Hand.SortType getSortType()
public int getMaxPosition(Hand.SortType sortType)
sortType
- the compare type to applypublic void setView(CardGame cardGame, HandLayout handLayout)
cardGame
- the reference of the CardGame where to display the handhandLayout
- the reference to a HandLayout instance; may be null, if
the hand is never drawn, but the CardGame reference should be setpublic void draw()
public <T extends java.lang.Enum<T>> Hand extractCardsWithSuit(T suit)
T
- the type of the suitsuit
- the requested suitpublic <T extends java.lang.Enum<T>> java.util.ArrayList<Card> getCardsWithSuit(T suit)
T
- the type of the suitsuit
- the requested suitpublic <R extends java.lang.Enum<R>> Hand extractCardsWithRank(R rank)
R
- the type of the rankrank
- the requested rankpublic <R extends java.lang.Enum<R>> java.util.ArrayList<Card> getCardsWithRank(R rank)
R
- the type of the rankrank
- the requested rankpublic java.util.ArrayList<Card[]> getSequences(int length)
length
- the length of the requested sequencepublic Hand[] extractSequences(int length)
length
- the length of the requested sequencepublic <T extends java.lang.Enum<T>> java.util.ArrayList<Card[]> getSequences(T suit, int length)
T
- the type of the suitsuit
- the requested suitlength
- the length of the requested sequencepublic <T extends java.lang.Enum<T>> Hand[] extractSequences(T suit, int length)
T
- the type of the suitsuit
- the requested suitlength
- the length of the requested sequencepublic java.util.ArrayList<Card[]> getPairs()
public java.util.ArrayList<Card[]> getTrips()
public java.util.ArrayList<Card[]> getQuads()
public Hand[] extractPairs()
public Hand[] extractTrips()
public Hand[] extractQuads()
public HandLayout getLayout()
public Location getHandLocation()
public void cut(int nb, boolean doDraw)
nb
- the number of cards in the first part. If less than one or greater
than the number of cards nothing happensdoDraw
- if true, the hand is drawnpublic static void randomBatchTransfer(int nb, Hand source, Hand target, boolean doDraw)
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 returnedsource
- the hand where to take the cardstarget
- the hand where to insert the cardsdoDraw
- if true, the source hand and the target hand are redrawnpublic void transfer(Card card, Hand targetHand, boolean doDraw)
card
- the card to transfertargetHand
- the hand where to transfer the carddoDraw
- if true, the current hand and the target hand are drawnTargetArea
public void transferNonBlocking(Card card, Hand targetHand, boolean doDraw)
card
- the card to transfertargetHand
- the hand where to transfer the carddoDraw
- if true, the current hand and the target hand are drawnpublic Card getCard(int cardNumber)
cardNumber
- the card number of the requested cardpublic <T extends java.lang.Enum<T>,R extends java.lang.Enum<R>> Card getCard(T suit, R rank)
T
- the Enum type of the suitR
- the Enum type of the ranksuit
- the card suitrank
- the card rank