Beispiel #1
0
        /// <summary>
        /// Attempt to play the chosen card for the user according to the rules
        /// of the game.
        /// </summary>
        /// <param name="cardNum"> Card's index in hand</param>
        /// <param name="chosenSuit">Suit if the card is eight</param>
        /// <returns>Return the action according to the rules</returns>
        public static ActionResult UserPlayCard(int cardNum, Suit?chosenSuit = null)
        {
            Card cardPlayed = UserHand.GetCard(cardNum);
            Suit newSuit    = chosenSuit == null?cardPlayed.GetSuit() : (Suit)chosenSuit;

            if (!IsPlaying || !IsUserTurn)
            {
                throw new Exception();
            }

            if (cardPlayed.GetFaceValue() == FaceValue.Eight && chosenSuit == null)
            {
                return(ActionResult.SuitRequired);
            }

            return(PlayCard(UserHand, cardNum, newSuit, ComputerHand));
        }