Advertisement
ds84182

Deck

Apr 19th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.18 KB | None | 0 0
  1. package practice;
  2. import java.util.Scanner;
  3. import java.util.Random;
  4.  
  5.  
  6.  
  7. public class deck {
  8.    
  9.  
  10.    
  11.  
  12.    
  13.     Scanner scan = new Scanner(System.in);
  14.     Random rand = new Random();
  15.  
  16.     String[] cards = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
  17.     String[] suits = {" of Hearts", " of Diamonds", " of Spades", " of Clubs"};
  18.  
  19. String[][] deck = new String[suits.length][cards.length];
  20.  
  21.  
  22.  
  23.  
  24. public deck(){
  25.     int shuffleCards, shuffleSuits, playerPoints, dealerPoints, playerTotal, dealerTotal, wins, loses, pushes;
  26. showCard = "";
  27. playAgain = "y";
  28. score = "";
  29.  
  30. playerTotal = 0;
  31. playerPoints = 0;
  32. dealerPoints = 0;
  33. dealerTotal = 0;
  34.  
  35. wins = loses = pushes = 0;
  36.  
  37.  
  38.  
  39.  
  40.     System.out.print("Your cards: ");
  41.     for(int a=1; a<=3; a++)
  42.     {
  43.         shuffleCards = rand.nextInt(cards.length-1) + 0;
  44.         shuffleSuits = rand.nextInt(suits.length-1) + 0;
  45.  
  46.         shuffleCards = 0;
  47.         shuffleSuits = 0;
  48.  
  49.         selectedCard.append(cards[shuffleCards].concat(suits[shuffleSuits]));
  50.  
  51.             currentCard = cards[shuffleCards].concat(suits[shuffleSuits]);
  52.         System.out.println("current card" + currentCard);
  53.         checkCards.add(currentCard);
  54.        System.out.println("currentCard " + checkCards);
  55.         for(int x=0; x<checkCards.length; x++)
  56.         {
  57.            public getCard = (String) checkCards.get(x);
  58.  
  59.             if(currentCard.matches(selectedCard.toString()))
  60.             {
  61.                 shuffleCards = rand.nextInt(cards.length-1) + 0;
  62.                 shuffleSuits = rand.nextInt(suits.length-1) + 0;
  63.  
  64.                 System.out.println("That card was already selected");
  65.  
  66.             }
  67.  
  68.             System.out.println("getCard["+x+"] = " + (String) checkCards.get(x));
  69.         }
  70.  
  71.         System.out.println(cards[shuffleCards] + suits[shuffleSuits] );                        
  72.  
  73.         if(shuffleCards == 1)
  74.         {
  75.             playerPoints = 2;
  76.         }
  77.  
  78.         if(shuffleCards == 2)
  79.         {
  80.             playerPoints = 3;
  81.         }
  82.  
  83.         if(shuffleCards == 3)
  84.         {
  85.             playerPoints = 4;
  86.         }
  87.  
  88.         if(shuffleCards == 4)
  89.         {
  90.             playerPoints = 5;
  91.         }
  92.  
  93.         if(shuffleCards == 5)
  94.         {
  95.             playerPoints = 6;
  96.         }
  97.  
  98.         if(shuffleCards == 6)
  99.         {
  100.             playerPoints = 7;
  101.         }
  102.  
  103.         if(shuffleCards == 7)
  104.         {
  105.             playerPoints = 8;
  106.         }
  107.  
  108.         if(shuffleCards == 8)
  109.         {
  110.             playerPoints = 9;
  111.         }
  112.  
  113.         if(shuffleCards == 9 || shuffleCards == 10 || shuffleCards == 11 || shuffleCards == 12)
  114.         {
  115.             playerPoints = 10;
  116.         }
  117.  
  118.         if((shuffleCards == 10 && shuffleSuits == 2 )|| (shuffleCards == 10 && shuffleSuits == 0) || (shuffleCards == 12 && shuffleSuits == 1))
  119.         {
  120.             playerPoints = 13;
  121.         }
  122.  
  123.         if(shuffleCards == 2 && shuffleSuits == 3)
  124.         {
  125.             playerPoints = 0;
  126.         }
  127.  
  128.         if(shuffleCards == 0 && (playerTotal <= 22))
  129.         {
  130.             playerPoints = 11;
  131.         }
  132.  
  133.         if(shuffleCards == 0 && (playerTotal > 22))
  134.         {
  135.             playerPoints = 1;
  136.         }  
  137.  
  138.         playerTotal = playerPoints + playerTotal;
  139.  
  140.         showCard = showCard.concat(cards[shuffleCards]).concat(suits[shuffleSuits].concat(", "));
  141.     }
  142.  
  143.     System.out.println("(Total " + playerTotal );
  144.  
  145.     System.out.println();
  146.  
  147.     System.out.println("Would you like another card (Y/N)? ");
  148.     anotherCard = scan.nextLine();
  149.  
  150.     while(anotherCard.equalsIgnoreCase("y"))
  151.     {
  152.         System.out.println("Your cards: " + showCard);
  153.  
  154.         shuffleCards = rand.nextInt(cards.length-1) + 0;
  155.         shuffleSuits = rand.nextInt(suits.length-1) + 0;
  156.  
  157.  
  158.         if(shuffleCards == 1)
  159.         {
  160.             playerPoints = 2;
  161.         }
  162.  
  163.         if(shuffleCards == 2)
  164.         {
  165.             playerPoints = 3;
  166.         }
  167.  
  168.         if(shuffleCards == 3)
  169.         {
  170.             playerPoints = 4;
  171.         }
  172.  
  173.         if(shuffleCards == 4)
  174.         {
  175.             playerPoints = 5;
  176.         }
  177.  
  178.         if(shuffleCards == 5)
  179.         {
  180.             playerPoints = 6;
  181.         }
  182.  
  183.         if(shuffleCards == 6)
  184.         {
  185.             playerPoints = 7;
  186.         }
  187.  
  188.         if(shuffleCards == 7)
  189.         {
  190.             playerPoints = 8;
  191.         }
  192.  
  193.         if(shuffleCards == 8)
  194.         {
  195.             playerPoints = 9;
  196.         }
  197.  
  198.         if(shuffleCards == 9 || shuffleCards == 10 || shuffleCards == 11 || shuffleCards == 12)
  199.         {
  200.             playerPoints = 10;
  201.         }
  202.  
  203.         if(shuffleCards == 10 && shuffleSuits == 2 || shuffleCards == 10 && shuffleSuits == 0 || shuffleCards == 12 && shuffleSuits == 1)
  204.         {
  205.             playerPoints = 13;
  206.         }
  207.         if(shuffleCards ==11 && shuffleSuites ==1||3)
  208.             playerPoints = 13;
  209.         if(shuffleCards ==13 && shuffleSuites ==2)
  210.             playerPoints = 13;
  211.  
  212.         if(shuffleCards == 3 && shuffleSuits == 4)
  213.         {
  214.             playerPoints = 0;
  215.         }
  216.  
  217.         if(shuffleCards == 0 && (playerTotal <= 22))
  218.         {
  219.             playerPoints = 11;
  220.         }
  221.  
  222.         if(shuffleCards == 0 && (playerTotal > 22))
  223.         {
  224.             playerPoints = 1;
  225.         }  
  226.  
  227.         playerTotal = playerPoints + playerTotal;
  228.  
  229.         System.out.println("(Total " + playerTotal );
  230.  
  231.         System.out.println();
  232.  
  233.         System.out.println("Would you like another card (Y/N)? ");
  234.         anotherCard = scan.nextLine();
  235.     }            
  236.  
  237.     System.out.println();
  238.  
  239.     System.out.println("The dealer drew: ");
  240.  
  241.     while(dealerTotal <= 26)
  242.     {
  243.         shuffleCards = rand.nextInt(cards.length-1) + 0;
  244.         shuffleSuits = rand.nextInt(suits.length-1) + 0;
  245.  
  246.         if(shuffleCards == 1)
  247.         {
  248.             dealerPoints = 2;
  249.         }
  250.  
  251.         if(shuffleCards == 2)
  252.         {
  253.             dealerPoints = 3;
  254.         }
  255.  
  256.         if(shuffleCards == 3)
  257.         {
  258.             dealerPoints = 4;
  259.         }
  260.  
  261.         if(shuffleCards == 4)
  262.         {
  263.             dealerPoints = 5;
  264.         }
  265.  
  266.         if(shuffleCards == 5)
  267.         {
  268.             dealerPoints = 6;
  269.         }
  270.  
  271.         if(shuffleCards == 6)
  272.         {
  273.             dealerPoints = 7;
  274.         }
  275.  
  276.         if(shuffleCards == 7)
  277.         {
  278.             dealerPoints = 8;
  279.         }
  280.  
  281.         if(shuffleCards == 8)
  282.         {
  283.             dealerPoints = 9;
  284.         }
  285.  
  286.         if(shuffleCards == 9 || shuffleCards == 10 || shuffleCards == 11 || shuffleCards == 12)
  287.         {
  288.             dealerPoints = 10;
  289.         }
  290.  
  291.         if((shuffleCards == 10 && shuffleSuits == 2 )|| (shuffleCards == 10 && shuffleSuits == 0) || (shuffleCards == 12 && shuffleSuits == 1))
  292.         {
  293.             dealerPoints = 13;
  294.         }
  295.  
  296.         if(shuffleCards == 2 && shuffleSuits == 3)
  297.         {
  298.             dealerPoints = 0;
  299.         }
  300.  
  301.         if(shuffleCards == 0 && (dealerTotal <= 22))
  302.         {
  303.             dealerPoints = 11;
  304.         }
  305.  
  306.         if(shuffleCards == 0 && (dealerTotal > 22))
  307.         {
  308.             dealerPoints = 1;
  309.         }
  310.  
  311.         dealerTotal = dealerPoints + dealerTotal;
  312.  
  313.         System.out.println(cards[shuffleCards] + suits[shuffleSuits].concat(", "));    
  314.  
  315.     }
  316.  
  317.     System.out.println("(Total " + dealerTotal );
  318.  
  319.     System.out.println();
  320.  
  321.     if((33 - playerTotal < 33 - dealerTotal) && playerTotal <= 33 || dealerTotal > 33)
  322.     {
  323.        System.out.println("You win!");
  324.         wins++;
  325.     }
  326.  
  327.     if((33 - playerTotal > 33 - dealerTotal) && dealerTotal <= 33 || playerTotal > 33)
  328.     {
  329.         System.out.println("Sorry, you lose");
  330.         loses++;
  331.     }
  332.  
  333.     if(playerTotal == dealerTotal)
  334.     {
  335.         score = "tied!";                
  336.         pushes++;
  337.     }
  338.  
  339.     System.out.println("You " + score + " Current Total :Wins - " + wins + " Ties : " + pushes + " Loses : " + loses);
  340.  
  341.    
  342.     System.out.println();
  343.  
  344.  
  345.  
  346.     else System.out.println("Would you like to play again (Y/Q)? ");
  347.     playAgain = scan.nextLine();
  348.  
  349.     if(playAgain.equalsIgnoreCase("y"))
  350.     {
  351.         playerTotal = 0;
  352.         dealerTotal = 0;
  353.         playerPoints = 0;
  354.         dealerPoints = 0;
  355.    
  356.        
  357.  
  358.  
  359. }
  360. }
  361. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement