com.blackledge.david.game.solitaire
Class CardStack
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.Vector
com.blackledge.david.game.solitaire.CardStack
- All Implemented Interfaces:
- Serializable, Cloneable, Iterable, Collection, List, RandomAccess
- Direct Known Subclasses:
- DeckStack, FreeCellGoalStack, FreeCellPlayStack, FreeCellSingleStack, SolitaireGoalStack, SolitairePlayStack
public class CardStack
- extends Vector
A collection of Card
objects
- Version:
- $Revision: 1.1 $
- See Also:
- Serialized Form
Methods inherited from class java.util.Vector |
add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize |
CardStack
public CardStack()
CardStack
public CardStack(Collection list)
add
public boolean add(Object o)
- calls super.
add(Object)
if the object is a card, calls super.Vector.addAll(Collection)
if the object is a CardStack.
- Specified by:
add
in interface Collection
- Specified by:
add
in interface List
- Overrides:
add
in class Vector
- Returns:
- whatever te super implementation returns.
- Throws:
IllegalArgumentException
- if the object is not one of the above
types.
canStack
public boolean canStack(Card card)
- Override for stacks with rules.
- Parameters:
card
- the card that wants to be stacked on top of this instance.
- Returns:
- true if not overridden.
canStack
public boolean canStack(CardStack stack)
- Parameters:
stack
- the stack that wants to be stacked on top of this instance.
- Returns:
canStack(Card)
for the stack argument's bottomCard
canPickUp
public boolean canPickUp(int i)
- Determine if we are allowed to call
pickUp(int)
without getting a null back.
- Returns:
- true always
pickUp
public CardStack pickUp(int i)
- Grab part of the stack off of the current instance, removing them from this instance.
- Parameters:
i
- how deep to reach when picking up from this instance. 0 == top card
- Returns:
- Stack of face-up cards from 0-i, or null if can't pick up or no cards.
bottomCard
public Card bottomCard()
- Returns:
- the card on the bottom of the stack. - don't call on an empty stack.
topCard
public Card topCard()
- Returns:
- the card on the top of the stack. - don't call on an empty stack.
getReverse
public CardStack getReverse()
- Get a new CardStack instance that contains the same cards as this stack, but in reverse order.
- Returns:
- a new CardStack instance the same size as this one.