private void GamePlayLogic() { switch (playerPlaying) { // Player is playing. case 1: // player can split hand if the first two cards are of the same type and its the initial deal. if (p.PlayerMainHand[0].cardType == p.PlayerMainHand[1].cardType && initialDeal == true) { buttonSplit.Enabled = true; } initialDeal = false; if (playingSplitHand == false) { // Only show one of the dealers cards and the value of that card until its the dealers turn to play. d.DisplayPlayerHand(panelDealerHand, d.DealerHand, d.playerName); labelDealersHand.Text = "Dealer shows: " + d.DealerHand[1].CardValue.ToString(); // Player has blackjack or player has 21 or player busts. Pass the play to the dealer by setting playerPlaying to 2. if ((p.PlayerMainHand[0].CardValue + p.PlayerMainHand[1].CardValue == 21) || p.CountHand(p.PlayerMainHand) >= 21) { if (splitHand == true) { playingSplitHand = true; panelPlayerHand.BackColor = Color.Transparent; panelSplitHand.BackColor = Color.Lime; } else { playerPlaying = 2; } } //Show the players hand and update the players label to reflect the total of the hand. p.DisplayPlayerHand(panelPlayerHand, p.PlayerMainHand, p.playerName); if (p.PlayerMainHand[0].CardValue + p.PlayerMainHand[1].CardValue == 21) { labelPlayerMainHand.Text = "Player has: BlackJack"; } else if (p.CountHand(p.PlayerMainHand) <= 21) { labelPlayerMainHand.Text = "Player has: " + p.CountHand(p.PlayerMainHand).ToString(); } else if (p.CountHand(p.PlayerMainHand) > 21) { labelPlayerMainHand.Text = "Player busts with " + p.CountHand(p.PlayerMainHand).ToString(); } if (doubleDown == true) { playerPlaying = 2; } } else if (playingSplitHand == true) { // Player has blackjack or player has 21 or player busts. Pass the play to the dealer by setting playerPlaying to 2. if ((p.PlayerSplitHand[0].CardValue + p.PlayerSplitHand[1].CardValue == 21) || p.CountHand(p.PlayerSplitHand) >= 21) { playerPlaying = 2; } //Show the players hand and update the players label to reflect the total of the hand. p.DisplayPlayerHand(panelSplitHand, p.PlayerSplitHand, p.playerName); if (p.PlayerSplitHand[0].CardValue + p.PlayerSplitHand[1].CardValue == 21) { labelPlayerSplitHand.Text = "Player has: BlackJack"; } else if (p.CountHand(p.PlayerSplitHand) <= 21) { labelPlayerSplitHand.Text = "Player has: " + p.CountHand(p.PlayerSplitHand).ToString(); } else if (p.CountHand(p.PlayerSplitHand) > 21) { labelPlayerSplitHand.Text = "Player busts with " + p.CountHand(p.PlayerSplitHand).ToString(); } } // Pass the play to the dealer if the player is finished. if (playerPlaying == 2) { doubleDown = false; GamePlayLogic(); } break; // Dealer is playing case 2: disablePlayerButtons(); panelSplitHand.BackColor = Color.Transparent; // Player does not have blackjack. Dealer plays the hand. if (!(p.PlayerMainHand[0].CardValue + p.PlayerMainHand[1].CardValue == 21)) { while (d.CountHand(d.DealerHand) < 17) { d.DealerHand.Add(d.DealCard(cd.ShoeDeck)); d.DisplayPlayerHand(panelDealerHand, d.DealerHand, d.playerName, true); } } // Show the dealers full hand and update the dealers label to reflect the total of the hand. d.DisplayPlayerHand(panelDealerHand, d.DealerHand, d.playerName, true); if (d.DealerHand[0].CardValue + d.DealerHand[1].CardValue == 21) { labelDealersHand.Text = "Dealer has: BlackJack"; } else { labelDealersHand.Text = "Dealer has: " + d.CountHand(d.DealerHand).ToString(); } checkWin(); buttonDeal.Enabled = true; playerPlaying = 1; break; default: break; } // Shoe deck is getting low. Repopulate queue. if (cd.ShoeDeck.Count <= 25) { cd.ShuffleDeck(); } }