Introduction to OOP Chapter 9: A Solitare Game: next previous audio real text

The Class CardPile

public class CardPile {
	public CardPile (int xl, int yl )
		{ x = xl; y = yl; pile = new Stack(); }

	public PlayingCard top 
		{ get { return (PlayingCard) pile.Peek (); } }

	public bool isEmpty 
		{ get { return pile.Count == 0; }	}

	public PlayingCard pop 
		{ get { return (PlayingCard) pile.Pop (); } }
		
		// the following are sometimes overridden
	public virtual bool includes (int tx, int ty ) {
		return( ( x <= tx ) && ( tx <= x + CardView.Width ) &&
		    ( y <= ty ) && ( ty <= y + CardView.Height ) );
	}

	public virtual void select (int tx, int ty ) {
		// do nothing--override
	}

	public virtual void addCard (PlayingCard aCard )
		{ pile.Push(aCard); }

	public virtual void display (CardView cv) {
		if ( isEmpty ) {
			cv.display(null, x, y);
		} else {
			cv.display((PlayingCard) pile.Peek(), x, y );
		}
	}

	public virtual bool canTake (PlayingCard aCard)
		{ return false; }

	protected int x, y; // coordinates of the card pile
	protected Stack pile; // card pile data
}
Intro OOP, Chapter 9, Slide 008