Advertisement
lilflamekid91

Lab 6 - Main Class

May 25th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.81 KB | None | 0 0
  1. /*Steven Lam
  2.  * May 8, 2013
  3.  * Purpose: To take User's choice from the main menu, decisions, and to play Black Jack
  4.  * Input: Choice from the main menu, User's wager, Does User want another card, Does User want to play again
  5.  * Output: Corresponding choice from the main menu and the black jack game
  6.  */
  7. import java.util.Scanner;
  8.  
  9. public class Main {
  10.     public static void main(String[] Args)
  11.     {
  12.         Scanner k = new Scanner(System.in);
  13.         CardDeck deck = new CardDeck();
  14.         int UserInput,Choice;
  15.         int Another = 0;
  16.         int menu = 0;
  17.         int wager = 0;
  18.         int bet = 0 ;
  19.         int ContinueGame=1;
  20.         Hand player = new Hand(21);
  21.         Hand computer = new Hand(21);
  22.         //Show The Menu
  23.         while(menu==0)
  24.         {
  25.         deck.ShowMenu();
  26.         System.out.println("What Do You Want To Do?");
  27.         Choice = k.nextInt();
  28.         switch(Choice)
  29.         {
  30.         case 1: deck = new CardDeck();
  31.                 System.out.println("You Have A New Deck");
  32.             break;
  33.         case 2: deck.shuffle();
  34.                 System.out.println("Your Deck Has Been Shuffled");
  35.             break;
  36.         case 3:  System.out.println("-----------------------------------");
  37.                  System.out.println("Here Are All The Cards In The Deck!");
  38.                  System.out.println("-----------------------------------");
  39.                
  40.                 deck.displayCardAt(deck.cardsLeft());
  41.                  break;
  42.         case 4:
  43.                 //The Actual Game
  44.             while(ContinueGame == 1)
  45.             {
  46.                 System.out.println("Welcome To Black Jack!");
  47.                 while(bet ==0)
  48.                 {
  49.                     player.Bet();
  50.                     wager = k.nextInt();
  51.                     if (wager <=0)
  52.                     {
  53.                         System.out.println("You Can't Bet That, Try Again!");
  54.                         bet=0;
  55.                     }
  56.                     else if (wager >= 1 && wager<=player.HandMoney())
  57.                     {
  58.                         bet=1;
  59.                     }
  60.                     else if (player.HandMoney()==0)
  61.                     {
  62.                         bet=1;
  63.                         System.out.println("You Had No Money! Here Is $10");
  64.                         player.WagerWon(10);
  65.                     }
  66.                 }
  67.                 System.out.println("...Dealing...");
  68.                 //Dealing First Round
  69.                 if (deck.cardsLeft()==0)
  70.                 {
  71.                     System.out.println("There Are No More Cards In The Deck");
  72.                     System.out.println("I Got You A New Shuffled Deck");
  73.                     deck = new CardDeck();
  74.                     deck.shuffle();
  75.                 }
  76.                 computer.add(deck.Deal());
  77.                 if (deck.cardsLeft()==0)
  78.                 {
  79.                     System.out.println("There Are No More Cards In The Deck");
  80.                     System.out.println("I Got You A New Shuffled Deck");
  81.                     deck = new CardDeck();
  82.                     deck.shuffle();
  83.                 }
  84.                 player.add(deck.Deal());
  85.                 if (deck.cardsLeft()==0)
  86.                 {
  87.                     System.out.println("There Are No More Cards In The Deck");
  88.                     System.out.println("I Got You A New Shuffled Deck");
  89.                     deck = new CardDeck();
  90.                     deck.shuffle();
  91.                 }
  92.                 computer.add(deck.Deal());
  93.                 if (deck.cardsLeft()==0)
  94.                 {
  95.                     System.out.println("There Are No More Cards In The Deck");
  96.                     System.out.println("I Got You A New Shuffled Deck");
  97.                     deck = new CardDeck();
  98.                     deck.shuffle();
  99.                 }
  100.                 player.add(deck.Deal());
  101.                 //shows first round cards
  102.                 System.out.println("---------------");
  103.                 System.out.println(" Dealer's Hand ");
  104.                 System.out.println("---------------");
  105.                 computer.DealerFirstRound();
  106.                 System.out.println("---------------");
  107.                 System.out.println("   Your Hand   ");
  108.                 System.out.println("---------------");
  109.                 player.showHand();
  110.                 System.out.println("Player's Hand Value is: "+player.HandValue());
  111.                
  112.                 //Player's turn to add cards
  113.                 while(Another==0)
  114.                 {
  115.                     System.out.println("Do You Want Another Card? [Y/N] (Yes: Type 1 // No: Enter 2)");
  116.                     UserInput = k.nextInt();
  117.                     if (UserInput == 1)
  118.                     {
  119.                         if (deck.cardsLeft()==0)
  120.                         {
  121.                             System.out.println("There Are No More Cards In The Deck");
  122.                             System.out.println("I Got You A New Shuffled Deck");
  123.                             deck = new CardDeck();
  124.                             deck.shuffle();
  125.                         }
  126.                         player.add(deck.Deal());
  127.                         System.out.println("---------------");
  128.                         System.out.println(" Dealer's Hand ");
  129.                         System.out.println("---------------");
  130.                         computer.DealerFirstRound();
  131.                         System.out.println("---------------");
  132.                         System.out.println("   Your Hand   ");
  133.                         System.out.println("---------------");
  134.                         player.showHand();
  135.                         System.out.println("Your Hand Value is: " +player.HandValue());
  136.                         if (player.HandValue()>21)
  137.                         {
  138.                             Another = 1;
  139.                         }
  140.                     }
  141.                    
  142.                     else
  143.                         Another = 1;
  144.                 }
  145.                     //Dealer's turn to add cards
  146.                 while(computer.HandValue()<17 && player.HandValue()<=21)
  147.                 {
  148.                     if (deck.cardsLeft()==0)
  149.                     {
  150.                         System.out.println("There Are No More Cards In The Deck");
  151.                         System.out.println("I Got You A New Shuffled Deck");
  152.                         deck = new CardDeck();
  153.                         deck.shuffle();
  154.                     }
  155.                     computer.add(deck.Deal());
  156.                     System.out.println("---------------");
  157.                     System.out.println(" Dealer's Hand ");
  158.                     System.out.println("---------------");
  159.                     computer.showHand();
  160.                     System.out.println("---------------");
  161.                     System.out.println("   Your Hand   ");
  162.                     System.out.println("---------------");
  163.                     player.showHand();
  164.                 }
  165.                
  166.                 System.out.println("");
  167.                 System.out.println("Dealer Stands");
  168.                 //Results
  169.                 if (player.HandValue()<=21)
  170.                 {
  171.                 System.out.println("---------------");
  172.                 System.out.println(" Dealer's Hand ");
  173.                 System.out.println("---------------");
  174.                 computer.showHand();
  175.                 System.out.println("");
  176.                 System.out.println("Dealer's Hand Total: "+ computer.HandValue());
  177.                 System.out.println("---------------");
  178.                 System.out.println("   Your Hand   ");
  179.                 System.out.println("---------------");
  180.                 player.showHand();
  181.                 System.out.println("");
  182.                 System.out.println("Your Hand Total: "+ player.HandValue());
  183.                 //Comparing to see who wins
  184.                 if (computer.HandValue()<=21 && player.HandValue()<=21)
  185.                 {
  186.                     if (computer.HandValue()>player.HandValue())
  187.                     {
  188.                         System.out.println("Sorry You Lost!");
  189.                         System.out.println(" ");
  190.                         player.WagerLost(wager);
  191.                     }
  192.                     else if (player.HandValue()>computer.HandValue())
  193.                     {
  194.                         System.out.println("Congrautaltions! You Won!!");
  195.                         System.out.println(" ");
  196.                         player.WagerWon(wager);
  197.                     }
  198.                     else
  199.                         System.out.println("It's A Tie, Here's Your Money Back");
  200.                         System.out.println(" ");
  201.                 }
  202.                 else if(computer.HandValue()>21 && player.HandValue()<=21)
  203.                 {
  204.                     System.out.println("Congrautaltions! You Won!!");
  205.                     System.out.println(" ");
  206.                     player.WagerWon(wager);
  207.                 }
  208.                 }
  209.                 else
  210.                 {
  211.                     System.out.println("Sorry, You Lost!");
  212.                     player.WagerLost(wager);
  213.                 }
  214.                 System.out.println("Want To Play Again? [Y/N] (Yes: Type 1 // No: Enter 2)");
  215.                 ContinueGame = k.nextInt();
  216.                 Another=0;
  217.                 bet=0;
  218.                 wager=0;
  219.                 player.CountReset();
  220.                 computer.CountReset();
  221.             }
  222.                 break;
  223.         case 5: menu = 1;
  224.                 break;
  225.              default: System.out.println("That Is Not A Choice On The Menu");
  226.             }
  227.         }
  228.     System.out.println("Thank You For Playing BlackJack");
  229. }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement