Example #1
0
        public int ChooseCard(bool cardFace, Hand playerHand)
        {
            int  cardPosition = rnd.Next(0, 9);
            Card c;

            //search through the hand for a card that is either facedown or faceup,
            //depending on the value of "cardFace"


            while (true)
            {
                c = playerHand.Peek(cardPosition);
                //look at a random position in the hand
                //If the boolean FaceUp value of the card in the hand matches the
                //desired card value(faceup or facedown)
                //then we just return the position

                if (c.FaceUp == cardFace)
                {
                    return(cardPosition);
                }
                else
                {
                    //If the FaceUp value of the card does not match
                    //the desired value (randomized), then just assign another random
                    //card position
                    cardPosition = rnd.Next(0, 9);
                }
            }
        }