Exemplo n.º 1
0
        // Based on Fisher-Yates algorithm
        // Source: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
        public void ShuffleCards(int howManyCards = 0)
        {
            int       numberCards = Length;
            int       lastCard    = numberCards - 1;
            int       shuffleCard = 0;
            SuperCard hold        = null;

            if (howManyCards > 0 && howManyCards <= lastCard)
            {
                lastCard = howManyCards;
            }

            for (int card = 0; card < lastCard; ++card)
            {
                // Randomnly choose a card between card and length of cardArray
                shuffleCard = rng.Next(card, numberCards);

                // Swap the found card with the "current" card
                hold = cardArray[shuffleCard];
                cardArray[shuffleCard] = cardArray[card];
                cardArray[card]        = hold;
            }

            // Reset the number of cards drawn
            cardsDrawn = 0;
        }
Exemplo n.º 2
0
        // Return a new child card class based on the enum passed in.
        public SuperCard MakeCard(Suit suit, Rank rank)
        {
            // Parent class needs to hold the child class
            SuperCard card = null;

            // "Cast" Suit enum to proper SuperCard child class
            switch (suit)
            {
            case Suit.Club:
                card = new CardClub(rank);
                break;

            case Suit.Diamond:
                card = new CardDiamond(rank);
                break;

            case Suit.Heart:
                card = new CardHeart(rank);
                break;

            case Suit.Spade:
                card = new CardSpade(rank);
                break;
            }

            // Return the new card
            return(card);
        }
Exemplo n.º 3
0
        public SuperCard[] GetCards(int number)
        {
            SuperCard[] mcardArray = new SuperCard[number];


            for (int i = 0; i < number; i++)
            {
                int randomNumber = random.Next(2, 52);
                mcardArray[i] = cardArray[randomNumber];

                if (cardArray[randomNumber].inplay == true)
                {
                    while (cardArray[randomNumber].inplay == true)
                    {
                        randomNumber  = random.Next(2, 52);
                        mcardArray[i] = cardArray[randomNumber];
                    }
                }
                if (cardArray[randomNumber].inplay == false)
                {
                    cardArray[randomNumber].inplay = true;
                }
            }
            return(mcardArray);
        }
Exemplo n.º 4
0
        public SuperCard[] GetCards(int passedNumer)
        {
            SuperCard[] handArray = new SuperCard[passedNumer];

            for (int i = 0; i < passedNumer; i++)
            {
                handArray[i] = GetOneCard();
            }
            return(handArray);
        }
Exemplo n.º 5
0
        }//end of constructor

        public SuperCard[] GetCards(int number)
        {
            SuperCard[] oneHand = new SuperCard[number];
            for (int i = 0; i < number; i++)
            {
                int myNum = myRandom.Next(cardArray.Length);
                oneHand[i] = cardArray[myNum];
            }
            return(oneHand);
        }
Exemplo n.º 6
0
        /*  GetOneCard() method gets one card from the deck of 52. It does not get a card that is already in play
         *  as it is no longer part of the deck. Returns a single SuperCard (not an array of cards)
         */
        public SuperCard GetOneCard()
        {
            int temp = rand.Next(0, 52);

            do
            {
                SuperCard oneCard = cardArray[temp];
                cardArray[temp].inplay = true;
                return(oneCard);
            } while (cardArray[temp].inplay == false);
        }
Exemplo n.º 7
0
        public SuperCard GetOneCard(int selectedCard)
        {
            SuperCard newCard = CardArray[rand.Next(0, 52)];

            while (newCard.Inplay)
            {
                newCard = CardArray[rand.Next(0, 52)];
            }

            newCard.Inplay = true;

            return(newCard);
        }
Exemplo n.º 8
0
        public SuperCard[] GetCards(int howManyCards)
        {
            // Instantiate a temporary hand, array, of cards
            SuperCard[] hand = new SuperCard[howManyCards];

            // Add cards to the hand.
            // For this phase, is okay to get same card.
            for (int card = 0; card < howManyCards; ++card)
            {
                hand[card] = GetOneCard();
                //hand[card] = cardArray[cardsDrawn++];
            }

            // Return the hand
            return(hand);
        }
Exemplo n.º 9
0
        public SuperCard[] GetCards(int howManyCards)
        {
            SuperCard[] tempHand = new SuperCard[howManyCards];
            int         i        = 0;

            while (i < howManyCards)
            {
                int num = rand.Next(0, 52);
                if (cardArray[num].inplay == false)
                {
                    tempHand[i]           = cardArray[num];
                    cardArray[num].inplay = true;
                    i++;
                }
            }
            return(tempHand);
        }
Exemplo n.º 10
0
        public SuperCard[] GetCards(int pnumber)
        {
            SuperCard[] newHand = new SuperCard[pnumber];

            for (int i = 0; i <= pnumber - 1; i++)
            {
                newHand[i] = CardArray[rand.Next(0, 52)];

                while (newHand[i].Inplay)
                {
                    newHand[i] = CardArray[rand.Next(0, 52)];
                }

                newHand[i].Inplay = true;
            }
            return(newHand);
        }
Exemplo n.º 11
0
        private static bool Flush(SuperCard[] computerHand)
        {
            SuperCard previousCard = null;

            foreach (SuperCard card in computerHand)
            {
                if (previousCard == null)
                {
                    previousCard = card;
                }
                if (!card.Equals(previousCard))
                {
                    return(false);
                }
                previousCard = card;
            }

            return(true);
        }