Beispiel #1
0
        public bool Turn(Player player, Hand playerHand)
        {
            int  cardPosition;
            Card drawnCard;
            Card discardedCard;

            //Choose whether to draw from main deck or discard pile

            if (playerHand.IsDone() == true)
            {
                return(false);
            }

            if (player.ChooseDrawDiscard() == true)
            {
                drawnCard = mainDeck.Draw();
            }
            else
            {
                //Error check.  If drawing from discard pile, but discard pile is empty...
                if (discardPile.Count == 0)
                {
                    //then draw from the main deck instead
                    drawnCard = mainDeck.Draw();
                }
                else
                {
                    //if the discard pile is not empty, then draw
                    //from it and remove the card.
                    drawnCard = discardPile[0];
                    discardPile.RemoveAt(0);
                }
            }

            /*
             * Look at the drawn card and replace any card(face down or face up) in the hand.
             * The new card is face up, the replaced card is added to
             * the top of the discard pile(face up).
             */

            //get the card position first
            cardPosition = player.ChooseReplace(playerHand);

            //replace card at "cardPosition" with the card that was drawn
            //store the card that was replaced
            discardedCard = playerHand.Replace(cardPosition, drawnCard);

            //Set the replaced card face up into the discard pile
            if (discardedCard.FaceUp == false)
            {
                discardedCard.FaceUp = true;
                discardPile.Add(discardedCard);
            }
            else
            {
                discardPile.Add(discardedCard);
            }

            return(true);
        }