Compare() public method

Compares two cards
public Compare ( object x, object y ) : int
x object First card
y object Second card
return int
Beispiel #1
0
        /// <summary>
        /// Compares current combination to another one
        /// </summary>
        /// <param name="combination">combination to compare to</param>
        /// <returns>1 if current combination is bigger, -1 if second combination is bigger, 0 if both combination are equal</returns>
        public override int CompareTo(object combination)
        {
            if (!(combination is SequentialCombination))
            {
                throw new InvalidOperationException("Cannot compare SequentialCombination to an object of different type");
            }

            int result = 0;

            SequentialCombination comb = combination as SequentialCombination;

            if (this.Points > comb.Points)
            {
                result = 1;
            }
            else if (this.Points < comb.Points)
            {
                result = -1;
            }
            else
            {
                // both combinations are sequential. See biggest card
                CardComparer comparer = new CardComparer( );
                this.Cards.Sort(comparer);
                comb.Cards.Sort(comparer);

                result = comparer.Compare(this.Cards[0], comb.Cards[0]);
            }
            return(result);
        }
        /// <summary>
        /// Compares current combination to another one
        /// </summary>
        /// <param name="combination">combination to compare to</param>
        /// <returns>1 if current combination is bigger, -1 if second combination is bigger, 0 if both combination are equal</returns>
        public override int CompareTo( object combination )
        {
            if( !(combination is SequentialCombination) )
            {
                throw new InvalidOperationException( "Cannot compare SequentialCombination to an object of different type" );
            }

            int result = 0;

            SequentialCombination comb = combination as SequentialCombination;
            if( this.Points > comb.Points )
            {
                result = 1;
            }
            else if( this.Points < comb.Points )
            {
                result = -1;
            }
            else
            {
                // both combinations are sequential. See biggest card
                CardComparer comparer = new CardComparer( );
                this.Cards.Sort( comparer );
                comb.Cards.Sort( comparer );

                result = comparer.Compare( this.Cards[0], comb.Cards[0] );
            }
            return result;
        }
Beispiel #3
0
        private bool IsCurrentMaxCardInPlayingColor( Card targetCard )
        {
            CardComparer comparer = new CardComparer( _playingManager.CurrentAnnouncement.Type );
            bool foundBigger = false;

            foreach ( Card remCard in _playingManager.RemainingCards )
            {
                if ( targetCard.CardColor == remCard.CardColor )
                {
                    if ( comparer.Compare( targetCard, remCard ) < 0 )
                    {
                        foundBigger = true;
                        break;
                    }
                }
            }

            if ( !foundBigger )
            {
                foreach ( Card remCard in _playingManager.CurrentHand )
                {
                    if ( targetCard.CardColor == remCard.CardColor )
                    {
                        if ( comparer.Compare( targetCard, remCard ) < 0 )
                        {
                            foundBigger = true;
                            break;
                        }
                    }
                }
            }

            return !foundBigger;
        }
Beispiel #4
0
        private Card GetCurrentMaxCardInColor( CardColor color )
        {
            Card maxCard = null;
            CardComparer comparer = new CardComparer( _playingManager.CurrentAnnouncement.Type );

            foreach ( Card card in _playingManager.RemainingCards )
            {
                if ( card.CardColor == color )
                {
                    if ( maxCard == null )
                    {
                        maxCard = card;
                    }

                    if ( comparer.Compare( maxCard, card ) < 0 )
                    {
                        maxCard = card;
                    }
                }
            }

            foreach ( Card card in _playingManager.CurrentHand )
            {
                if ( card.CardColor == color )
                {
                    if ( maxCard == null )
                    {
                        maxCard = card;
                    }

                    if ( comparer.Compare( maxCard, card ) < 0 )
                    {
                        maxCard = card;
                    }
                }
            }

            return maxCard;
        }
Beispiel #5
0
 private bool IsBigger(Card card, Card biggestCard)
 {
     return(_cardComparer.Compare(card, biggestCard) > 0);
 }