Exemplo n.º 1
0
        /* This method displays the final score for the dealer hand, then displays
         * the result of each player hand one at a time.  This can never be called
         * if all of a player's hands have been busted thus it only applies to */
        protected void ResolvePlayerHands()
        {
            ShowDealerScore();
            CasinoDoor.WaitForDisplay();                  //A short delay before displaying the player's hands

            int dealerScore = CheckHandScore(dealerHand); //Stores the dealer's hand score

            //Player hands are resolved one at a time
            for (int handIndex = 0; handIndex < playerHands.Count; handIndex++)
            {
                int handScore = CheckHandScore(playerHands[handIndex]);

                Console.Write("Hand " + (handIndex + 1).ToString() + ": ");
                if ((handScore > dealerScore) || (handScore < dealerScore && dealerScore > 21)) //A player always wins these hands
                {
                    ResolveWinningHand(handIndex);
                }
                else if (handScore < dealerScore && dealerScore <= 21) //A player always loses this hand
                {
                    ResolveLosingHand(handIndex);
                }
                else //If the player's hand and the dealer both have the same hand value
                {
                    ResolveTiedHand(handIndex); //A player wins if this hand is a blackjack and the dealer's isn't, otherwise it is a push
                }
                CasinoDoor.RestoreDefaultColors(); //The default colors are restored after each hand as each hand resolution may have unique coloring
                CasinoDoor.WaitForDisplay();       //Each hand is displayed with a slight delay before the next reveal
            }
        }
Exemplo n.º 2
0
 //If the player makes an incorrect selection the error is displayed before they are re-prompted
 public void DisplayError(string error)
 {
     Console.BackgroundColor = ConsoleColor.Black;
     Console.ForegroundColor = ConsoleColor.DarkRed;
     Console.WriteLine(error);
     CasinoDoor.RestoreDefaultColors();
     CasinoDoor.WaitForDisplay();
 }
Exemplo n.º 3
0
        /* PlayHand initializes the loop for a single hand of BlackJack.  Returns
         * true or false based on whether or not the player wants to keep playing
         * at the end of a hand*/
        private bool PlayHand()
        {
            bool handInProgress     = true; //This variable tracks whether a hand is complete
            bool dealerHandRevealed = false;

            while (handInProgress)
            {
                DisplayTable(dealerHandRevealed);
                if (playerHands.Count == 0) //If the player is not currently holding any cards
                {
                    GetWagerAndDeal();
                }
                else //If the player has at least one hand
                {
                    Console.WriteLine();
                    if (AllHandsFrozen() == true) //If all the hands are busted, doubled down, or stayed
                    {
                        if (AllHandsBusted() == false)
                        {
                            dealerHandRevealed = true;
                            DisplayTable(dealerHandRevealed);
                            if (CheckHandScore(dealerHand) < 17)
                            {
                                CasinoDoor.WaitForDisplay();
                                DealerHit();
                            }
                            else
                            {
                                dealerHandRevealed = true;
                                ResolvePlayerHands();
                                handInProgress = false;
                            }
                        }
                        else
                        {
                            handInProgress = false;
                        }

                        Console.WriteLine(); //Spacing for readability
                        CasinoDoor.WaitForDisplay();
                    }
                    else
                    {
                        OfferPlayerOptions();
                        CasinoDoor.WaitForDisplay();
                    }
                }
            }
            if (HumanPlayer.Bank > 0)
            {
                return(PlayAnotherHand(true));
            }
            else
            {
                Console.WriteLine("You went bankrupt! Time to go home.");
                return(false);
            }
        }
Exemplo n.º 4
0
 //This is called by PlayGame when the player has no cards
 private void GetWagerAndDeal()
 {
     if (InitialWagerPrompt() == true)
     {
         Console.WriteLine();
         DealHands();
         CasinoDoor.WaitForDisplay();
     }
     else
     {
         DisplayError("Invalid wager, try again");
     }
 }
Exemplo n.º 5
0
 /* Shuffles the deck and deals the initial 4 cards, 2 to the dealer and 2 to the
  * human player.*/
 public void DealHands()
 {
     Console.WriteLine("Shuffling deck...");
     Deck.ShuffleDeck();
     CasinoDoor.WaitForDisplay();
     Console.WriteLine("Dealing hands...");
     for (int startingCards = 0; startingCards < 2; startingCards++)
     {
         if (playerHands.Count == 0)
         {
             playerHands.Add(new CardList());
             frozenHands.Add(false);
         }
         playerHands[0].AddCard(Deck.DealCard());
         dealerHand.AddCard(Deck.DealCard());
     }
 }
Exemplo n.º 6
0
        //This is called by PlayGame when there is one or more hands needing attention from the user
        private void OfferPlayerOptions()
        {
            for (int handIndex = 0; handIndex < playerHands.Count; handIndex++) //Iterates over the currently present hands
            {
                if (frozenHands[handIndex] == false)                            //Checks to see if this hand has been frozen
                {
                    int cardsInHand = playerHands[handIndex].Cards.Count;

                    if (cardsInHand == 2 && HumanPlayer.Bank > 0)                      //If the player's hand has 2 cards and the player has funds remaining
                    {
                        if (CheckBlackJack(playerHands[handIndex], handIndex) == true) //Checks for a blackjack
                        {
                            AnnounceBlackJack(handIndex);
                        }
                        else if (CheckSplit(playerHands[handIndex]) == true)                //Checks to see if the cards are a pair
                        {
                            if (SplitHandPrompt(playerHands[handIndex], handIndex) == true) //Prompts the player to split the hand and validates input
                            {
                                CasinoDoor.WaitForDisplay();
                                break;
                            }
                            else //If the user presses a wrong key when attempting to split a hand
                            {
                                DisplayError("Input for split attempt invalid, please try again."); //Occurs when the player's input is invalid
                                break;
                            }
                        }
                        else
                        {
                            if (DoubleDownPrompt(playerHands[handIndex], handIndex) == true) //Prompts the player to double down and verifies input
                            {
                                CasinoDoor.WaitForDisplay();
                                break;
                            }
                            else //If the user presses an incorrect key when attempting to double down
                            {
                                DisplayError("Input for double down attempt invalid, please try again."); //Occurs when the player's input is invalid
                                break;
                            }
                        }
                    }
                    else if (cardsInHand == 2 && HumanPlayer.Bank <= 0)                //If the player has 2 cards but does not have any funds remaining
                    {
                        if (CheckBlackJack(playerHands[handIndex], handIndex) == true) //Checks for a blackjack
                        {
                            AnnounceBlackJack(handIndex);
                        }
                        else if (CheckSplit(playerHands[handIndex]) == true) //If the hand is not a blackjack but is a face-value pair
                        {
                            Console.WriteLine("Insufficient funds to split hand.");
                            CasinoDoor.WaitForDisplay();
                        }
                        else
                        {
                            Console.WriteLine("Insufficient funds to double down on hand."); //If the hand is neither blackjack nor a pair
                            CasinoDoor.WaitForDisplay();
                            HitOrStay(playerHands[handIndex], handIndex);                    //This ensures that the split/double down checks won't loop endlessly
                        }
                    }
                    else //If this hand has more than 2 cards in it
                    {
                        if (CheckHandScore(playerHands[handIndex]) < 21)
                        {
                            HitOrStay(playerHands[handIndex], handIndex);  //Prompts the player to hit or stay
                        }
                        break;
                    }
                }
            }
        }