Advertisement
lilflamekid91

Lab 5 - Main Class

May 25th, 2013
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.89 KB | None | 0 0
  1. /*Steven Lam
  2.  * April 24, 2013
  3.  * Purpose: To take User inputs and run the corresponding choice from the main menu and to play the War Game
  4.  * Input: Choice from the main menu and yes/no if User wants to play again
  5.  * Output: Corresponding choice from the main menu and the War Game
  6.  */
  7. import java.util.Scanner;
  8. public class Main {
  9.  
  10.     public static void main(String[] args)
  11.     {
  12.         Scanner keyboard = new Scanner(System.in);
  13.         int Choice;
  14.         int menu=0, WAR=1;
  15.         CardDeck d = new CardDeck();
  16.        
  17.         System.out.println("Welcome to the War Game");
  18.         d.ShowMenu();
  19.        
  20.         while (menu==0){
  21.         Choice = keyboard.nextInt();
  22.         WAR=1;
  23.         d.User=0;
  24.         d.Comp=0;
  25.         switch (Choice) {
  26.        
  27.           case 1:
  28.               d = new CardDeck();
  29.               System.out.println("You Have A New Card Deck!");
  30.               d.ShowMenu();
  31.             break;
  32.            
  33.           case 2:
  34.               System.out.println("-----------------------------------");
  35.               System.out.println("Here Are All The Cards In The Deck!");
  36.               System.out.println("-----------------------------------");
  37.               for (int k = 0; k<52;k++)
  38.               {
  39.                   d.displayCardAt(k);
  40.               }
  41.               d.ShowMenu();
  42.             break;
  43.            
  44.           case 3:
  45.               d.shuffle();
  46.               System.out.println("Your Deck Has Been Shuffled!");
  47.               d.ShowMenu();
  48.             break;
  49.            
  50.           case 4:
  51.               while(WAR==1)
  52.               {
  53.                   System.out.println("----------------------------------");
  54.                   System.out.println("Get Ready To Play Two-Card WAR!!!!");
  55.                   System.out.println("----------------------------------");
  56.                   System.out.println("There are "+d.cardsLeft()+" left in the deck.");
  57.                   System.out.println("...dealing...");
  58.                   System.out.println("-----------------------");
  59.                   System.out.println("Here Are Your Two Cards");
  60.                   System.out.println("-----------------------");
  61.                   d.Deal();
  62.                   d.Deal();
  63.                   System.out.println("---------------------");
  64.                   System.out.println("Here Are My Two Cards");
  65.                   System.out.println("---------------------");
  66.                   d.CompDeal();
  67.                   d.CompDeal();
  68.                   System.out.println();
  69.                   System.out.println("Your Score is " + d.User);
  70.                   System.out.println();
  71.                   System.out.println("My Score is " + d.Comp);
  72.                   System.out.println();
  73.                   if (d.User > d.Comp)
  74.                   {
  75.                       System.out.println("You Won!");
  76.                   }
  77.                   else if (d.User == d.Comp)
  78.                   {
  79.                       System.out.println("It is a Tie!");
  80.                   }
  81.                   else if (d.User < d.Comp)
  82.                   {
  83.                       System.out.println("I Won!");
  84.                   }
  85.                   System.out.println();
  86.                   d.User=0;
  87.                   d.Comp=0;
  88.                   System.out.println("Wanna Play Again? (Yes: 1 / No: 2)");
  89.                   WAR=keyboard.nextInt();
  90.               }
  91.               d.ShowMenu();
  92.             break;
  93.            
  94.           case 5:
  95.               System.out.println("5");
  96.               menu=1;
  97.             break;
  98.           default: System.out.println("Sorry, That's Not Part Of the Menu. Select An Option From The Menu");
  99.         }
  100.         }
  101.         System.out.println("Thank You For Playing WAR!");
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement