Introduction to OOP: Chapter 8: The Solitaire Game [next] [previous] [audio] [real] [text]

The Suit Pile

class SuitPile extends CardPile {

	SuitPile (int x, int y) { super(x, y); }

	public boolean canTake (Card aCard) {
		if (empty())
			return aCard.rank() == 0;
		Card topCard = top();
		return (aCard.suit() == topCard.suit()) &&
			(aCard.rank() == 1 + topCard.rank());
		}
}
Intro OOP, Chapter 8, Slide 16