コード例 #1
0
        /// <summary>
        /// Method for selecting the trump of the game
        /// </summary>
        /// <returns></returns>
        public PlayingCard SelectTrumpCard()
        {
            PlayingCard drawnCard = MyDeck.GetCard(0);                                            // Get the first card on the top of the deck. Assign to drawnCard.

            MyDeck.RemoveCard(drawnCard);                                                         // Remove this card from the deck.
            drawnCard.FlipCard();                                                                 // Flip drawnCard.

            SoundPlayer audio = new SoundPlayer(CardGameLibrary.Properties.Resources.flip_sound); //create new soundplayer for the card flip sound

            audio.PlaySync();                                                                     //play the card flip sound on same thread haulting program

            return(drawnCard);                                                                    //return trump card
        }
コード例 #2
0
        /// <summary>
        /// Removes a passed card to the player's hand.
        /// </summary>
        /// <param name="newCard"></param>
        public void Remove(PlayingCard newCard)
        {
            // Loop through cards...
            for (int cardCounter = 0; cardCounter < myHand.Count; cardCounter++)
            {
                // If the current card is equal to the passed card, remove it from the hand.
                if (myHand[cardCounter] == newCard)
                {
                    myHand.RemoveAt(cardCounter);
                }
            }

            // Loop through card boxes...
            for (int boxCounter = 0; boxCounter < myCardBoxes.Count(); boxCounter++)
            {
                // If the current cardbox is equal to the passed card, remove it from the list.
                if (myCardBoxes[boxCounter].MyCard == newCard)
                {
                    myCardBoxes.RemoveAt(boxCounter);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// CompareTo method that takes an object and converts it to a card and compares it to this card.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public virtual int CompareTo(object obj)
        {
            // Check if the arugment is null.
            if (obj == null)
            {
                throw new ArgumentNullException("Unable to compare a Card to a null object.");
            }

            // Convert arugment object to a card.
            PlayingCard compareCard = obj as PlayingCard;

            // Check if the arugment object could be comparable to a card object.
            if (compareCard != null)
            {
                // Compare the card objects.
                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 card.");
            }
        }