Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Steven Lam
- * May 8, 2013
- * Purpose: To take User's choice from the main menu, decisions, and to play Black Jack
- * Input: Choice from the main menu, User's wager, Does User want another card, Does User want to play again
- * Output: Corresponding choice from the main menu and the black jack game
- */
- import java.util.Scanner;
- public class Main {
- public static void main(String[] Args)
- {
- Scanner k = new Scanner(System.in);
- CardDeck deck = new CardDeck();
- int UserInput,Choice;
- int Another = 0;
- int menu = 0;
- int wager = 0;
- int bet = 0 ;
- int ContinueGame=1;
- Hand player = new Hand(21);
- Hand computer = new Hand(21);
- //Show The Menu
- while(menu==0)
- {
- deck.ShowMenu();
- System.out.println("What Do You Want To Do?");
- Choice = k.nextInt();
- switch(Choice)
- {
- case 1: deck = new CardDeck();
- System.out.println("You Have A New Deck");
- break;
- case 2: deck.shuffle();
- System.out.println("Your Deck Has Been Shuffled");
- break;
- case 3: System.out.println("-----------------------------------");
- System.out.println("Here Are All The Cards In The Deck!");
- System.out.println("-----------------------------------");
- deck.displayCardAt(deck.cardsLeft());
- break;
- case 4:
- //The Actual Game
- while(ContinueGame == 1)
- {
- System.out.println("Welcome To Black Jack!");
- while(bet ==0)
- {
- player.Bet();
- wager = k.nextInt();
- if (wager <=0)
- {
- System.out.println("You Can't Bet That, Try Again!");
- bet=0;
- }
- else if (wager >= 1 && wager<=player.HandMoney())
- {
- bet=1;
- }
- else if (player.HandMoney()==0)
- {
- bet=1;
- System.out.println("You Had No Money! Here Is $10");
- player.WagerWon(10);
- }
- }
- System.out.println("...Dealing...");
- //Dealing First Round
- if (deck.cardsLeft()==0)
- {
- System.out.println("There Are No More Cards In The Deck");
- System.out.println("I Got You A New Shuffled Deck");
- deck = new CardDeck();
- deck.shuffle();
- }
- computer.add(deck.Deal());
- if (deck.cardsLeft()==0)
- {
- System.out.println("There Are No More Cards In The Deck");
- System.out.println("I Got You A New Shuffled Deck");
- deck = new CardDeck();
- deck.shuffle();
- }
- player.add(deck.Deal());
- if (deck.cardsLeft()==0)
- {
- System.out.println("There Are No More Cards In The Deck");
- System.out.println("I Got You A New Shuffled Deck");
- deck = new CardDeck();
- deck.shuffle();
- }
- computer.add(deck.Deal());
- if (deck.cardsLeft()==0)
- {
- System.out.println("There Are No More Cards In The Deck");
- System.out.println("I Got You A New Shuffled Deck");
- deck = new CardDeck();
- deck.shuffle();
- }
- player.add(deck.Deal());
- //shows first round cards
- System.out.println("---------------");
- System.out.println(" Dealer's Hand ");
- System.out.println("---------------");
- computer.DealerFirstRound();
- System.out.println("---------------");
- System.out.println(" Your Hand ");
- System.out.println("---------------");
- player.showHand();
- System.out.println("Player's Hand Value is: "+player.HandValue());
- //Player's turn to add cards
- while(Another==0)
- {
- System.out.println("Do You Want Another Card? [Y/N] (Yes: Type 1 // No: Enter 2)");
- UserInput = k.nextInt();
- if (UserInput == 1)
- {
- if (deck.cardsLeft()==0)
- {
- System.out.println("There Are No More Cards In The Deck");
- System.out.println("I Got You A New Shuffled Deck");
- deck = new CardDeck();
- deck.shuffle();
- }
- player.add(deck.Deal());
- System.out.println("---------------");
- System.out.println(" Dealer's Hand ");
- System.out.println("---------------");
- computer.DealerFirstRound();
- System.out.println("---------------");
- System.out.println(" Your Hand ");
- System.out.println("---------------");
- player.showHand();
- System.out.println("Your Hand Value is: " +player.HandValue());
- if (player.HandValue()>21)
- {
- Another = 1;
- }
- }
- else
- Another = 1;
- }
- //Dealer's turn to add cards
- while(computer.HandValue()<17 && player.HandValue()<=21)
- {
- if (deck.cardsLeft()==0)
- {
- System.out.println("There Are No More Cards In The Deck");
- System.out.println("I Got You A New Shuffled Deck");
- deck = new CardDeck();
- deck.shuffle();
- }
- computer.add(deck.Deal());
- System.out.println("---------------");
- System.out.println(" Dealer's Hand ");
- System.out.println("---------------");
- computer.showHand();
- System.out.println("---------------");
- System.out.println(" Your Hand ");
- System.out.println("---------------");
- player.showHand();
- }
- System.out.println("");
- System.out.println("Dealer Stands");
- //Results
- if (player.HandValue()<=21)
- {
- System.out.println("---------------");
- System.out.println(" Dealer's Hand ");
- System.out.println("---------------");
- computer.showHand();
- System.out.println("");
- System.out.println("Dealer's Hand Total: "+ computer.HandValue());
- System.out.println("---------------");
- System.out.println(" Your Hand ");
- System.out.println("---------------");
- player.showHand();
- System.out.println("");
- System.out.println("Your Hand Total: "+ player.HandValue());
- //Comparing to see who wins
- if (computer.HandValue()<=21 && player.HandValue()<=21)
- {
- if (computer.HandValue()>player.HandValue())
- {
- System.out.println("Sorry You Lost!");
- System.out.println(" ");
- player.WagerLost(wager);
- }
- else if (player.HandValue()>computer.HandValue())
- {
- System.out.println("Congrautaltions! You Won!!");
- System.out.println(" ");
- player.WagerWon(wager);
- }
- else
- System.out.println("It's A Tie, Here's Your Money Back");
- System.out.println(" ");
- }
- else if(computer.HandValue()>21 && player.HandValue()<=21)
- {
- System.out.println("Congrautaltions! You Won!!");
- System.out.println(" ");
- player.WagerWon(wager);
- }
- }
- else
- {
- System.out.println("Sorry, You Lost!");
- player.WagerLost(wager);
- }
- System.out.println("Want To Play Again? [Y/N] (Yes: Type 1 // No: Enter 2)");
- ContinueGame = k.nextInt();
- Another=0;
- bet=0;
- wager=0;
- player.CountReset();
- computer.CountReset();
- }
- break;
- case 5: menu = 1;
- break;
- default: System.out.println("That Is Not A Choice On The Menu");
- }
- }
- System.out.println("Thank You For Playing BlackJack");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement