Exemple #1
0
 public void Shuffle()
 {
     //  >>>>>[  Shuffle
     //          -----
     for (int index = 51; index >= 0; index--)
     {
         int         SwapCard  = rng.Next(index + 1);
         PlayingCard SwapValue = Cards[SwapCard];
         Cards[SwapCard] = Cards[index];
         Cards[index]    = SwapValue;
     }
 }
Exemple #2
0
        public void shuffleDeck()
        {
            // int currentCard = 0;

            Random ranNum = new Random();

            for (int i = 0; i < deck.Length; i++)
            {
                int         second = ranNum.Next(NUMBER_OF_CARDS);
                PlayingCard temp   = deck[i];
                deck[i]      = deck[second];
                deck[second] = temp;
            }
        }
Exemple #3
0
        // Deal a random card from the deck.
        public PlayingCard DealCard(Hand hand)
        {
            Random rand = new Random();

            if (deck.Count == 0)
            {
                deck = MakeADeck();
            }
            int idx = rand.Next(deck.Count);    // Get a random # between 0-# of cards left in deck

            PlayingCard card = deck[idx];       // Get the card at the random index

            hand.TakeCard(card);
            deck.RemoveAt(idx);                         // Remove the card from the deck
            return(card);
        }
Exemple #4
0
        public DeckOfCards()
        {
            for (int deckCT = 1; deckCT <= 6; deckCT++)
            {
                for (int suit = 1; suit <= 4; suit++)
                {
                    for (int val = 1; val <= 13; val++)
                    {
                        deck[ct++] = new PlayingCard(val, suit);
                    }
                }
            }

            //showDeck();
            shuffleDeck();
        }
Exemple #5
0
        // Generates the deck of 52 cards
        static PlayingCard[] generateDeck()
        {
            PlayingCard[] deck    = new PlayingCard[52]; // Declares an array of PlayingCards with a size of 52
            int           counter = 0;                   // Tells us where to save the next value into the array

            // Nested for loop to generate all 52 cards - 4 possible suits with 13 possible values each
            for (int suit = 1; suit < 5; suit++)                  // Loop through the 4 possible suits
            {
                for (int value = 1; value < 14; value++)          // Loop through the 13 possible values
                {
                    deck[counter] = new PlayingCard(suit, value); // Generate new card and store it in the deck
                    counter++;                                    // Increment the counter
                }
            }

            return(deck); // Returns the completed deck
        }
        public HandOfCards(DeckOfCards gameDeck)
        //        public HandOfCards(int handSize, DeckOfCards gameDeck)
        {
            PlayingCard pc = gameDeck.dealCard();

            gameHand.Add(pc);
            pc = gameDeck.dealCard();
            gameHand.Add(pc);

            //for (int i = 0; i < handSize; i++)
            //{
            //    PlayingCard pc = gameDeck.dealCard();
            //    gameHand[i] = pc;

            //}

            //showHand();

            handValue();
        }
Exemple #7
0
        static void drawCard(PlayingCard[] deck, ref Player player)
        {
            PlayingCard nextCard = deck[pointer];

            // Add the next card in the deck to the player's hand
            if (player.cardsInHand < 5)
            {
                player.hand[player.cardsInHand] = nextCard;

                // Increment the number of cards in the player's hand
                player.cardsInHand++;

                // Add the point value of the new card to the player's total
                player.points += nextCard.Points;

                // Output the details of the card
                //outputCard(nextCard);

                // Increment the pointer
                pointer++;
            }
        }
 public static string GetCard(PlayingCard card)
 {
     return(String.Format("{0} {1} ", card.Value.ToString(), card.Suit.ToString()));
 }
