Class CardPile

java.lang.Object
  extended by CardPile
All Implemented Interfaces:
ICardPile, IGuiPileModel
Direct Known Subclasses:
Foundation, Tableau

public class CardPile
extends java.lang.Object
implements ICardPile, IGuiPileModel


Constructor Summary
CardPile()
          Constructor
 
Method Summary
 boolean addCard(Card card)
          Adds a card to the pile, if card is addable
 void clear()
          Clears the pile
 boolean dealCard(Card card)
          Deals a card to the pile.
 boolean forceAddCard(Card card)
          Adds a card to pile (no conditions)
 Card getCard()
          Gets top card from pile, unless pile is empty
 int getMaxSize()
          Returns maximum size of pile
 java.lang.String getPileID()
          Returns the pile's unique ID, e.g., "t2"
 int getSize()
          Returns size of pile
 java.lang.String getSuit()
          Returns suit of pile
 IGuiCard getVisibleCard(int index)
          Returns the index(th) visible card
 boolean isAddable(Card card)
          Checks if card can be added to pile By default, as long as pile is not empty, a card can be removed
 boolean isEmpty()
          Checks if pile is full or not
 boolean isFull()
          Checks if pile is empty or not
 boolean isRemovable()
          Checks if card can be removed from pile By default, as long as pile is not empty, a card can be removed
 boolean isSameSuit(Card card)
          Checks if pile is of the same suit as card
static void main(java.lang.String[] args)
          Main method, checks whether there are bugs in class
 int maxVisibleCount()
          Returns the max number of cards in the pile.
 Card removeCard()
          Adds a card to the pile, if card is addable
 void setID(java.lang.String ID)
          Sets the ID for the pile model to the String ID
 void setMaxSize(int maxSize)
          Sets maxSize of pile to maxSize
 void setSuit(java.lang.String suit)
          Sets mySuit of pile to suit
 void setView(IPileView view)
          Sets the view of the pile
 void update()
          Tells the view for this pile to update itself - this is overridden in both the TableauPiles and CellPiles classes.
 int visibleCardCount()
          Returns the number of cards in the pile.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CardPile

public CardPile()
Constructor

Method Detail

setSuit

public void setSuit(java.lang.String suit)
Sets mySuit of pile to suit

Parameters:
suit -

setMaxSize

public void setMaxSize(int maxSize)
Sets maxSize of pile to maxSize

Parameters:
maxSize -

setID

public void setID(java.lang.String ID)
Sets the ID for the pile model to the String ID

Parameters:
ID - the ID created for this pile

getCard

public Card getCard()
Gets top card from pile, unless pile is empty

Specified by:
getCard in interface ICardPile
Returns:
top card if pile is nonempty; null otherwise

getSize

public int getSize()
Returns size of pile

Returns:
size of pile

getSuit

public java.lang.String getSuit()
Returns suit of pile

Returns:
mySuit

getMaxSize

public int getMaxSize()
Returns maximum size of pile

Returns:
myMaxSize

addCard

public boolean addCard(Card card)
Adds a card to the pile, if card is addable

Specified by:
addCard in interface ICardPile
Parameters:
card - is the Card Object being added
Returns:
true if card was added successfully, false otherwise

removeCard

public Card removeCard()
Adds a card to the pile, if card is addable

Specified by:
removeCard in interface ICardPile
Returns:
removed card if card was removed successfully; null otherwise

forceAddCard

public boolean forceAddCard(Card card)
Adds a card to pile (no conditions)

Parameters:
card - is the Card Object being added
Returns:
true if card was added successfully to stack, false otherwise

dealCard

public boolean dealCard(Card card)
Deals a card to the pile. This is separate from the forceAddCard because you do not want to update the pile each time you deal - this would be inefficient and unnecessary.

Parameters:
card - the card to deal to the pile
Returns:
true, always

isAddable

public boolean isAddable(Card card)
Checks if card can be added to pile By default, as long as pile is not empty, a card can be removed

Specified by:
isAddable in interface ICardPile
Parameters:
card - is the Card object being added
Returns:
true if card can be added to stack, false otherwise

isRemovable

public boolean isRemovable()
Checks if card can be removed from pile By default, as long as pile is not empty, a card can be removed

Specified by:
isRemovable in interface ICardPile
Parameters:
card - is the Card object being added
Returns:
true if card can be removed from stack, false otherwise

isEmpty

public boolean isEmpty()
Checks if pile is full or not

Specified by:
isEmpty in interface ICardPile
Returns:
true if pile is empty, false otherwise

isFull

public boolean isFull()
Checks if pile is empty or not

Specified by:
isFull in interface ICardPile
Returns:
true if pile is empty, false otherwise

isSameSuit

public boolean isSameSuit(Card card)
Checks if pile is of the same suit as card

Returns:
true if same suit, false otherwise

clear

public void clear()
Clears the pile

Specified by:
clear in interface ICardPile

main

public static void main(java.lang.String[] args)
Main method, checks whether there are bugs in class


setView

public void setView(IPileView view)
Sets the view of the pile

Specified by:
setView in interface IGuiPileModel
Parameters:
view - is the view "observing" this model

visibleCardCount

public int visibleCardCount()
Returns the number of cards in the pile. This is a separate method because you may not want to display all the cards in a pile.

Specified by:
visibleCardCount in interface IGuiPileModel
Returns:
size of the pile

maxVisibleCount

public int maxVisibleCount()
Returns the max number of cards in the pile.

Specified by:
maxVisibleCount in interface IGuiPileModel
Returns:
max size of the pile

getPileID

public java.lang.String getPileID()
Returns the pile's unique ID, e.g., "t2"

Specified by:
getPileID in interface IGuiPileModel
Returns:
the ID of the pile

getVisibleCard

public IGuiCard getVisibleCard(int index)
Returns the index(th) visible card

Specified by:
getVisibleCard in interface IGuiPileModel
Parameters:
index - specifies which visible card obtained from model
Returns:
the card in this pile that is index number of cards from the top

update

public void update()
Tells the view for this pile to update itself - this is overridden in both the TableauPiles and CellPiles classes.