コード例 #1
0
        /// <summary>
        /// Check to see if a hand is a valid defense hand
        /// </summary>
        /// <param name="defenseHand"></param>
        /// <param name="attackHand"></param>
        /// <returns></returns>
        public bool IsValidDefenseHand(PlayingCards defenseHand, PlayingCards attackHand)
        {
            bool isValid = false;

            //www.java2s.com/Tutorial/CSharp/0450__LINQ/Sortobjectbyitsproperty.htm
            //^^^^^^^^^^^ Found here
            defenseHand.Sort((c1, c2) => c1.suit.CompareTo(c2.suit));
            attackHand.Sort((c1, c2) => c1.suit.CompareTo(c2.suit));
            //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            if (attackHand.Count() == defenseHand.Count())
            {
                for (int index = 0; index < attackHand.Count(); index++)
                {
                    if (defenseHand.ElementAt(index).suit == attackHand.ElementAt(index).suit)
                    {
                        if (defenseHand.ElementAt(index).rank > attackHand.ElementAt(index).rank)
                        {
                            isValid = true;
                        }
                        else
                        {
                            isValid = false;
                        }
                    }
                    else
                    {
                        isValid = false;
                    }
                }
            }
            return(isValid);
        }
コード例 #2
0
        /// <summary>
        /// Checks to see if a hand is a valid attack hand
        /// </summary>
        /// <param name="attackHand"></param>
        /// <returns></returns>
        public bool IsValidAttackHand(PlayingCards attackHand)
        {
            bool isValid = false;

            if (attackHand.Count() > 1)
            {
                for (int index = 0; index < attackHand.Count(); index++)
                {
                    if (index != 0)
                    {
                        if (attackHand.ElementAt(index - 1).rank == attackHand.ElementAt(index).rank)
                        {
                            isValid = true;
                        }
                    }
                }
            }
            else
            {
                isValid = true;
            }
            return(isValid);
        }