
/* Check if one of the players has Blackjack (two cards totaling to 21).
The player with Blackjack wins the game.
Dealer wins ties.
*/
if (value(dealerHand) == 21)
{
System.out.println("Dealer has the " + showCard(getCard(dealerHand, 0))
+ " and the " + showCard(getCard(dealerHand, 1)) + ".");
System.out.println("User has the " + showCard(getCard(userHand, 0)) + "
and the " + showCard(getCard(userHand, 1)) + ".");
System.out.println();
System.out.println("Dealer has Blackjack.
Dealer wins.");
return false;
}
if (value(userHand) == 21)
{
System.out.println("Dealer has the " + showCard(getCard(dealerHand, 0))
+ " and the " + showCard(getCard(dealerHand, 1)) + ".");
System.out.println("User has the " + showCard(getCard(userHand, 0)) + "
and the " + showCard(getCard(userHand, 1)) + ".");
System.out.println();
System.out.println("You have Blackjack.
You win.");
return true;
}
/*
If neither player has Blackjack, play the game.
The user gets a chance
to draw cards (i.e., to "Hit").
The while loop ends when the user
chooses to "Stand" or when the user goes over 21.
*/
while (true)
{
/* Display user's cards, and let user decide to Hit or Stand. */
System.out.println();
System.out.println();
System.out.println("Your cards are:");
for (int i = 0; i < userHand.size(); i++)
{
System.out.println("
" + showCard(getCard(userHand, i)));
}
System.out.println("Your total is " + value(userHand));
System.out.println();
System.out.println("Dealer is showing the " +
showCard(getCard(dealerHand, 0)));
System.out.println();
System.out.print("Hit (H) or Stand (S)? ");
char userAction;
// User's response, 'H' or 'S'.

