|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object smithers.cards.CardStack
public class CardStack
Class to store a stack of Card
objects. Includes methods for
creating, sorting, shuffling and dealing cards.
Constructor Summary | |
---|---|
CardStack()
Constructs an empty stack. |
|
CardStack(Card[] cards)
Creates a stack from an array of cards. |
|
CardStack(int length)
Creates a stack of a given number of new cards. |
Method Summary | |
---|---|
void |
addCard(Card newCard)
Adds a card to the top of the stack. |
void |
deal(CardStack target)
Deals one card into the specified stack. |
void |
deal(CardStack[] targets)
Deals all of the cards in this stack into the specified stacks. |
int |
deal(CardStack[] targets,
int count)
Deals the specified number of cards into the specified stacks. |
void |
deal(CardStack target,
int count)
Deals the specified number of cards into the specified stack. |
Card |
getCard(int index)
Returns a specific card from the list. |
int |
getLength()
Returns the number of cards in the list. |
void |
move(CardStack target,
int count)
Moves the specified number of cards into the specified stack. |
void |
removeCard()
Removes a card from the top of the stack. |
void |
setSeed(long seed)
Sets the random seed used for shuffling this stack. |
void |
shuffle()
Shuffles this stack of cards. |
void |
sort()
Sorts this stack by suit then rank using quicksort with aces low. |
void |
sort(boolean acesHigh)
Sorts this stack by suit then rank using quicksort, optionally ranking aces as high or low. |
Card[] |
toArray()
Returns an array containing all the cards in this stack. |
Card |
topCard()
Returns the top card in the stack. |
java.lang.String |
toString()
Returns a String representation of the entire stack. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CardStack()
public CardStack(int length)
length
cards in the deck (0 and 52 are useful values). Values >52
produce multiple decks.
length
- the number of Card
s to create.public CardStack(Card[] cards)
cards
- the Card
s to put into the stackMethod Detail |
---|
public int getLength()
public Card topCard()
public Card getCard(int index)
index
- the index of the card to get
public java.lang.String toString()
String
representation of the entire stack.
toString
in class java.lang.Object
String
containing a 2-character representation of each
card in this stackpublic Card[] toArray()
public void addCard(Card newCard)
newCard
- the card to addpublic void removeCard()
public void move(CardStack target, int count)
count == 0
, moves all of them. This differs from the method deal(CardStack, count)
in that the cards are kept in the same order.
target
- the stack to deal tocount
- the number of cards to move, or 0
for all of thempublic void deal(CardStack target)
target
- the stack to deal topublic void deal(CardStack target, int count)
count == 0
, deals all of them.
target
- the stack to deal tocount
- the number of cards to deal, or 0
for all of thempublic void deal(CardStack[] targets)
targets
- the stacks to deal topublic int deal(CardStack[] targets, int count)
count < 0
then deal -count
cards to each stack, if count
> 0
then deal count
cards in total, if count == 0
then
deal all the cards.
targets
- the stacks to deal tocount
- the number of cards to deal (as above)
public void setSeed(long seed)
seed
- the new seedpublic void shuffle()
public void sort()
public void sort(boolean acesHigh)
acesHigh
- true
iff aces are to be ranked as high
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |