com.blackledge.david.game.solitaire
Class CardDeck

java.lang.Object
  extended by com.blackledge.david.game.solitaire.CardDeck
Direct Known Subclasses:
SolitaireDeck

public class CardDeck
extends Object

Represents a Deck of cards.

Version:
$Revision: 1.1 $

Constructor Summary
CardDeck()
          Creates a new Deck of cards containing every card from Card.getMinValue() to Card.getMaxValue() for all 4 suits, and calls shuffle().
CardDeck(CardStack cards)
          Create a Deck of cards containing the cards in the supplied stack.
 
Method Summary
 CardStack draw()
          Override for different default draw behavior.
 CardStack draw(int num)
          Draw the specified number of cards from the deck.
 Card get(int i)
          get the Card at the specified index, or null if the deck isn't that big.
 Card peek()
           
 void shuffle()
          perform a "natural shuffle" 3 times.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CardDeck

public CardDeck(CardStack cards)
Create a Deck of cards containing the cards in the supplied stack.

Parameters:
cards -

CardDeck

public CardDeck()
Creates a new Deck of cards containing every card from Card.getMinValue() to Card.getMaxValue() for all 4 suits, and calls shuffle().

Method Detail

shuffle

public void shuffle()
perform a "natural shuffle" 3 times. cuts the deck in half and randomly adds cards from the halves to the new pile


size

public int size()
Returns:
The size of the deck.

draw

public CardStack draw()
Override for different default draw behavior. By default, calls draw(int) with a 1.

Returns:
the result of draw(int)

draw

public CardStack draw(int num)
Draw the specified number of cards from the deck.

Parameters:
num - the number of cards to (attempt to) draw
Returns:
a CardStack containing num cards or size() cards, whichever is smaller, all face up.

get

public Card get(int i)
get the Card at the specified index, or null if the deck isn't that big.

Parameters:
i -
Returns:
the Card at that index.

peek

public Card peek()
Returns:
the Top Card in the deck, or null if the deck is empty.