/// <summary> /// Clear game and set up /// </summary> private void SetupGame() { Reset(); deck = SetupDeck(3); //Set up the hands playerHand = new Hand(); dealerHand = new Hand(); dealerFullHand = new Hand(); //Deal the player two cards DealPlayerCard(); DealPlayerCard(); //Deal the dealer his card and the hole DealDealerCard(); holeCard = deck.DrawOneCard(); //Add the hole card to the full hand //which is already equal to the visible hand dealerFullHand.Add(holeCard); //If the player has Blackjack end the game. if (HandValue(playerHand) == 21) { EndGame(); } //If the dealer has blackjack end the game. if (HandValue(dealerFullHand) == 21) { hasDealerStand = true; EndGame(); } }
/// <summary> /// Deal the player a card /// </summary> private void DealPlayerCard() { //Draw one card and add it to the players hand Card card = deck.DrawOneCard(); playerHand.Add(card); DisplayCards(); //Update the value of the players hand int playerHandValue = HandValue(playerHand); System.Windows.Application.Current.Dispatcher.Invoke(delegate { lblHandValue.Content = playerHandValue.ToString(); }); if (playerHandValue > 21) //If the player has gone bust { EndGame(); } }
/// <summary> /// Creates a Blackjack deck from the number of regular decks specified /// </summary> /// <param name="numDecks">The number of decks to use</param> public static Deck MakeBlackjackDeck(int numDecks) { List <Card> newDeck = new List <Card>(); for (int i = 0; i < numDecks; i++) { Deck baseDeck = new Deck(); for (int x = 0; x < 52; x++) { newDeck.Add(baseDeck.DrawOneCard()); } } return(new Deck(newDeck)); }