public PlayingCard GetCard(int cardNum) { if (cardNum >= 0 && cardNum <= (myDeckSize - 1)) { if ((cardNum == (myDeckSize - 1)) && (LastCardDrawn != null)) { LastCardDrawn(this, EventArgs.Empty); } PlayingCard cardToDraw = Cards[cardNum]; Cards.RemoveAt(cardNum); return(cardToDraw); } else { throw new CardOutOfRangeException(Cards.Clone() as Cards); } }
/// <summary> /// CompareTo Method /// PlayingCard-specific comparison method used to sort PlayingCard instances /// </summary> /// <param name="ojb">The object this PlayingCard is being compared to</param> /// <returns>an integer that indicates whether this PlayingCard precedes, follows or occurs in the sequence</returns> public virtual int CompareTo(object obj) { // is the argument null? if (obj == null) { throw new ArgumentNullException("Unable to compare a PlayingCard to a null object."); } // convert the argument to a PlayingCard PlayingCard compareCard = obj as PlayingCard; // if the conversion worked if (compareCard != null) { //compare based on the value first, then mySuit int thisSort = this.myValue * 10 + (int)this.mySuit; int compareCardSort = compareCard.myValue * 10 + (int)compareCard.mySuit; return(thisSort.CompareTo(compareCardSort)); } else { throw new ArgumentException("Object being compared cannot be converted to a PlayingCard."); } } //end of CompareTo
/// <summary> /// Equals: Overrides System.Object.Equals() /// </summary> /// <param name="obj"></param> /// <returns>true if PlayingCard values are equal</returns> public override bool Equals(object obj) { PlayingCard card2 = (PlayingCard)obj; return((this.mySuit == card2.mySuit) && (this.myRank == card2.myRank)); }