Beispiel #1
0
        public static void playerDecisions(CardHand[] player, DeckOfCards shuffled_Deck)
        {
            for (int i = 0; i < player.GetUpperBound(0); i++) //The decision rests on i; no decisions for dealer.
            {                                                 //Print opponent's hands.
                Console.Clear();
                for (int j = 0; j <= player.GetUpperBound(0); j++)
                {
                    if (j != i)
                    {
                        writePlayerHand(j, false, player);
                    }
                }

                //Go back and print i
                Console.WriteLine();
                writePlayerHand(i, true, player);

                //Hit or Stay?
                Console.WriteLine();
                string hitChoice;
                do
                {
                    Console.WriteLine("Your current score: {0}.", player[i].score);
                    Console.Write($"{player[i].playerName}, (H)it or (S)tay: ");
                    hitChoice = Console.ReadLine().ToUpper();
                    if (hitChoice == "H")
                    {
                        player[i].TakeCard(shuffled_Deck.DealCard());
                        writePlayerHand(i, true, player);
                        WinnerStatus(player[i].score, player[player.GetUpperBound(0)].score, false);
                        if (player[i].score >= 21)
                        {
                            break;
                        }                                    //Exit if Blackjack or Bust
                    }
                } while (hitChoice.ToUpper() == "H");
                continue;
            }
        }
Beispiel #2
0
        public static void Play_Blackjack()
        {
            int    numberCards_InitialDeal_Blackjack = 2;
            int    numberPlayers = 0;
            string continuePlay;

            //Generate Shuffled deck
            DeckOfCards shuffled_Deck = new DeckOfCards(1);

            //Number of players
            Console.Clear();
            Console.Write("Enter the number of players: ");
            Int32.TryParse(Console.ReadLine(), out numberPlayers);

            //Initial Deal
            //Assume last player is dealer.
            CardHand[] playerHand = new CardHand[numberPlayers + 1];
            initialDeal(numberCards_InitialDeal_Blackjack, numberPlayers, playerHand, shuffled_Deck);

            //For each player, display hand; only show first card of all opponents including dealer.
            Console.Clear();
            playerDecisions(playerHand, shuffled_Deck);
            dealerDecisions(playerHand, shuffled_Deck);

            DisplayGameStatus(playerHand);
            Console.WriteLine("Would you like to play again? Y/N");
            continuePlay = Console.ReadLine();
            if (continuePlay.ToUpper() == "Y")
            {
                Play_Blackjack();
            }
            else
            {
                System.Environment.Exit(0);
            }
        }
Beispiel #3
0
        public static void initialDeal(int numberCardsPerPlayer, int numberPlayers, CardHand[] player, DeckOfCards shuffled_Deck)
        {//Deals two cards to each player in increasing order.  Also, records player's names during the process.
            string name;

            for (int j = 0; j < numberCardsPerPlayer; j++)
            {
                for (int i = 0; i <= numberPlayers; i++)
                {
                    if (j == 0)
                    {
                        if (i != numberPlayers)
                        {
                            Console.WriteLine("Enter Player {0}'s name:", i + 1);
                            name = Console.ReadLine();
                        }
                        else
                        {
                            name = "Dealer";
                        }
                        player[i] = new CardHand(name);
                    }
                    player[i].TakeCard(shuffled_Deck.DealCard());
                }
            }
        }