|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ch.aplu.jcardgame.Deck
public class Deck
A class to bundle information about the card suits and ranks and their
card actors (sprite images).
You find a general description of the JCardGame library in the Card
class documentation.
A deck maintains a store of available cards and contains the information
about available card suits and card ranks as enumerations. Each card may have
an individual integer card value called card point. Suits and ranks are ordered
in a priority list defined by the order of enums when the deck is created.
Each card is linked to a JGameGrid actor that uses two sprite images,
one for the face and one for the cover (back). Each sprite image should have
the same standard dimension. The scaling and rotation of card images is
done dynamically when the cards are drawn in the game grid window.
The sprite images are loaded from disk files in the subdirectory "sprites"
using the enum string values of the suits with an increasing number appended
starting from 0.
For instance
enum Suit
{
SPADES, HEARTS, DIAMONDS, CLUBS
}
enum Rank
{
ACE, KING, QUEEN, JACK, TEN, NINE, EIGHT, SEVEN, SIX
}
the disk files
sprites/clubs0.gif for Clubs-Ace, sprites/clubs1.gif for Clubs-King, etc. (all lowercase)
will be used. Another set of sprites images can be loaded by providing a
sprites enumeration in the deck constructor. E.g. If the following
enumeration is passed to the constructor
enum Sprites
{
A, B, C, D
}
the sprite images are loaded from
sprites/a0.gif for Clubs-Ace, sprites/a1.gif for Clubs-King, etc. (all lowercase)
but the card suits and ranks names remain unchanged.
Card
Nested Class Summary | |
---|---|
static interface |
Deck.CardValues
Interface for the construction of integer arrays with card values (card points, card values) of each card in each suit. |
Field Summary | |
---|---|
Card[][] |
cards
Public array of all cards in this deck in the order cards[suitId][rankId]. |
Constructor Summary | |
---|---|
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 using the values of the suits enumeration for the sprite names. |
|
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 using the values of the suits enumeration for the sprite names. |
Method Summary | ||
---|---|---|
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
|
enumToStringArray(T[] values)
Returns the enumeration values as string array for the given enumeration. |
|
java.awt.Dimension |
getCardDimension()
Returs the card dimensions of the card with suit and rank id zero. |
|
|
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 double |
getHeapSize()
Returns the current memory heap size. |
|
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. |
|
|
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.) |
|
|
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. |
|
|
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. |
|
static void |
showHeapSize()
Displays the current memory heap size in System.out. |
|
Hand |
toHand()
Returns the complete shuffled deck as a hand. |
|
Hand |
toHand(boolean shuffle)
Returns the complete deck as a hand. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public Card[][] cards
Constructor Detail |
---|
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 partial filename of the card cover sprite image. The file
must reside in the sprites subdirectory and have the extension .gifpublic 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 partial filename of the card cover sprite image. The file
must reside in the sprites subdirectory and have the extension .gifcardValues
- 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 spritessuits
- 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 partial filename of the card cover sprite image. The file
must reside in the sprites subdirectory and have the extension .gifpublic 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 spritessuits
- 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 partial filename of the card cover sprite image. The file
must reside in the sprites subdirectory and have the extension .gifcardValues
- the integer array of card values for each suit; if null
is passed, all card values are set to zeroMethod Detail |
---|
public <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 card
public <T extends java.lang.Enum<T>> int getSuitId(T suit)
T
- the type of the suitsuit
- the requested suit
public 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 rank
public 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 number
public java.lang.String getSuitName(int cardNb)
cardNb
- the card number
public int getRankId(int cardNb)
cardNb
- the card number
public java.lang.String getRankName(int cardNb)
cardNb
- the card number
public java.awt.Dimension getCardDimension()
public Hand toHand()
public Hand toHand(boolean shuffle)
shuffle
- if true, the cards are shuffle; otherwise they are ordered
by rank and then by suit
public Hand[] dealingOut(int nbPlayers, int nbCardsPerPlayer)
nbPlayers
- the number of playersnbCardsPerPlayer
- the number of cards for each player
public 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 suit
public int[] getCardValues(java.lang.Enum suit)
suit
- the suit from where to get the card values
public static <T extends java.lang.Enum<T>> java.lang.String[] enumToStringArray(T[] values)
T
- the enumeration typevalues
- the values of the given enumeration
public 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 card
public static double getHeapSize()
public static void showHeapSize()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |