All pastes #470139 Raw Edit

blackjack

public java v1 · immutable
·published 2007-05-04 02:44 UTC
rendered paste body
import javax.swing.*;import java.text.*;import java.util.*;// import blackjack.*;/** * This is the main class for the Blackjack Game. * * @author Bill Kukowski */public class BlackjackMain{	/**	 * Main method. Controls program I/O	 *	 * @param args	 */	public static void main(String[] args)	{		Account account;		boolean userDumb, playing, sameHand;		playing = sameHand = true;				//create deck		Deck deck;		DecimalFormat df = new DecimalFormat("0.00"); //used for cost display		Rules rules = new Rules();		Hand playerHand, dealerHand;				while (playing) //game loop		{			deck = new Deck();			deck.shuffle();			account = new Account();						while (sameHand && account.getBalance() > 0) //hand loop			{				playerHand = new Hand();				dealerHand = new Hand();				userDumb = true;						playerHand.addCardToHand(deck.drawCard());				playerHand.addCardToHand(deck.drawCard());						dealerHand.addCardToHand(deck.drawCard());				dealerHand.addCardToHand(deck.drawCard());								Scanner scanner = new Scanner(System.in);						double amount = 0;								//getbet				while (userDumb) 				{					System.out.println("You have $" + df.format(account.getBalance()) + " in your account.");					System.out.print("How much do you want to bet? ");					amount = 0;					amount = scanner.nextDouble();								if (amount <= account.getBalance()) 					{						account.withdraw(amount);						account.addToBet(amount);						userDumb = false;					}					else {System.out.println("You are stupid. Bet less money!" );					}							}						System.out.println("You have these cards:");				playerHand.printCards();						System.out.println("The dealer has a " + deck.getCardName(dealerHand.getCard(1)) + " showing.");						if (rules.blackjack(playerHand)) //check blackjack!				{					System.out.println("You have Blackjack!");					account.deposit(amount*2);							}								if (rules.doubleDownEnable(playerHand))//check double down				{					System.out.println("Press 1 to double down.  Press 0 if you don't want to.");					if (scanner.nextInt() == 1) 					{						rules.doubleDown(account, amount, playerHand, deck);						System.out.println("You now have these cards.");						playerHand.printCards();					}				}								while (playerHand.getHandTotal() < 21) //enable hit while player has less than 21				{					System.out.println("Press 1 to hit, 2 to stand.");					if (scanner.nextInt() == 1) 					{						playerHand.addCardToHand(deck.drawCard());						System.out.println("You now have these cards.");						playerHand.printCards();					}					if (playerHand.getHandTotal() > 21) {						System.out.println("bust!");						sameHand = false;					}				}																							}		}	}}