private HighPlayer EvaluateHands() { // Compare the player hands to determine the result // of the play. HighPlayer result = HighPlayer.Undetermined; int playerHand = tablePlayer.GetHandValue(); int dealerHand = dealerPlayer.GetHandValue(); try { // If it's no longer the table player's turn, // show the dealer hand. if (Turn < PlayerTurn.Player) { ShowDealerHand(); } // Look for a push. if (playerHand == dealerHand) { result = HighPlayer.Push; // If the hands are 21 or higher, end. if (playerHand >= BLACKJACK) { Turn = PlayerTurn.Close; } } // Look for a bust if (result == HighPlayer.Undetermined) { if (playerHand > BLACKJACK && dealerHand < BLACKJACK) { // Table player busts. result = HighPlayer.DealerWin; PlayerPicture.Image = MiscImagery.Images["Bust.jpg"]; } else if (dealerHand > BLACKJACK && playerHand < BLACKJACK) { // Dealer busts. result = HighPlayer.PlayerWin; DealerPicture.Image = MiscImagery.Images["Bust.jpg"]; } if (result != HighPlayer.Undetermined) { Turn = PlayerTurn.Close; } } // Look for a player with 21. if (result == HighPlayer.Undetermined) { if (playerHand == BLACKJACK || dealerHand == BLACKJACK) { Turn = PlayerTurn.Close; if (playerHand == BLACKJACK) { result = HighPlayer.PlayerBlackJack; } else { result = HighPlayer.DealerBlackJack; } } } // Look for a non-winning high player. if (result == HighPlayer.Undetermined) { result = (playerHand > dealerHand) ? HighPlayer.Player : HighPlayer.Dealer; } // The dealer must stand on 17 or greater. if (Turn == PlayerTurn.Dealer && dealerHand > 16) { if (result != HighPlayer.Push) { result = (playerHand > dealerHand) ? HighPlayer.PlayerWin : HighPlayer.DealerWin; } Turn = PlayerTurn.Close; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error ..."); } return(result); }
private void HandProgress(HighPlayer status) { double betAmount; try { // Get the bet amount from the form. betAmount = double.Parse(txtBet.Text); // If either player has won, show the dealer's hand. if (status <= HighPlayer.Push) { ShowDealerHand(); } // Display the appropriate message and adjust the bank // depending on the winning player. switch (status) { case HighPlayer.DealerWin: MessageBox.Show("Dealer wins."); ProcessBet(tablePlayer, (betAmount * -1)); break; case HighPlayer.DealerBlackJack: DealerPicture.Image = MiscImagery.Images["Blackjack.jpg"]; MessageBox.Show("Dealer has Blackjack."); ProcessBet(tablePlayer, (betAmount * -1)); break; case HighPlayer.PlayerWin: MessageBox.Show("You win!"); ProcessBet(tablePlayer, (betAmount)); break; case HighPlayer.PlayerBlackJack: PlayerPicture.Image = MiscImagery.Images["Blackjack.jpg"]; MessageBox.Show("BLACKJACK!"); ProcessBet(tablePlayer, (betAmount)); break; case HighPlayer.Push: if (Turn == PlayerTurn.Close) { MessageBox.Show("You and the Dealer push ... sorry."); } break; default: break; } // Update the player stats on the form. UpdatePlayerStats(); // Adjust the controls. if (Turn == PlayerTurn.Close) { txtBet.ReadOnly = false; DealButtonSwitch(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error ..."); } }