Exemple #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("\n-------Welcome To BlackJack-----------");

            //Console.WriteLine("Enter Username: "******"\nName: {p1.name} Wins: {p1.wins} Losses: {p1.losses} Balance: {p1.balance}\n");

            DeckOfCards gameDeck = new DeckOfCards();

            HandOfCards cpuHand = new HandOfCards(gameDeck);

            Console.WriteLine("\n*****************Dealers*******************\n\n");
            cpuHand.showDealerHand();
            Console.WriteLine("\n*******************************************\n");
            int dealerCount = cpuHand.handValue();

            HandOfCards playerHand = new HandOfCards(gameDeck);

            Console.WriteLine("\n**********YOURS**********\n");
            playerHand.showHand();
            int playerHandValue = playerHand.handValue();

            Console.WriteLine($"\nYour Hand Value: {playerHandValue}\n******************************\n\n");

            // player option : hit, stay, double
            Console.WriteLine($"\nHIT(h) STAY(s) DOUBLE(d)??");
            string option    = Console.ReadLine();
            string keepGoing = "y";

            do
            {
                if (option == "h")
                {
                    PlayingCard pc = gameDeck.dealCard();
                    playerHand.Add(pc);


                    Console.WriteLine("\n************************Dealers************************\n\n");
                    cpuHand.showDealerHand();
                    dealerCount = cpuHand.handValue();
                    Console.WriteLine($"\nDealer Hand Value: {dealerCount}\n************************************************************\n\n");
                    dealerCount = cpuHand.handValue();


                    Console.WriteLine("\n************************YOURS************************\n");
                    playerHand.showHand();
                    playerHandValue = playerHand.handValue();
                    Console.WriteLine($"\nYour Hand Value: {playerHandValue}\n************************************************************\n\n");
                    Console.WriteLine($"\nHIT(h) STAY(s)\n");
                }

                else if (option == "s")
                {
                    PlayingCard pc = gameDeck.dealCard();

                    Console.WriteLine("\n************Dealers************************\n");
                    cpuHand.showHand();
                    dealerCount = cpuHand.handValue();
                    Console.WriteLine($"\nDealer Hand Value: {dealerCount}\n************************************************************\n\n");



                    Console.WriteLine("\n************YOURS************************\n");
                    playerHand.showHand();
                    playerHandValue = playerHand.handValue();
                    Console.WriteLine($"\nYour Hand Value: {playerHandValue}\n************************************************************\n\n");



                    while (playerHandValue < 22 && dealerCount < 17)
                    {
                        pc = gameDeck.dealCard();
                        cpuHand.Add(pc);
                        Console.WriteLine("\n************************Dealers************************\n");
                        cpuHand.showHand();
                        dealerCount = cpuHand.handValue();
                        Console.WriteLine($"\nDealer Hand Value: {dealerCount}\n************************************************************\n\n");
                    }
                    Console.WriteLine($"\nHIT(h) STAY(s)\n");
                }
                //              double
                else if (option == "d")
                {
                    PlayingCard pc = gameDeck.dealCard();
                    playerHand.Add(pc);
                    Console.WriteLine("\n************Dealers************************\n");
                    cpuHand.showHand();
                    dealerCount = cpuHand.handValue();
                    Console.WriteLine($"\nDealer Hand Value: {dealerCount}\n************************************************************\n\n");

                    Console.WriteLine("\n************YOURS************************\n");
                    playerHand.showHand();
                    playerHandValue = playerHand.handValue();
                    Console.WriteLine($"\nYour Hand Value: {playerHandValue}\n************************************************************\n\n");


                    while (playerHandValue < 22 && dealerCount < 17)
                    {
                        pc = gameDeck.dealCard();
                        cpuHand.Add(pc);
                        Console.WriteLine("\n************************Dealers************************\n");
                        cpuHand.showHand();
                        dealerCount = cpuHand.handValue();
                        Console.WriteLine($"\nDealer Hand Value: {dealerCount}\n************************************************************\n\n");
                    }

                    dealerCount     = cpuHand.handValue();
                    playerHandValue = playerHand.handValue();
                }

                winner(playerHandValue, dealerCount);
                Console.WriteLine($"\nKeep going(y)? or quit(q)?");
                keepGoing = Console.ReadLine();

                if (keepGoing == "y")
                {
                    cpuHand = new HandOfCards(gameDeck);

                    Console.WriteLine("\n************************Dealers************************\n\n");
                    cpuHand.showDealerHand();
                    Console.WriteLine("\n************************************************************\n\n");
                    dealerCount = cpuHand.handValue();

                    playerHand = new HandOfCards(gameDeck);
                    Console.WriteLine("\n************************YOURS************************\n");
                    playerHand.showHand();
                    playerHandValue = playerHand.handValue();
                    Console.WriteLine($"\nYour Hand Value: {playerHandValue}\n************************************************************\n\n");

                    // player option : hit, stay, double
                    Console.WriteLine($"\nHIT(h) STAY(s) DOUBLE(d)??");
                    option = Console.ReadLine();
                }
                //option = Console.ReadLine();
            } while (keepGoing == "y");
        }
 internal void Add(PlayingCard pc)
 {
     gameHand.Add(pc);
 }