public override bool AddCard( Card c ) { // If we're dealing 3 cards, we shift // the cards to the right so that each // deal will be shown: return base.AddCard( c ); }
protected bool CanAddCard( Card c ) { // The behaviour is different if there are no cards // yet in our pile: if ( this.Count == 0 ) { // In this case we accept any suit, // and the first card (Ace) in that suit: return ( c.Rank == 1 ); } else { // Already some cards in our pile, we therefore only // accept cards of the same suit and where the first // card in the collection of cards to be added has // one higher rank than the topmost card in our pile: if ( c.Suit == m_cards[ 0 ].Suit && c.Rank == m_cards[ m_cards.Count - 1 ].Rank + 1 ) { return true; } else { return false; } } }
/// <summary> /// TODO: document /// </summary> /// <param name="c"></param> /// <returns></returns> public override bool AddCard( Card c ) { if ( this.CanAddCard( c ) ) { base.InternalAddCard( c ); return true; } return false; }
/// <summary> /// Constructor. Creates all the cards and stores them. Cards are initially /// created face down. Accepts an (optional) ImageManager. /// </summary> public Deck( ImageManager imgMgr ) { // Create a default image manager if none is provided: if ( imgMgr == null ) { imgMgr = new ImageManager( ); } m_imgMgr = imgMgr; // Create all 52 cards: Suit[] arrSuits = { Suit.Hearts, Suit.Spades, Suit.Diamonds, Suit.Clubs }; foreach ( Suit s in arrSuits ) { for ( int i = 1; i <= 13; i++ ) { Card c = new Card( s, i, false, this ); m_cards.Add( c ); } } }
/// <summary> /// Returns true if the color of the current card is the opposite /// color of the other card. Red and black are considered opposite /// colors in this regard. /// </summary> /// <param name="other"></param> /// <returns></returns> public bool IsOppositeColor( Card other ) { return ( this.IsBlack( ) && other.IsRed( ) ) || ( this.IsRed( ) && other.IsBlack( ) ); }
/// <summary> /// We don't support adding cards back: /// </summary> /// <param name="c"></param> /// <returns></returns> public override bool AddCard( Card c ) { return false; }
public void SetAt( int index, Card c ) { base.m_cards[ index ] = c; }