cardDeck
Class CardPile

java.lang.Object
  extended by cardDeck.CardPile
All Implemented Interfaces:
java.lang.Iterable<Card>
Direct Known Subclasses:
DeckOfCards

public class CardPile
extends java.lang.Object
implements java.lang.Iterable<Card>

A pile of cards which can be used for a discard pile, hand, deck, etc.

Version:
0.5
Author:
Devin Ryan

Constructor Summary
CardPile()
           
 
Method Summary
 void clear()
          Empty the pile of cards
 boolean isRemovable()
          Checks if a card is removable from this pile.
 java.util.Iterator<Card> iterator()
          Returns iterator of all the cards in the pile.
 Card peekTop()
          Allows you to see what card is at the top, without removing it from the pile
 Card pop()
          Removes the top card of the pile for use if cards can be removed from this pile.
 Card popIgnoreRules()
          Removes card from the top of this pile without adhering to any rules.
 boolean push(Card newCard)
          Adds card to this pile, adhering to any rules.
 void pushIgnoreRules(Card newCard)
          Adds card to this pile without adhering to any rules.
 java.util.ListIterator<Card> reverseIterator()
          Returns a list iterator of the elements in this list (in proper sequence),
 boolean rulesAllowAddingThisCard(Card card)
          Subclasses may override this to enforce their rules for adding cards to the pile.
 void shuffle()
          Shuffles the deck
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CardPile

public CardPile()
Method Detail

pushIgnoreRules

public void pushIgnoreRules(Card newCard)
Adds card to this pile without adhering to any rules.

Parameters:
newCard - Card to be added to the pile

popIgnoreRules

public Card popIgnoreRules()
Removes card from the top of this pile without adhering to any rules.

Returns:
Card from the top of the pile.

push

public boolean push(Card newCard)
Adds card to this pile, adhering to any rules.

Parameters:
newCard - Card to be added to the pile

rulesAllowAddingThisCard

public boolean rulesAllowAddingThisCard(Card card)
Subclasses may override this to enforce their rules for adding cards to the pile.

Parameters:
card - Card to be added.
Returns:
True if the card is allowed to be added to pile, false otherwise

size

public int size()
Returns:
Number of cards in this pile.

pop

public Card pop()
Removes the top card of the pile for use if cards can be removed from this pile.

Returns:
Card from top of the pile

shuffle

public void shuffle()
Shuffles the deck


peekTop

public Card peekTop()
Allows you to see what card is at the top, without removing it from the pile

Returns:
Element at the top of the pile

iterator

public java.util.Iterator<Card> iterator()
Returns iterator of all the cards in the pile.

Specified by:
iterator in interface java.lang.Iterable<Card>

reverseIterator

public java.util.ListIterator<Card> reverseIterator()
Returns a list iterator of the elements in this list (in proper sequence),

Returns:
list iterator of cards in proper sequence

clear

public void clear()
Empty the pile of cards


isRemovable

public boolean isRemovable()
Checks if a card is removable from this pile. May wish to override in a subclass

Returns:
True if it is removable, false otherwise.