public class Deck
extends java.lang.Object
enum Suit
{
SPADES, HEARTS, DIAMONDS, CLUBS
}
enum Rank
{
ACE, KING, QUEEN, JACK, TEN, NINE, EIGHT, SEVEN, SIX
}
spades0 for Spades-Ace, spades1 for Spades-King, etc.
enum Sprites
{
SPRITES$MYSPADES, SPRITES$MYHEARTS, SPRITES$MYDIAMOND, SPRITES$MYCLUBS
}
/sdcard/sprites/myspades0 for Spades-Ace, /sdcard/sprites/myspades1 forSpades-King, etc.
Card
Modifier and Type | Class and Description |
---|---|
static interface |
Deck.CardValues
Interface for the construction of integer arrays with card values (card points,
card values) of each card in each suit.
|
Modifier and Type | Field and Description |
---|---|
Card[][] |
cards
Public array of all cards in this deck in the order cards[suitId][rankId].
|
Constructor and Description |
---|
Deck(T[] suits,
R[] ranks,
S[] sprites,
java.lang.String cover)
Creates a deck from given suit and rank and sprites enumerations
with card values set to zero.
|
Deck(T[] suits,
R[] ranks,
S[] sprites,
java.lang.String cover,
Deck.CardValues cardValues)
Creates a deck from given suit and rank and sprites enumerations
with given card values.
|
Deck(T[] suits,
R[] ranks,
java.lang.String cover)
Creates a deck from given suit and rank enumerations with card values set to
zero.
|
Deck(T[] suits,
R[] ranks,
java.lang.String cover,
Deck.CardValues cardValues)
Creates a deck from given suit and rank enumerations with given card values.
|
Modifier and Type | Method and Description |
---|---|
Hand[] |
dealingOut(int nbPlayers,
int nbCardsPerPlayer)
Same as dealingOut(nbPlayers, nbCardsPerPlayer, shuffle) with shuffle = true.
|
Hand[] |
dealingOut(int nbPlayers,
int nbCardsPerPlayer,
boolean shuffle)
Returns an array with nbPlayers + 1 hands.
|
static <T extends java.lang.Enum<T>> |
enumToStringArray(T[] values)
Returns the enumeration values as string array for the given enumeration.
|
android.graphics.Point |
getCardDimension()
Returs the real card dimensions of the card with suit and rank id zero.
|
<T extends java.lang.Enum<T>,R extends java.lang.Enum<R>> |
getCardNumber(T suit,
R rank)
Returns the card number of the card with given suit and rank.
|
int[] |
getCardValues(java.lang.Enum suit)
Returns an integer array of the card values in the given suit.
|
static long |
getFreeMemory()
Returns the free memory available to the running program.
|
int |
getNumberOfCards()
Returns the total number of cards in this deck.
|
int |
getNumberOfRanks()
Returns the number of ranks in this deck.
|
int |
getNumberOfSuits()
Returns the number of suits in this deck.
|
java.lang.Enum |
getRank(int rankId)
Returns the rank corresponding the given rank id.
|
int |
getRankId(int cardNb)
Returns the rank id for the given card number.
|
<R extends java.lang.Enum<R>> |
getRankId(R rank)
Returns an integer id of the given rank (0: for rank with highest priority)
|
java.lang.String |
getRankName(int cardNb)
Returns the rank name as string for the given card number
The cards are numbered from 0 in the suit and rank priority order given when
the deck is created (the following numbering is used: all card from high
to low rank of the cards in the highest priority suit, in the next suit, etc.)
|
<T extends java.lang.Enum<T>,R extends java.lang.Enum<R>> |
getSeedActor(T suit,
R rank)
Returns the JGameGrid actor attributed to the card with the specified
suit and rank.
|
java.lang.Enum |
getSuit(int suitId)
Returns the suit corresponding the given suit id.
|
int |
getSuitId(int cardNb)
Returns the suit id for the card with the given card number.
|
<T extends java.lang.Enum<T>> |
getSuitId(T suit)
Returns an integer id of the given suit (0: for suit with highest priority)
|
java.lang.String |
getSuitName(int cardNb)
Returns the suit name as string for the card with the given card number.
|
android.graphics.Point |
getVirtualCardDimension()
Returs the virtual card dimensions of the card with suit and rank id zero.
|
Hand |
toHand()
Returns the complete shuffled deck as a hand.
|
Hand |
toHand(boolean shuffle)
Returns the complete deck as a hand.
|
public Card[][] cards
public Deck(T[] suits, R[] ranks, java.lang.String cover)
T
- the Enum type of the suitR
- the Enum type of the ranksuits
- an array of suitsranks
- an array of rankscover
- the filename of the card cover sprite image.
From the given filename the image file in searched in the following order:public Deck(T[] suits, R[] ranks, java.lang.String cover, Deck.CardValues cardValues)
T
- the Enum type of the suitR
- the Enum type of the ranksuits
- an array of suitsranks
- an array of rankscover
- the filename of the card cover sprite image.
From the given filename the image file in searched in the following order:cardValues
- the integer array of card values for each suit; if null
is passed, all card values are set to zeropublic Deck(T[] suits, R[] ranks, S[] sprites, java.lang.String cover)
T
- the Enum type of the suitR
- the Enum type of the rankS
- the Enum type of the sprites. Defines the card image file path.
The images are loaded from the sdcard. All occurences of '$' in the sprites
enumeration are replaced by '/' (folder separator).suits
- an array of suitsranks
- an array of rankssprites
- an array of sprites; if null is passed, the suits values are
used for creating the filenamescover
- the filename of the card cover sprite image.
From the given filename the image file in searched in the following order:public Deck(T[] suits, R[] ranks, S[] sprites, java.lang.String cover, Deck.CardValues cardValues)
T
- the Enum type of the suitR
- the Enum type of the rankS
- the Enum type of the sprites. Defines the card image file path.
The images are loaded from the sdcard. All occurences of '$' in the sprites
enumeration are replaced by '/' (folder separator).suits
- an array of suitsranks
- an array of rankssprites
- an array of sprites; if null is passed, the suits values are
used for creating the filenamescover
- the filename of the card cover sprite image.
From the given filename the image file in searched in the following order:cardValues
- the integer array of card values for each suit; if null
is passed, all card values are set to zeropublic <T extends java.lang.Enum<T>,R extends java.lang.Enum<R>> Actor getSeedActor(T suit, R rank)
suit
- the suit of the cardrank
- the rank of the cardpublic <T extends java.lang.Enum<T>> int getSuitId(T suit)
T
- the type of the suitsuit
- the requested suitpublic java.lang.Enum getSuit(int suitId)
suitId
- the id of the suit in the order the suit enum is defined.public <R extends java.lang.Enum<R>> int getRankId(R rank)
R
- the type of the suitrank
- the requested rankpublic java.lang.Enum getRank(int rankId)
rankId
- the id of the rank in the order the rank enum is defined.public int getSuitId(int cardNb)
cardNb
- the card numberpublic java.lang.String getSuitName(int cardNb)
cardNb
- the card numberpublic int getRankId(int cardNb)
cardNb
- the card numberpublic java.lang.String getRankName(int cardNb)
cardNb
- the card numberpublic android.graphics.Point getCardDimension()
public android.graphics.Point getVirtualCardDimension()
public Hand toHand()
public Hand toHand(boolean shuffle)
shuffle
- if true, the cards are shuffle; otherwise they are ordered
by rank and then by suitpublic Hand[] dealingOut(int nbPlayers, int nbCardsPerPlayer)
nbPlayers
- the number of playersnbCardsPerPlayer
- the number of cards for each playerpublic Hand[] dealingOut(int nbPlayers, int nbCardsPerPlayer, boolean shuffle)
nbPlayers
- the number of playersnbCardsPerPlayer
- the number of cards for each playershuffle
- if true, the cards are shuffled; otherwise they are ordered
by rank and then by suitpublic int[] getCardValues(java.lang.Enum suit)
suit
- the suit from where to get the card valuespublic static <T extends java.lang.Enum<T>> java.lang.String[] enumToStringArray(T[] values)
T
- the enumeration typevalues
- the values of the given enumerationpublic int getNumberOfSuits()
public int getNumberOfRanks()
public int getNumberOfCards()
public <T extends java.lang.Enum<T>,R extends java.lang.Enum<R>> int getCardNumber(T suit, R rank)
suit
- the suit of the cardrank
- the rank of the cardpublic static long getFreeMemory()