Example #1
0
    //卡牌大小比较
    public int CompareTo(object obj)
    {
        CardInfo other = obj as CardInfo;

        if (other == null)
        {
            throw new Exception("比较对象类型非法!");
        }

        //如果当前是大小王
        if (cardType == CardTypes.Joker)
        {
            //对方也是大小王
            if (other.cardType == CardTypes.Joker)
            {
                return(cardIndex.CompareTo(other.cardIndex));
            }
            //对方不是大小王
            return(1);
        }
        //如果是一般的牌
        else
        {
            //对方是大小王
            if (other.cardType == CardTypes.Joker)
            {
                return(-1);
            }
            //如果对方也是一般的牌
            else
            {
                //计算牌力
                var thisNewIndex  = (cardIndex == 1 || cardIndex == 2) ? 13 + cardIndex : cardIndex;
                var otherNewIndex = (other.cardIndex == 1 || other.cardIndex == 2) ? 13 + other.cardIndex : other.cardIndex;

                if (thisNewIndex == otherNewIndex)
                {
                    return(-cardType.CompareTo(other.cardType));
                }

                return(thisNewIndex.CompareTo(otherNewIndex));
            }
        }
    }
Example #2
0
    //卡牌大小比较
    public int CompareTo(object obj)
    {
        CardInfo other = obj as CardInfo;

        if (other == null)
        {
            throw new Exception("比较对象类型非法!");
        }

        //如果当前是大小王
        if (cardType == CardTypes.Joker)
        {
            //对方也是大小王
            if (other.cardType == CardTypes.Joker)
            {
                return(cardIndex.CompareTo(other.cardIndex));
            }
            //对方不是大小王
            return(1);
        }
        //如果是一般的牌
        else
        {
            //对方是大小王
            if (other.cardType == CardTypes.Joker)
            {
                return(-1);
            }
            //如果对方也是一般的牌
            else
            {
                //计算牌力
                if (cardIndex == other.cardIndex)
                {
                    return(-cardType.CompareTo(other.cardType));
                }

                return(cardIndex.CompareTo(other.cardIndex));
            }
        }
    }