////////////////////////////////////////////////////////////////////////////////////
// CardFoundation.java
//
// Implementation of class CardFoundation, a type-safe collection of Cards
//  which is displayed as a top card only.
//  Cards are removed from the top and added to the top.
//  Foundation card-adding rules are enforced.

public class CardFoundation extends CardPile
{
    public CardFoundation(int x, int y)
    {
        super(x, y);
    }
    
    public boolean CanAddCard(Card c)
    {
        // Add cards if: 
        //  we're empty and it's an ace
        //  it's the next in sequence
        
        int nSize = GetNumCards();
        if (nSize == 0)
            return (c.GetValue() == 1);
        
        Card top = GetTopCard();
        if (c.GetSuit() != top.GetSuit())
            return false;
        if (c.GetValue() != (top.GetValue() + 1))
            return false;
        return true;
    }
}