smithers.cards
Class AbstractBuildingRule

java.lang.Object
  extended by smithers.cards.AbstractBuildingRule
All Implemented Interfaces:
BuildingRule
Direct Known Subclasses:
BuildingDownByAlternatingColours, BuildingUpBySuits

public abstract class AbstractBuildingRule
extends java.lang.Object
implements BuildingRule

Simplifies the definition of a BuildingRule be redefining in terms of a different collection of methods.


Field Summary
protected  boolean canAddMultiple
          Set to true if multiple cards can be added at once.
 
Constructor Summary
AbstractBuildingRule()
           
 
Method Summary
 boolean canAddCard(CardStack stack, Card add)
          Determines whether the specified card can be added to the top of the stack.
 int canAddCards(CardStack stack, CardStack add)
          Determines whether cards can be moved from one stack to another.
abstract  boolean goesInSpace(Card c)
          Determines whether the specified card can be placed in an empty space.
abstract  boolean goesOn(Card c1, Card c2)
          Determines whether card c2 can be placed on top of card c1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canAddMultiple

protected boolean canAddMultiple
Set to true if multiple cards can be added at once.

Constructor Detail

AbstractBuildingRule

public AbstractBuildingRule()
Method Detail

goesOn

public abstract boolean goesOn(Card c1,
                               Card c2)
Determines whether card c2 can be placed on top of card c1.

Parameters:
c1 - the card to move onto
c2 - the card to be moved
Returns:
true iff the card can be moved

goesInSpace

public abstract boolean goesInSpace(Card c)
Determines whether the specified card can be placed in an empty space.

Parameters:
c - the card to be moved
Returns:
true iff the card can be moved into a space

canAddCard

public boolean canAddCard(CardStack stack,
                          Card add)
Determines whether the specified card can be added to the top of the stack.

Specified by:
canAddCard in interface BuildingRule
Parameters:
stack - the stack to add the card to
add - the card to add
Returns:
true iff the card can be added

canAddCards

public int canAddCards(CardStack stack,
                       CardStack add)
Determines whether cards can be moved from one stack to another. This method should return the smallest non-zero number of cards which can be moved (usually this will be the only number of cards which can be moved), or 0 if no cards can be moved. Note this method makes no checks according to whether the required cards can all legally be moved from the source stack, as this stack may be operating under different rules.

Specified by:
canAddCards in interface BuildingRule
Parameters:
stack - the stack to move cards to
add - the stack to move cards from
Returns:
the number of cards which can be moved