dwlakes

Untitled

Feb 5th, 2022
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 66.46 KB | None | 0 0
  1. package BlackJackGame;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.util.ArrayList;
  9. import java.util.Collections;
  10. import java.util.ListIterator;
  11. import java.util.Timer;
  12. import java.util.TimerTask;
  13. import java.util.concurrent.TimeUnit;
  14.  
  15. import javax.sound.sampled.AudioSystem;
  16. import javax.sound.sampled.Clip;
  17. import javax.sound.sampled.LineUnavailableException;
  18. import javax.sound.sampled.UnsupportedAudioFileException;
  19. import javax.swing.JTextField;
  20.  
  21. import javafx.application.Application;
  22. import javafx.scene.Group;
  23. import javafx.scene.Scene;
  24. import javafx.scene.control.Button;
  25. import javafx.scene.control.Label;
  26. import javafx.scene.control.Spinner;
  27. import javafx.scene.control.TextField;
  28. import javafx.scene.image.Image;
  29. import javafx.scene.image.ImageView;
  30. import javafx.scene.paint.Color;
  31. import javafx.scene.paint.ImagePattern;
  32. import javafx.scene.text.Font;
  33. import javafx.scene.text.FontPosture;
  34. import javafx.scene.text.FontWeight;
  35. import javafx.stage.Stage;
  36.  
  37. public class Game extends Application{
  38.     Label userCardHit1Label = new Label("");
  39.     Label userCardHit2Label = new Label("");
  40.     Label userCardHit3Label = new Label("");
  41.     Label userCardHit4Label = new Label("");
  42.     Label resultsLabel = new Label("");
  43.     Label dealerCardHit1Label = new Label("");
  44.     Label dealerCardHit2Label = new Label("");
  45.     Label dealerCardHit3Label = new Label("");
  46.     Label dealerCardHit4Label = new Label("");
  47.     Label userSplit1CardHit1Label = new Label("");
  48.     Label userSplit1CardHit2Label = new Label("");
  49.     Label userSplit1CardHit3Label = new Label("");
  50.     Label userSplit1CardHit4Label = new Label("");
  51.     Label userSplit2CardHit1Label = new Label("");
  52.     Label userSplit2CardHit2Label = new Label("");
  53.     Label userSplit2CardHit3Label = new Label("");
  54.     Label userSplit2CardHit4Label = new Label("");
  55.     Label currentBetLabel = new Label("");
  56.     Label gameOverLabel = new Label("");
  57.     Button btHit = new Button("Hit");
  58.     Button btRetry = new Button("Next Round");
  59.     Button btStand = new Button("Stand");
  60.     Button btnDouble = new Button("Double Down");
  61.     Button btnDoubleSplit1 = new Button ("Double Down" + '\n'+
  62.                                             "Split 1");
  63.     Button btnDoubleSplit2 = new Button ("Double Down" + '\n'+
  64.                                             "Split 2");
  65.     Button btnSplit = new Button("Split");
  66.     Button btnStandSplit1 = new Button ("Stand Split 1");
  67.     Button btnStandSplit2 = new Button ("Stand Split 2");
  68.     Button btnHitSplit1 = new Button("Hit Split 1");
  69.     Button btnHitSplit2 = new Button("Hit Split 2");
  70.     int resetCounter=0;
  71.     int bank = 1000;
  72.     Label bankLabel = new Label("");
  73.     Label bankLabel2 =new Label("");
  74.     Spinner<Integer> betSpinner = new Spinner<>(25, bank, 25, 25);
  75.     Button btnBet = new Button("Bet");
  76.     String bet;
  77.     boolean splitBoolean = false;
  78.     boolean split1Bust = false;
  79.     boolean split2Bust = false;
  80.     int split1Bet;
  81.     int split2Bet;
  82.     Label split1BetLabel = new Label("");
  83.     Label split2BetLabel = new Label("");
  84.    
  85.    
  86.  
  87.    
  88.     @Override
  89.     public void start(Stage primaryStage) throws Exception {
  90.        
  91.        
  92.         //Initializing the home/start screen
  93.         Image background= new Image(getClass().getResourceAsStream("PokerTable.jpeg"));
  94.         ImagePattern bgImage= new ImagePattern(background);
  95.         Image openImage = new Image(getClass().getResourceAsStream("IntroPic.jpeg"));
  96.         ImageView imgOpen =new ImageView(openImage);
  97.         imgOpen.setFitWidth(300);
  98.         imgOpen.setFitHeight(200);
  99.         imgOpen.setLayoutX(110);
  100.         imgOpen.setLayoutY(50);
  101.        
  102.         //Button to start the game
  103.         Button btPlay = new Button("Play");
  104.         btPlay.setLayoutX(230);
  105.         btPlay.setLayoutY(350);
  106.        
  107.          
  108.         Group rootOpen= new Group(imgOpen,btPlay);
  109.         Scene scene = new Scene(rootOpen, 535,500);
  110.         scene.setFill(bgImage);
  111.         primaryStage.setScene(scene);
  112.         primaryStage.show();
  113.        
  114.          
  115.          //Listens for click on button play
  116.            btPlay.setOnAction(e -> {
  117.             try {
  118.                 mainGame(primaryStage);
  119.             } catch (FileNotFoundException e1) {
  120.                 // TODO Auto-generated catch block
  121.                 e1.printStackTrace();
  122.             }
  123.         });
  124.        
  125.     }
  126.    
  127.    
  128.    
  129.         //mainGame method essentially allows for restarting the game without going back to the home screen
  130.         void mainGame(Stage primaryStage) throws FileNotFoundException{
  131.            
  132.             //dec shuffle sound effect
  133.             File file = new File("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/Shuffle.wav");
  134.             Clip shuffle = null;
  135.             try {
  136.                 shuffle = AudioSystem.getClip();
  137.             } catch (LineUnavailableException e) {
  138.                 // TODO Auto-generated catch block
  139.                 e.printStackTrace();
  140.             }  
  141.             try {
  142.                 shuffle.open(AudioSystem.getAudioInputStream(file));
  143.             } catch (LineUnavailableException e) {
  144.                 // TODO Auto-generated catch block
  145.                 e.printStackTrace();
  146.             } catch (IOException e) {
  147.                 // TODO Auto-generated catch block
  148.                 e.printStackTrace();
  149.             } catch (UnsupportedAudioFileException e) {
  150.                 // TODO Auto-generated catch block
  151.                 e.printStackTrace();
  152.             }
  153.             shuffle.start();
  154.            
  155.             //Sets up betting scene
  156.            
  157.            
  158.         //Creates an image for the back of the card
  159.         InputStream imageBackStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/BackSide.png");
  160.         Image imageBack = new Image(imageBackStream);
  161.         //ImageView imageView4 = new ImageView(imageBack);
  162.        
  163.         //Creating card objects (spades) in chronological order
  164.         Card twoSpade = new Card(2, 0, "Spade", null, null, null);
  165.         InputStream twoSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/2Spade.png");
  166.         Image twoSpadeImage = new Image (twoSpadeStream);
  167.         twoSpade.image=twoSpadeImage;
  168.         twoSpade.imageBack=imageBack;
  169.        
  170.         Card threeSpade = new Card(3, 0, "Spade", null, null, null);
  171.         InputStream threeSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/3Spade.png");
  172.         Image threeSpadeImage = new Image (threeSpadeStream);
  173.         threeSpade.image=threeSpadeImage;
  174.         threeSpade.imageBack=imageBack;
  175.        
  176.         Card fourSpade = new Card(4, 0, "Spade", null, null,null);
  177.         InputStream fourSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/4Spade.png");
  178.         Image fourSpadeImage = new Image (fourSpadeStream);
  179.         fourSpade.image=fourSpadeImage;
  180.         fourSpade.imageBack=imageBack;
  181.        
  182.         Card fiveSpade = new Card(5, 0, "Spade", null, null,null);
  183.         InputStream fiveSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/5Spade.png");
  184.         Image fiveSpadeImage = new Image (fiveSpadeStream);
  185.         fiveSpade.image=fiveSpadeImage;
  186.         fiveSpade.imageBack=imageBack;
  187.        
  188.         Card sixSpade = new Card(6, 0, "Spade", null, null,null);
  189.         InputStream sixSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/6Spade.png");
  190.         Image sixSpadeImage = new Image (sixSpadeStream);
  191.         sixSpade.image=sixSpadeImage;
  192.         sixSpade.imageBack=imageBack;
  193.        
  194.         Card sevenSpade = new Card(7, 0, "Spade", null, null,null);
  195.         InputStream sevenSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/7Spade.png");
  196.         Image sevenSpadeImage = new Image (sevenSpadeStream);
  197.         sevenSpade.image=sevenSpadeImage;
  198.         sevenSpade.imageBack=imageBack;
  199.        
  200.         Card eightSpade = new Card(8, 0, "Spade", null, null,null);
  201.         InputStream eightSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/8Spade.png");
  202.         Image eightSpadeImage = new Image (eightSpadeStream);
  203.         eightSpade.image=eightSpadeImage;
  204.         eightSpade.imageBack=imageBack;
  205.        
  206.         Card nineSpade = new Card(9, 0, "Spade", null, null,null);
  207.         InputStream nineSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/9Spade.png");
  208.         Image nineSpadeImage = new Image (nineSpadeStream);
  209.         nineSpade.image=nineSpadeImage;
  210.         nineSpade.imageBack=imageBack;
  211.        
  212.         Card tenSpade = new Card(10, 0, "Spade", null, null,null);
  213.         InputStream tenSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/10Spade.png");
  214.         Image tenSpadeImage = new Image (tenSpadeStream);
  215.         tenSpade.image=tenSpadeImage;
  216.         tenSpade.imageBack=imageBack;
  217.        
  218.         Card jackSpade = new Card(10, 0, "Spade","Jack", null, null);
  219.         InputStream jackSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/JackSpade.png");
  220.         Image jackSpadeImage = new Image (jackSpadeStream);
  221.         jackSpade.image=jackSpadeImage;
  222.         jackSpade.imageBack=imageBack;
  223.        
  224.         Card queenSpade = new Card(10, 0, "Spade","Queen", null, null);
  225.         InputStream queenSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/QueenSpade.png");
  226.         Image queenSpadeImage = new Image (queenSpadeStream);
  227.         queenSpade.image=queenSpadeImage;
  228.         queenSpade.imageBack=imageBack;
  229.        
  230.         Card kingSpade = new Card(10, 0, "Spade", "King", null, null);
  231.         InputStream kingSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/KingSpade.png");
  232.         Image kingSpadeImage = new Image (kingSpadeStream);
  233.         kingSpade.image=kingSpadeImage;
  234.         kingSpade.imageBack=imageBack;
  235.        
  236.         Card aceSpade = new Card(11, 1, "Spade", "Ace", null, null);
  237.         InputStream aceSpadeStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/AceSpade.png");
  238.         Image aceSpadeImage = new Image (aceSpadeStream);
  239.         aceSpade.image=aceSpadeImage;
  240.         aceSpade.imageBack=imageBack;
  241.        
  242.         //Creating clubs in chronological order
  243.        
  244.         Card twoClub = new Card(2, 0, "Club", null, null, null);
  245.         InputStream twoClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/2Club.png");
  246.         Image twoClubImage = new Image (twoClubStream);
  247.         twoClub.image=twoClubImage;
  248.         twoClub.imageBack=imageBack;
  249.        
  250.         Card threeClub = new Card(3, 0, "Club", null, null, null);
  251.         InputStream threeClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/3Club.png");
  252.         Image threeClubImage = new Image (threeClubStream);
  253.         threeClub.image=threeClubImage;
  254.         threeClub.imageBack=imageBack;
  255.        
  256.         Card fourClub = new Card(4, 0, "Club", null, null,null);
  257.         InputStream fourClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/4Club.png");
  258.         Image fourClubImage = new Image (fourClubStream);
  259.         fourClub.image=fourClubImage;
  260.         fourClub.imageBack=imageBack;
  261.        
  262.         Card fiveClub = new Card(5, 0, "Club", null, null,null);
  263.         InputStream fiveClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/5Club.png");
  264.         Image fiveClubImage = new Image (fiveClubStream);
  265.         fiveClub.image=fiveClubImage;
  266.         fiveClub.imageBack=imageBack;
  267.        
  268.         Card sixClub = new Card(6, 0, "Club", null, null,null);
  269.         InputStream sixClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/6Club.png");
  270.         Image sixClubImage = new Image (sixClubStream);
  271.         sixClub.image=sixClubImage;
  272.         sixClub.imageBack=imageBack;
  273.        
  274.         Card sevenClub = new Card(7, 0, "Club", null, null,null);
  275.         InputStream sevenClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/7Club.png");
  276.         Image sevenClubImage = new Image (sevenClubStream);
  277.         sevenClub.image=sevenClubImage;
  278.         sevenClub.imageBack=imageBack;
  279.        
  280.         Card eightClub = new Card(8, 0, "Club", null, null,null);
  281.         InputStream eightClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/8Club.png");
  282.         Image eightClubImage = new Image (eightClubStream);
  283.         eightClub.image=eightClubImage;
  284.         eightClub.imageBack=imageBack;
  285.        
  286.         Card nineClub = new Card(9, 0, "Club", null, null,null);
  287.         InputStream nineClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/9Club.png");
  288.         Image nineClubImage = new Image (nineClubStream);
  289.         nineClub.image=nineClubImage;
  290.         nineClub.imageBack=imageBack;
  291.        
  292.         Card tenClub = new Card(10, 0, "Club", null, null,null);
  293.         InputStream tenClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/10Club.png");
  294.         Image tenClubImage = new Image (tenClubStream);
  295.         tenClub.image=tenClubImage;
  296.         tenClub.imageBack=imageBack;
  297.        
  298.         Card jackClub = new Card(10, 0, "Club","Jack", null, null);
  299.         InputStream jackClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/JackClub.png");
  300.         Image jackClubImage = new Image (jackClubStream);
  301.         jackClub.image=jackClubImage;
  302.         jackClub.imageBack=imageBack;
  303.        
  304.         Card queenClub = new Card(10, 0, "Club","Queen", null, null);
  305.         InputStream queenClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/QueenClub.png");
  306.         Image queenClubImage = new Image (queenClubStream);
  307.         queenClub.image=queenClubImage;
  308.         queenClub.imageBack=imageBack;
  309.        
  310.         Card kingClub = new Card(10, 0, "Club", "King", null, null);
  311.         InputStream kingClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/KingClub.png");
  312.         Image kingClubImage = new Image (kingClubStream);
  313.         kingClub.image=kingClubImage;
  314.         kingClub.imageBack=imageBack;
  315.        
  316.         Card aceClub = new Card(11, 1, "Club", "Ace", null, null);
  317.         InputStream aceClubStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/AceClub.png");
  318.         Image aceClubImage = new Image (aceClubStream);
  319.         aceClub.image=aceClubImage;
  320.         aceClub.imageBack=imageBack;
  321.        
  322.        
  323.         //Creating cards in hearts
  324.        
  325.         Card twoHeart = new Card(2, 0, "Heart", null, null, null);
  326.         InputStream twoHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/2Heart.png");
  327.         Image twoHeartImage = new Image (twoHeartStream);
  328.         twoHeart.image=twoHeartImage;
  329.         twoHeart.imageBack=imageBack;
  330.        
  331.         Card threeHeart = new Card(3, 0, "Heart", null, null, null);
  332.         InputStream threeHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/3Heart.png");
  333.         Image threeHeartImage = new Image (threeHeartStream);
  334.         threeHeart.image=threeHeartImage;
  335.         threeHeart.imageBack=imageBack;
  336.        
  337.         Card fourHeart = new Card(4, 0, "Heart", null, null,null);
  338.         InputStream fourHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/4Heart.png");
  339.         Image fourHeartImage = new Image (fourHeartStream);
  340.         fourHeart.image=fourHeartImage;
  341.         fourHeart.imageBack=imageBack;
  342.        
  343.         Card fiveHeart = new Card(5, 0, "Heart", null, null,null);
  344.         InputStream fiveHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/5Heart.png");
  345.         Image fiveHeartImage = new Image (fiveHeartStream);
  346.         fiveHeart.image=fiveHeartImage;
  347.         fiveHeart.imageBack=imageBack;
  348.        
  349.         Card sixHeart = new Card(6, 0, "Heart", null, null,null);
  350.         InputStream sixHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/6Heart.png");
  351.         Image sixHeartImage = new Image (sixHeartStream);
  352.         sixHeart.image=sixHeartImage;
  353.         sixHeart.imageBack=imageBack;
  354.        
  355.         Card sevenHeart = new Card(7, 0, "Heart", null, null,null);
  356.         InputStream sevenHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/7Heart.png");
  357.         Image sevenHeartImage = new Image (sevenHeartStream);
  358.         sevenHeart.image=sevenHeartImage;
  359.         sevenHeart.imageBack=imageBack;
  360.        
  361.         Card eightHeart = new Card(8, 0, "Heart", null, null,null);
  362.         InputStream eightHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/8Heart.png");
  363.         Image eightHeartImage = new Image (eightHeartStream);
  364.         eightHeart.image=eightHeartImage;
  365.         eightHeart.imageBack=imageBack;
  366.        
  367.         Card nineHeart = new Card(9, 0, "Heart", null, null,null);
  368.         InputStream nineHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/9Heart.png");
  369.         Image nineHeartImage = new Image (nineHeartStream);
  370.         nineHeart.image=nineHeartImage;
  371.         nineHeart.imageBack=imageBack;
  372.        
  373.         Card tenHeart = new Card(10, 0, "Heart", null, null,null);
  374.         InputStream tenHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/10Heart.png");
  375.         Image tenHeartImage = new Image (tenHeartStream);
  376.         tenHeart.image=tenHeartImage;
  377.         tenHeart.imageBack=imageBack;
  378.        
  379.         Card jackHeart = new Card(10, 0, "Heart","Jack", null, null);
  380.         InputStream jackHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/JackHeart.png");
  381.         Image jackHeartImage = new Image (jackHeartStream);
  382.         jackHeart.image=jackHeartImage;
  383.         jackHeart.imageBack=imageBack;
  384.        
  385.         Card queenHeart = new Card(10, 0, "Heart","Queen", null, null);
  386.         InputStream queenHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/QueenHeart.png");
  387.         Image queenHeartImage = new Image (queenHeartStream);
  388.         queenHeart.image=queenHeartImage;
  389.         queenHeart.imageBack=imageBack;
  390.        
  391.         Card kingHeart = new Card(10, 0, "Heart", "King", null, null);
  392.         InputStream kingHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/KingHeart.png");
  393.         Image kingHeartImage = new Image (kingHeartStream);
  394.         kingHeart.image=kingHeartImage;
  395.         kingHeart.imageBack=imageBack;
  396.        
  397.         Card aceHeart = new Card(11, 1, "Heart", "Ace", null, null);
  398.         InputStream aceHeartStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/AceHeart.png");
  399.         Image aceHeartImage = new Image (aceHeartStream);
  400.         aceHeart.image=aceHeartImage;
  401.         aceHeart.imageBack=imageBack;
  402.        
  403.        
  404.        
  405.         //Creating cards in diamonds
  406.         Card twoDiamond = new Card(2, 0, "Diamond ", null, null, null);
  407.         InputStream twoDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/2Diamond.png");
  408.         Image twoDiamondImage = new Image (twoDiamondStream);
  409.         twoDiamond.image=twoDiamondImage;
  410.         twoDiamond.imageBack=imageBack;
  411.        
  412.         Card threeDiamond = new Card(3, 0, "Diamond", null, null, null);
  413.         InputStream threeDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/3Diamond.png");
  414.         Image threeDiamondImage = new Image (threeDiamondStream);
  415.         threeDiamond.image=threeDiamondImage;
  416.         threeDiamond.imageBack=imageBack;
  417.        
  418.         Card fourDiamond = new Card(4, 0, "Diamond", null, null,null);
  419.         InputStream fourDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/4Diamond.png");
  420.         Image fourDiamondImage = new Image (fourDiamondStream);
  421.         fourDiamond.image=fourDiamondImage;
  422.         fourDiamond.imageBack=imageBack;
  423.        
  424.         Card fiveDiamond = new Card(5, 0, "Diamond", null, null,null);
  425.         InputStream fiveDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/5Diamond.png");
  426.         Image fiveDiamondImage = new Image (fiveDiamondStream);
  427.         fiveDiamond.image=fiveDiamondImage;
  428.         fiveDiamond.imageBack=imageBack;
  429.        
  430.         Card sixDiamond = new Card(6, 0, "Diamond", null, null,null);
  431.         InputStream sixDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/6Diamond.png");
  432.         Image sixDiamondImage = new Image (sixDiamondStream);
  433.         sixDiamond.image=sixDiamondImage;
  434.         sixDiamond.imageBack=imageBack;
  435.        
  436.         Card sevenDiamond = new Card(7, 0, "Diamond", null, null,null);
  437.         InputStream sevenDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/7Diamond.png");
  438.         Image sevenDiamondImage = new Image (sevenDiamondStream);
  439.         sevenDiamond.image=sevenDiamondImage;
  440.         sevenDiamond.imageBack=imageBack;
  441.        
  442.         Card eightDiamond = new Card(8, 0, "Diamond", null, null,null);
  443.         InputStream eightDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/8Diamond.png");
  444.         Image eightDiamondImage = new Image (eightDiamondStream);
  445.         eightDiamond.image=eightDiamondImage;
  446.         eightDiamond.imageBack=imageBack;
  447.        
  448.         Card nineDiamond = new Card(9, 0, "Diamond", null, null,null);
  449.         InputStream nineDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/9Diamond.png");
  450.         Image nineDiamondImage = new Image (nineDiamondStream);
  451.         nineDiamond.image=nineDiamondImage;
  452.         nineDiamond.imageBack=imageBack;
  453.        
  454.         Card tenDiamond = new Card(10, 0, "Diamond", null, null,null);
  455.         InputStream tenDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/10Diamond.png");
  456.         Image tenDiamondImage = new Image (tenDiamondStream);
  457.         tenDiamond.image=tenDiamondImage;
  458.         tenDiamond.imageBack=imageBack;
  459.        
  460.         Card jackDiamond = new Card(10, 0, "Diamond","Jack", null, null);
  461.         InputStream jackDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/JackDiamond.png");
  462.         Image jackDiamondImage = new Image (jackDiamondStream);
  463.         jackDiamond.image=jackDiamondImage;
  464.         jackDiamond.imageBack=imageBack;
  465.        
  466.         Card queenDiamond = new Card(10, 0, "Diamond","Queen", null, null);
  467.         InputStream queenDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/QueenDiamond.png");
  468.         Image queenDiamondImage = new Image (queenDiamondStream);
  469.         queenDiamond.image=queenDiamondImage;
  470.         queenDiamond.imageBack=imageBack;
  471.        
  472.         Card kingDiamond = new Card(10, 0, "Diamond", "King", null, null);
  473.         InputStream kingDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/KingDiamond.png");
  474.         Image kingDiamondImage = new Image (kingDiamondStream);
  475.         kingDiamond.image=kingDiamondImage;
  476.         kingDiamond.imageBack=imageBack;
  477.        
  478.         Card aceDiamond = new Card(11, 1, "Diamond", "Ace", null, null);
  479.         InputStream aceDiamondStream = new FileInputStream("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/AceDiamond.png");
  480.         Image aceDiamondImage = new Image (aceDiamondStream);
  481.         aceDiamond.image=aceDiamondImage;
  482.         aceDiamond.imageBack=imageBack;
  483.        
  484.         //Creating an array list for the cards
  485.         ArrayList<Card> deckArray = new ArrayList<Card>();
  486.         Collections.addAll(deckArray, twoSpade, threeSpade, fourSpade, fiveSpade, sixSpade, sevenSpade, eightSpade, nineSpade, tenSpade,
  487.                 jackSpade, queenSpade, kingSpade, aceSpade,
  488.                 twoClub, threeClub, fourClub, fiveClub, sixClub, sevenClub, eightClub, nineClub, tenClub,
  489.                 jackClub, queenClub, kingClub, aceClub,
  490.                 twoHeart, threeHeart, fourHeart, fiveHeart, sixHeart, sevenHeart, eightHeart, nineHeart, tenHeart,
  491.                 jackHeart, queenHeart, kingHeart, aceHeart,
  492.                 twoDiamond, threeDiamond, fourDiamond, fiveDiamond, sixDiamond, sevenDiamond, eightDiamond, nineDiamond, tenDiamond,
  493.                 jackDiamond, queenDiamond, kingDiamond, aceDiamond);
  494.        
  495.         Collections.shuffle(deckArray);
  496.        
  497.         //Creates an iterator to go through the deck
  498.         ListIterator<Card> iterator= deckArray.listIterator();
  499.        
  500.         //Creates arraylists for the hand of the user and dealer
  501.         ArrayList<Card>userHandArray= new ArrayList<Card>();
  502.         ArrayList<Card>dealerHandArray= new ArrayList<Card>();
  503.         ArrayList<Card>userHandSplit1Array= new ArrayList<Card>();
  504.         ArrayList<Card>userHandSplit2Array= new ArrayList<Card>();
  505.        
  506.        
  507.         userHandArray.add(iterator.next());
  508.         iterator.next();
  509.         dealerHandArray.add(iterator.next());
  510.         iterator.next();
  511.         userHandArray.add(iterator.next());
  512.         iterator.next();
  513.         dealerHandArray.add(iterator.next());
  514.        
  515.         //Creats an object to hold the cards and points of the dealer and user
  516.         Hand userHand = new Hand(0, null);
  517.         Hand dealerHand = new Hand(0, null);
  518.         Hand userHandSplit1 = new Hand(0,null);
  519.         Hand userHandSplit2 = new Hand(0,null);
  520.        
  521.         //initaliaztes hand arrays
  522.         userHand.handArray=userHandArray;
  523.         dealerHand.handArray=dealerHandArray;
  524.        
  525.        
  526.         //Clones the first card card of the userHand's array
  527.         try {
  528.             Card split1Card1 = (Card)userHand.handArray.get(0).clone();
  529.             userHandSplit1Array.add(split1Card1);
  530.         } catch (CloneNotSupportedException e2) {
  531.             // TODO Auto-generated catch block
  532.             e2.printStackTrace();
  533.         }
  534.         //Clones the second card card of the userHand's array
  535.         try {
  536.             Card split2Card1 = (Card)userHand.handArray.get(1).clone();
  537.             userHandSplit2Array.add(split2Card1);
  538.         } catch (CloneNotSupportedException e2) {
  539.             // TODO Auto-generated catch block
  540.             e2.printStackTrace();
  541.         }
  542.        
  543.         //adds the clones to their respective split hands (first clone goes to first split, second clone to second split)
  544.         userHandSplit1.handArray=userHandSplit1Array;
  545.         userHandSplit2.handArray=userHandSplit2Array;
  546.        
  547.         System.out.println("Dealer hand size " +dealerHand.handArray.size());
  548.        
  549.        
  550.         //Creates image view
  551.         ImageView imageView = new ImageView(userHand.handArray.get(0).image);
  552.         ImageView imageView2 = new ImageView(userHand.handArray.get(1).image);
  553.         ImageView imageView3 = new ImageView(dealerHand.handArray.get(0).image);
  554.         ImageView imageView4 = new ImageView(dealerHand.handArray.get(1).imageBack);
  555.         //ImageView bgImage = new ImageView(backgroundImage);
  556.        
  557.        
  558.         //Layouts for images and buttons
  559.         imageView.setPreserveRatio(true);
  560.         imageView.setFitWidth(100);
  561.         imageView.setFitHeight(100);      
  562.         imageView.setX(200);
  563.         imageView.setY(300);
  564.         imageView.setVisible(false);
  565.        
  566.         imageView2.setX(225);
  567.         imageView2.setY(300);
  568.         imageView2.setPreserveRatio(true);
  569.         imageView2.setFitWidth(100);
  570.         imageView2.setFitHeight(100);
  571.         imageView2.setVisible(false);
  572.  
  573.        
  574.         imageView3.setX(200);
  575.         imageView3.setY(100);
  576.         imageView3.setPreserveRatio(true);
  577.         imageView3.setFitWidth(100);
  578.         imageView3.setFitHeight(100);
  579.         imageView3.setVisible(false);
  580.  
  581.  
  582.         imageView4.setX(225);
  583.         imageView4.setY(100);
  584.         imageView4.setPreserveRatio(true);
  585.         imageView4.setFitWidth(100);
  586.         imageView4.setFitHeight(100);
  587.         imageView4.setVisible(false);
  588.  
  589.        
  590.         //button layouts
  591.         btHit.setVisible(false);
  592.         btHit.setLayoutX(10);
  593.         btHit.setLayoutY(450);
  594.        
  595.         btnSplit.setVisible(false);
  596.         btnSplit.setLayoutX(50);
  597.         btnSplit.setLayoutY(450);
  598.        
  599.         btnHitSplit1.setVisible(false);
  600.         btnHitSplit1.setLayoutX(10);
  601.         btnHitSplit1.setLayoutY(370);
  602.        
  603.         btnHitSplit2.setVisible(false);
  604.         btnHitSplit2.setLayoutX(85);
  605.         btnHitSplit2.setLayoutY(370);
  606.        
  607.         btnStandSplit1.setVisible(false);
  608.         btnStandSplit1.setLayoutX(10);
  609.         btnStandSplit1.setLayoutY(335);
  610.        
  611.         btnStandSplit2.setVisible(false);
  612.         btnStandSplit2.setLayoutX(100);
  613.         btnStandSplit2.setLayoutY(335);
  614.        
  615.         btnDoubleSplit1.setVisible(false);
  616.         btnDoubleSplit1.setLayoutX(10);
  617.         btnDoubleSplit1.setLayoutY(285);
  618.        
  619.         btnDoubleSplit2.setVisible(false);
  620.         btnDoubleSplit2.setLayoutX(110);
  621.         btnDoubleSplit2.setLayoutY(285);
  622.        
  623.         split2BetLabel.setVisible(true);
  624.         split2BetLabel.setLayoutX(10);
  625.         split2BetLabel.setLayoutY(265);
  626.         split2BetLabel.setFont(Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 16));
  627.         split2BetLabel.setTextFill(Color.BEIGE);
  628.        
  629.         split1BetLabel.setVisible(true);
  630.         split1BetLabel.setLayoutX(10);
  631.         split1BetLabel.setLayoutY(245);
  632.         split1BetLabel.setFont(Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 16));
  633.         split1BetLabel.setTextFill(Color.BEIGE);
  634.        
  635.         btRetry.setVisible(false);
  636.         btRetry.setLayoutX(100);
  637.         btRetry.setLayoutY(450);
  638.        
  639.         btStand.setVisible(false);
  640.         btStand.setLayoutX(190);
  641.         btStand.setLayoutY(450);
  642.        
  643.         btnDouble.setVisible(false);
  644.         btnDouble.setLayoutX(250);
  645.         btnDouble.setLayoutY(450);
  646.        
  647.        
  648.         gameOverLabel.setVisible(false);
  649.         gameOverLabel.setLayoutX(177);
  650.         gameOverLabel.setLayoutY(250);
  651.         gameOverLabel.setFont(Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 20));
  652.         gameOverLabel.setTextFill(Color.BEIGE);
  653.        
  654.         resultsLabel.setLayoutX(350);
  655.         resultsLabel.setLayoutY(450);
  656.         resultsLabel.setFont(Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 20));
  657.         resultsLabel.setTextFill(Color.BEIGE);
  658.        
  659.        
  660.         //hit cards labels layout
  661.         userCardHit1Label.setLayoutX(147);
  662.         userCardHit1Label.setLayoutY(25);
  663.         userCardHit2Label.setLayoutX(162);
  664.         userCardHit2Label.setLayoutY(25);
  665.         userCardHit3Label.setLayoutX(177);
  666.         userCardHit3Label.setLayoutY(25);
  667.         userCardHit4Label.setLayoutX(192);
  668.         userCardHit4Label.setLayoutY(25);
  669.         dealerCardHit1Label.setLayoutX(147);
  670.         dealerCardHit1Label.setLayoutY(25);
  671.         dealerCardHit2Label.setLayoutX(162);
  672.         dealerCardHit2Label.setLayoutY(25);
  673.         dealerCardHit3Label.setLayoutX(177);
  674.         dealerCardHit3Label.setLayoutY(25);
  675.         dealerCardHit4Label.setLayoutX(192);
  676.         dealerCardHit4Label.setLayoutY(25);
  677.         betSpinner.setLayoutX(190);
  678.         betSpinner.setLayoutY(210);
  679.         btnBet.setLayoutX(230);
  680.         btnBet.setLayoutY(275);
  681.         currentBetLabel.setLayoutX(10);
  682.         currentBetLabel.setLayoutY(425);
  683.         currentBetLabel.setFont(Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 20));
  684.         currentBetLabel.setTextFill(Color.BEIGE);
  685.         bankLabel.setLayoutX(10);
  686.         bankLabel.setLayoutY(400);
  687.         bankLabel.setFont(Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 20));
  688.         bankLabel.setTextFill(Color.BEIGE);
  689.         bankLabel2.setLayoutX(10);
  690.         bankLabel2.setLayoutY(400);
  691.         bankLabel2.setFont(Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 20));
  692.         bankLabel2.setTextFill(Color.BEIGE);
  693.        
  694.        
  695.        
  696.        //Sets up background image
  697.        
  698.         Image background= new Image(getClass().getResourceAsStream("PokerTable.jpeg"));
  699.           ImagePattern bgImage= new ImagePattern(background);
  700.         //Creating main part
  701.         //adding elements to window
  702.        
  703.         Group root = new Group (imageView, imageView2,imageView3,imageView4,btHit,btRetry,userCardHit1Label,
  704.                 userCardHit2Label,userCardHit3Label,userCardHit4Label,btStand,dealerCardHit1Label,dealerCardHit2Label,
  705.                 dealerCardHit3Label,dealerCardHit4Label,resultsLabel, currentBetLabel,bankLabel2,gameOverLabel,btnDouble,btnSplit,
  706.                 userSplit1CardHit1Label,userSplit1CardHit2Label,userSplit1CardHit3Label,userSplit1CardHit4Label,btnHitSplit1,btnHitSplit2,
  707.                 btnStandSplit1,btnStandSplit2,userSplit2CardHit1Label,userSplit2CardHit2Label,userSplit2CardHit3Label,
  708.                 userSplit2CardHit4Label,btnDoubleSplit1,btnDoubleSplit2,split2BetLabel,split1BetLabel);
  709.          //root.getChildren().add(cardHit1Label);
  710.         Scene scene1 = new Scene(root, 535,500);
  711.         bankLabel.setText("Bank: $"+bank);
  712.         Group preRoot = new Group(btnBet,betSpinner,bankLabel);
  713.         Scene preScene = new Scene(preRoot,535,500);
  714.    
  715.         preScene.setFill(bgImage);
  716.         scene1.setFill(bgImage);
  717.         primaryStage.setScene(preScene);
  718.         primaryStage.show();
  719.         btnBet.setOnAction(e -> {
  720.             bet = betSpinner.getValue().toString();
  721.             int betInt = Integer.parseInt(bet);
  722.             bank = bank-betInt;
  723.             currentBetLabel.setText("Current bet: $"+bet);
  724.             bankLabel2.setText("Bank: $"+bank);
  725.             //calls the method to do the initial dealing of the game
  726.             initialDealMethod(imageView,imageView2,imageView3,imageView4,userHand);
  727.            
  728.             //launches scene of main game
  729.            
  730.         primaryStage.setScene(scene1);
  731.     });
  732.         //resets the button
  733.         btRetry.setText("Next Round");
  734.        
  735.         //Checks for user and dealer Black Jack
  736.         if ((userHand.handArray.get(0).type==("Ace")&&userHand.handArray.get(1).value==10)||
  737.                 (userHand.handArray.get(1).type==("Ace")&&userHand.handArray.get(0).value==10)) {
  738.             if((dealerHand.handArray.get(0).type==("Ace")&&dealerHand.handArray.get(1).value==10)||
  739.                     (dealerHand.handArray.get(1).type==("Ace")&&dealerHand.handArray.get(0).value==10)) {
  740.                 resultsLabel.setText("Dealer and user" +'\n' + "Black Jack. Tie!");
  741.                 imageView4.setImage(dealerHand.handArray.get(1).image);
  742.                 btStand.setDisable(true);
  743.                 btHit.setDisable(true);
  744.                 btRetry.setVisible(true);
  745.                 btnDouble.setDisable(true);
  746.             }else {
  747.                 resultsLabel.setText("User Black Jack!");
  748.                 imageView4.setImage(dealerHand.handArray.get(1).image);
  749.                 btStand.setDisable(true);
  750.                 btHit.setDisable(true);
  751.                 btRetry.setVisible(true);
  752.                 btnDouble.setDisable(true);
  753.                 //Adds user win to bank
  754.                 userWin();
  755.             }
  756.        
  757.                
  758.             //Checks for dealer Black Jack for win
  759.         }else if ((dealerHand.handArray.get(0).type==("Ace")&&dealerHand.handArray.get(1).value==10)||
  760.                 (dealerHand.handArray.get(1).type==("Ace")&&dealerHand.handArray.get(0).value==10)){
  761.         resultsLabel.setText("Dealer Black Jack!" +'\n' + "You lose!");
  762.         imageView4.setImage(dealerHand.handArray.get(1).image);
  763.         btHit.setDisable(true);
  764.         btRetry.setVisible(true);
  765.         btStand.setDisable(true);
  766.         btnDouble.setDisable(false);
  767.         imageView4.setImage(dealerHand.handArray.get(1).image);
  768.         userLose(userHand,dealerHand,primaryStage);
  769.    
  770.         }
  771.        
  772.      
  773.        
  774.         //methdod and hit button action to hit hand
  775.         btHit.setOnAction(e -> userHit(iterator,userHand,dealerHand,imageView4));
  776.         //User ends turn by standing
  777.         btStand.setOnAction(e -> stand(iterator,userHand,dealerHand,userHandSplit1,userHandSplit2,imageView4,primaryStage));
  778.         //User doubles their bet if they want, but only as their first move
  779.         btnDouble.setOnAction(e ->{
  780.             int betInt = Integer.parseInt(bet);
  781.             bank=bank-betInt;
  782.             bankLabel2.setText("Bank: $"+bank);
  783.             betInt=betInt*2;
  784.             bet = String.valueOf(betInt);
  785.             currentBetLabel.setText("Current bet: $"+betInt);
  786.             userHit(iterator,userHand,dealerHand,imageView4);
  787.             if(userHand.points>21) {
  788.                 imageView4.setImage(dealerHand.handArray.get(1).image);
  789.                 resultsLabel.setText("Bust");
  790.                 btHit.setDisable(true);
  791.                 btRetry.setVisible(true);
  792.                 userHand.handArray.removeAll(userHand.handArray);
  793.                 btStand.setDisable(true);
  794.                 btHit.setDisable(true);
  795.                 btRetry.setVisible(true);
  796.                 btnDouble.setDisable(true);
  797.                 userLose(userHand,dealerHand,primaryStage);
  798.                
  799.             }else {
  800.             imageView4.setImage(dealerHand.handArray.get(1).image);
  801.             System.out.println("Dealer hand size after double down " +dealerHand.handArray.size());
  802.             stand(iterator,userHand,userHandSplit1,userHandSplit2,dealerHand,imageView4,primaryStage);
  803.             btnDouble.setDisable(true);
  804.             }
  805.            
  806.         });
  807.        
  808.         btnSplit.setOnAction(e -> {
  809.             btnHitSplit1.setDisable(false);
  810.             btnStandSplit1.setDisable(false);
  811.             btStand.setDisable(true);
  812.             splitBoolean=true;
  813.             imageView.setY(240);
  814.             imageView2.setX(200);
  815.             imageView2.setY(340);
  816.             split1Hit(userHandSplit1,iterator,userHand,dealerHand,primaryStage);
  817.             split2Hit(userHandSplit2,userHandSplit1,iterator,userHand,dealerHand,primaryStage,imageView4);
  818.             btnSplit.setDisable(true);
  819.             btHit.setDisable(true);
  820.             btnDouble.setDisable(true);
  821.             btnDoubleSplit1.setVisible(true);
  822.             btnDoubleSplit1.setDisable(false);
  823.             bank -=Integer.parseInt(bet);
  824.             bankLabel2.setText("Bank: $"+bank);
  825.             split1Bet = Integer.parseInt(bet);
  826.             split2Bet = Integer.parseInt(bet);
  827.             System.out.println("Split 1 bet " + split1Bet);
  828.             System.out.println("Split 2 bet " + split2Bet);
  829.             currentBetLabel.setText("Initial bet: $" + bet );
  830.             split2BetLabel.setText("Split 2 bet: $"+split2Bet);
  831.             split1BetLabel.setText("Split 1 bet: $"+split1Bet);
  832.            
  833.         });
  834.         //button to double down on split 1
  835.         btnDoubleSplit1.setOnAction(e ->{
  836.             btnStandSplit1.setDisable(true);
  837.             btnDoubleSplit1.setDisable(true);
  838.             btnHitSplit1.setDisable(true);
  839.             btnHitSplit2.setDisable(false);
  840.             btnStandSplit2.setDisable(false);
  841.             btnDoubleSplit2.setDisable(false);
  842.             split1Hit(userHandSplit1,iterator,userHand,dealerHand,primaryStage);
  843.             bank -= split1Bet;
  844.             split1Bet = split1Bet *2;
  845.             bankLabel2.setText("Bank: $"+bank);
  846.             split1BetLabel.setText("Split 1 bet: $"+split1Bet);
  847.            
  848.         });
  849.        
  850.         btnDoubleSplit2.setOnAction(e ->{
  851.             btnStandSplit2.setDisable(true);
  852.             btnDoubleSplit2.setDisable(true);
  853.             btnHitSplit2.setDisable(true);
  854.             btnHitSplit2.setDisable(true);
  855.             btnStandSplit2.setDisable(true);
  856.             btnDoubleSplit2.setDisable(true);
  857.             split2Hit(userHandSplit2,userHandSplit1,iterator,userHand,dealerHand,primaryStage, imageView4);
  858.             bank -= split2Bet;
  859.             split2Bet = split2Bet *2;
  860.             bankLabel2.setText("Bank: $"+bank);
  861.             split2BetLabel.setText("Split 1 bet: $"+split2Bet);
  862.            
  863.         });
  864.        
  865.         //hit split one
  866.         btnHitSplit1.setOnAction(e ->{
  867.             btnDoubleSplit1.setDisable(true);
  868.             split1Hit(userHandSplit1,iterator,userHand,dealerHand,primaryStage);
  869.         });
  870.        
  871.         btnHitSplit2.setOnAction(e ->{
  872.             split2Hit(userHandSplit2,userHandSplit1,iterator,userHand,dealerHand,primaryStage, imageView4);
  873.         });
  874.        
  875.         btnStandSplit1.setOnAction(e -> {
  876.             btnStandSplit1.setDisable(true);
  877.             btnHitSplit1.setDisable(true);
  878.             btnStandSplit2.setDisable(false);
  879.             btnHitSplit2.setDisable(false);
  880.             btnDoubleSplit1.setDisable(true);
  881.             btnDoubleSplit2.setDisable(false);
  882.            
  883.            
  884.         });
  885.        
  886.         btnStandSplit2.setOnAction(e -> {
  887.             btnStandSplit1.setDisable(true);
  888.             btnHitSplit1.setDisable(true);
  889.             btnStandSplit2.setDisable(true);
  890.             btnHitSplit2.setDisable(true);
  891.             btnDoubleSplit2.setDisable(true);
  892.             stand(iterator,userHand,dealerHand,userHandSplit1,userHandSplit2,imageView4,primaryStage);
  893.            
  894.         });
  895.        
  896.        
  897.        
  898.        
  899.         //Resets game
  900.         btRetry.setOnAction(e -> {
  901.             count = 0;
  902.            
  903.             try {
  904.                
  905.                 userCardHit1Label.setGraphic(null);
  906.                 userCardHit2Label.setGraphic(null);
  907.                 userCardHit3Label.setGraphic(null);
  908.                 userCardHit4Label.setGraphic(null);
  909.                 dealerCardHit1Label.setGraphic(null);
  910.                 dealerCardHit2Label.setGraphic(null);
  911.                 dealerCardHit3Label.setGraphic(null);
  912.                 dealerCardHit4Label.setGraphic(null);
  913.                 userSplit1CardHit1Label.setGraphic(null);
  914.                 userSplit1CardHit2Label.setGraphic(null);
  915.                 userSplit1CardHit3Label.setGraphic(null);
  916.                 userSplit1CardHit4Label.setGraphic(null);
  917.                 userSplit2CardHit1Label.setGraphic(null);
  918.                 userSplit2CardHit2Label.setGraphic(null);
  919.                 userSplit2CardHit3Label.setGraphic(null);
  920.                 userSplit2CardHit4Label.setGraphic(null);
  921.                 split2BetLabel.setText("");
  922.                 split1BetLabel.setText("");
  923.                 resultsLabel.setText("");
  924.                 btHit.setDisable(false);
  925.                 btStand.setDisable(false);
  926.                 btRetry.setVisible(false);
  927.                 btnDouble.setDisable(false);
  928.                 userHand.points=0;
  929.                 userHand.handArray.removeAll(userHand.handArray);
  930.                 dealerHand.points=0;
  931.                 dealerHand.handArray.removeAll(userHand.handArray);
  932.                 userHandSplit1.points=0;
  933.                 userHandSplit1.handArray.removeAll(userHand.handArray);
  934.                 userHandSplit2.points=0;
  935.                 userHandSplit2.handArray.removeAll(userHand.handArray);
  936.                 dealerCount =2;
  937.                 count =2;
  938.                 split1Count=1;
  939.                 split2Count =1;
  940.                 split1Bust = false;
  941.                 split2Bust = false;
  942.                 splitBoolean = false;
  943.                 mainGame(primaryStage);
  944.                
  945.             } catch (Exception e1) {
  946.                 // TODO Auto-generated catch block
  947.                 e1.printStackTrace();
  948.             }
  949.         });
  950.    
  951.         }
  952.  
  953.  
  954.  
  955.    
  956.     //adds user's bet bank to bank
  957.     public void tie() {
  958.             int betInt = Integer.parseInt(bet);
  959.             bank= bank+betInt;
  960.         }
  961.     //Adds user win to bank
  962.     public void userWin() {
  963.         int betInt = Integer.parseInt(bet);
  964.         bank = bank + (betInt*2);
  965.            
  966.         }
  967.     //checks to see if the user runs out of money
  968.     public void userLose(Hand userHand, Hand dealerHand, Stage primaryStage) {
  969.         if (bank<1) {
  970.             //btRetry.setVisible(false);
  971.             btHit.setVisible(false);
  972.             btStand.setVisible(false);
  973.             gameOverLabel.setVisible(true);
  974.             btnDouble.setVisible(false);
  975.             gameOverLabel.setText("You went broke! Try again?");
  976.             //btnNewGame.setVisible(true);
  977.             bank = 1000;
  978.             btRetry.setText("New Game?");
  979.                 count = 0;
  980.                
  981.         }
  982.     }
  983.  
  984.  
  985.  
  986.     //deals cards
  987.     private void initialDealMethod(ImageView imageView, ImageView imageView2, ImageView imageView3, ImageView imageView4, Hand userHand) {
  988.         shuffleSound();
  989.         Timer timer = new Timer();
  990.            timer.schedule(new TimerTask() {
  991.                //first loop keeps any card from being dealt
  992.             @Override
  993.             public void run() {
  994.                 hitSound();
  995.                 imageView.setVisible(true);
  996.                 timer.schedule(new TimerTask() {
  997.  
  998.                 @Override
  999.                     public void run() {
  1000.                         hitSound();
  1001.                         imageView3.setVisible(true);
  1002.                         timer.schedule(new TimerTask() {
  1003.  
  1004.                 @Override
  1005.                         public void run() {
  1006.                             hitSound();
  1007.                             imageView2.setVisible(true);
  1008.                             timer.schedule(new TimerTask() {
  1009.  
  1010.                 @Override
  1011.                             public void run() {
  1012.                                 hitSound();
  1013.                                 imageView4.setVisible(true);
  1014.                                 timer.schedule(new TimerTask() {
  1015.  
  1016.                     @Override
  1017.                                 public void run() {
  1018.                                     btStand.setVisible(true);
  1019.                                     btHit.setVisible(true);
  1020.                                     btnDouble.setVisible(true);
  1021.                                     btnSplit.setVisible(true);
  1022.                                     btnSplit.setDisable(true);
  1023.                                     btnHitSplit1.setVisible(true);
  1024.                                     btnHitSplit2.setVisible(true);
  1025.                                     btnHitSplit1.setDisable(true);
  1026.                                     btnHitSplit2.setDisable(true);
  1027.                                     btnStandSplit1.setVisible(true);
  1028.                                     btnStandSplit1.setDisable(true);
  1029.                                     btnStandSplit2.setVisible(true);
  1030.                                     btnStandSplit2.setDisable(true);
  1031.                                     btnDoubleSplit1.setVisible(true);
  1032.                                     btnDoubleSplit1.setDisable(true);
  1033.                                     btnDoubleSplit2.setVisible(true);
  1034.                                     btnDoubleSplit2.setDisable(true);
  1035.                                    
  1036.                                     if (userHand.handArray.get(0).type==userHand.handArray.get(1).type &&
  1037.                                             userHand.handArray.get(0).value==userHand.handArray.get(1).value) {
  1038.                                         btnSplit.setDisable(false);
  1039.                                     }
  1040.                                    
  1041.                                    
  1042.                                 }
  1043.                        
  1044.                                 }, 500);
  1045.                                
  1046.                             }
  1047.                    
  1048.                             }, 500);
  1049.                            
  1050.                         }
  1051.                    
  1052.                         }, 500);
  1053.          
  1054.                     }
  1055.                    
  1056.                     }, 500);
  1057.            
  1058.             }
  1059.                
  1060.            }, 500);
  1061.            
  1062.         }
  1063.  
  1064.  
  1065.  
  1066.     private void shuffleSound() {
  1067.         //dec shuffle sound effect
  1068.         File file = new File("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/Shuffle.wav");
  1069.         Clip shuffle = null;
  1070.         try {
  1071.             shuffle = AudioSystem.getClip();
  1072.         } catch (LineUnavailableException e) {
  1073.             // TODO Auto-generated catch block
  1074.             e.printStackTrace();
  1075.         }  
  1076.         try {
  1077.             shuffle.open(AudioSystem.getAudioInputStream(file));
  1078.         } catch (LineUnavailableException e) {
  1079.             // TODO Auto-generated catch block
  1080.             e.printStackTrace();
  1081.         } catch (IOException e) {
  1082.             // TODO Auto-generated catch block
  1083.             e.printStackTrace();
  1084.         } catch (UnsupportedAudioFileException e) {
  1085.             // TODO Auto-generated catch block
  1086.             e.printStackTrace();
  1087.         }
  1088.         shuffle.start();       
  1089.     }
  1090.  
  1091.  
  1092.  
  1093.     private void stand(ListIterator<Card> iterator, Hand userHand, Hand dealerHand,
  1094.             Hand userHandSplit1, Hand userHandSplit2, ImageView imageView4, Stage primaryStage) {
  1095.        
  1096.         imageView4.setImage(dealerHand.handArray.get(1).image);
  1097.        
  1098.         btnDoubleSplit2.setDisable(true);
  1099.        
  1100.         //In case the user's first move was to stand, is user's hand is calculated again
  1101.         userHand.points= 0;
  1102.         boolean ace = false;
  1103.         for(int i = 0; i < userHand.handArray.size(); i++) {
  1104.            
  1105.            
  1106.            
  1107.             if(userHand.handArray.get(i).type=="Ace") {
  1108.                 ace = true;
  1109.             }
  1110.        
  1111.             userHand.points += userHand.handArray.get(i).value;;
  1112.            
  1113.             //if the hand breaks 21 and has an ace, the ace value is reassigned to one and the
  1114.             //hand points value is recalculated
  1115.             if (userHand.points>21 && ace==true) {
  1116.                 userHand.points = 0;
  1117.                 for( i = 0; i < userHand.handArray.size(); i++) {
  1118.                     if(userHand.handArray.get(i).type=="Ace") {
  1119.                         userHand.handArray.get(i).value=userHand.handArray.get(i).otherValue;
  1120.                        
  1121.                        
  1122.                     }userHand.points += userHand.handArray.get(i).value;
  1123.                 }
  1124.            
  1125.             }
  1126.            
  1127.        
  1128.             if (userHand.points>21) {
  1129.                 imageView4.setImage(dealerHand.handArray.get(1).image);
  1130.                 resultsLabel.setText("Bust");
  1131.                 btHit.setDisable(true);
  1132.                 btRetry.setVisible(true);
  1133.                 userHand.handArray.removeAll(userHand.handArray);
  1134.                 btStand.setDisable(true);
  1135.                 btHit.setDisable(true);
  1136.                 btRetry.setVisible(true);
  1137.                 btnDouble.setDisable(true);
  1138.                 userLose(userHand,dealerHand,primaryStage);
  1139.             }
  1140.        
  1141.         }
  1142.        
  1143.         //calls the hit sound sound effect
  1144.         hitSound();
  1145.         //btHit.setDisable(true);
  1146.         System.out.println("Dealer hand array size after play :"+ dealerHand.handArray.size());
  1147.         //imageView4.setImage(dealerHand.handArray.get(1).image);
  1148.            
  1149.         dealerHand.points = 0;
  1150.         for(int i = 0; i < dealerHand.handArray.size(); i++) {
  1151.             //Tells the dealer what to do and it's resulting consequences ie hitting
  1152.             dealerHand.points+=dealerHand.handArray.get(i).value;
  1153.             }
  1154.             //Determines if the dealer needs a hit or not  
  1155.        
  1156.         while (dealerHand.points<17) {
  1157.                
  1158.            
  1159.             dealerHit(dealerHand,iterator, userHand,imageView4);
  1160.            
  1161.                
  1162.             }
  1163.         //imageView4.setImage(dealerHand.handArray.get(1).image);
  1164.        
  1165.         if (splitBoolean == true ) {
  1166.             if (split1Bust==false && split2Bust == false) {
  1167.                 if(userHandSplit1.points>dealerHand.points && userHandSplit2.points>dealerHand.points && dealerHand.points<22) {
  1168.                     resultsLabel.setText("Split 1 and 2 win!");
  1169.                     btHit.setDisable(true);
  1170.                     btRetry.setVisible(true);
  1171.                     btStand.setDisable(true);
  1172.                     btnDouble.setDisable(true);
  1173.                     btnDoubleSplit2.setDisable(true);
  1174.                     split1Win();
  1175.                     split2Win();
  1176.                    
  1177.                 }else if(userHandSplit1.points<dealerHand.points && userHandSplit2.points>dealerHand.points && dealerHand.points<22) {
  1178.                     resultsLabel.setText("Split 1 loses!" + '\n'+
  1179.                                             "Split 2 wins!");
  1180.                     btHit.setDisable(true);
  1181.                     btRetry.setVisible(true);
  1182.                     btStand.setDisable(true);
  1183.                     btnDouble.setDisable(true);
  1184.                     btnDoubleSplit2.setDisable(true);
  1185.                     split2Win();
  1186.                     userLose(userHand,dealerHand,primaryStage);
  1187.                 }else if(userHandSplit1.points>dealerHand.points && userHandSplit2.points<dealerHand.points && dealerHand.points<22) {
  1188.                     resultsLabel.setText("Split 1 wins!" + '\n'+
  1189.                             "Split 2 loses!");
  1190.                     btHit.setDisable(true);
  1191.                     btRetry.setVisible(true);
  1192.                     btStand.setDisable(true);
  1193.                     btnDouble.setDisable(true);
  1194.                     btnDoubleSplit2.setDisable(true);
  1195.                     split1Win();
  1196.                     userLose(userHand,dealerHand,primaryStage);
  1197.                 }else if(userHandSplit1.points<dealerHand.points && userHandSplit2.points<dealerHand.points && dealerHand.points<22) {
  1198.                     resultsLabel.setText("Split 1 and 2 lose!");
  1199.                     btHit.setDisable(true);
  1200.                     btRetry.setVisible(true);
  1201.                     btStand.setDisable(true);
  1202.                     btnDouble.setDisable(true);
  1203.                     btnDoubleSplit2.setDisable(true);
  1204.                     userLose(userHand,dealerHand,primaryStage);
  1205.                 }else if (dealerHand.points>21) {
  1206.                     resultsLabel.setText("Dealer Bust");
  1207.                     btHit.setDisable(true);
  1208.                     btStand.setDisable(true);
  1209.                     btRetry.setVisible(true);
  1210.                     btnDouble.setDisable(true);
  1211.                     btnDoubleSplit2.setDisable(true);
  1212.                     //Adds the user win to bank
  1213.                     split1Win();
  1214.                     split2Win();
  1215.                 }else if(userHandSplit1.points>dealerHand.points && userHandSplit2.points==dealerHand.points && dealerHand.points<22) {
  1216.                     resultsLabel.setText("Split 1 wins!" + '\n'+
  1217.                             "Split 2 ties!");
  1218.                     btHit.setDisable(true);
  1219.                     btRetry.setVisible(true);
  1220.                     btStand.setDisable(true);
  1221.                     btnDouble.setDisable(true);
  1222.                     btnDoubleSplit2.setDisable(true);
  1223.                     split1Win();
  1224.                     split2Tie();
  1225.                 }else if(userHandSplit1.points==dealerHand.points && userHandSplit2.points>dealerHand.points && dealerHand.points<22) {
  1226.                     resultsLabel.setText("Split 1 ties!" + '\n'+
  1227.                             "Split 2 wins!");
  1228.                     btHit.setDisable(true);
  1229.                     btRetry.setVisible(true);
  1230.                     btStand.setDisable(true);
  1231.                     btnDouble.setDisable(true);
  1232.                     btnDoubleSplit2.setDisable(true);
  1233.                     split1Tie();
  1234.                     split2Win();
  1235.                 }else if(userHandSplit1.points==dealerHand.points && userHandSplit2.points<dealerHand.points && dealerHand.points<22) {
  1236.                     resultsLabel.setText("Split 1 ties!" + '\n'+
  1237.                             "Split 2 loses!");
  1238.                     btHit.setDisable(true);
  1239.                     btRetry.setVisible(true);
  1240.                     btStand.setDisable(true);
  1241.                     btnDouble.setDisable(true);
  1242.                     btnDoubleSplit2.setDisable(true);
  1243.                     split1Tie();
  1244.                     userLose(userHand,dealerHand,primaryStage);
  1245.                 }else if(userHandSplit1.points<dealerHand.points && userHandSplit2.points==dealerHand.points && dealerHand.points<22) {
  1246.                     resultsLabel.setText("Split 1 loses!" + '\n'+
  1247.                             "Split 2 ties!");
  1248.                     btHit.setDisable(true);
  1249.                     btRetry.setVisible(true);
  1250.                     btStand.setDisable(true);
  1251.                     btnDouble.setDisable(true);
  1252.                     btnDoubleSplit2.setDisable(true);
  1253.                     split2Tie();
  1254.                     userLose(userHand,dealerHand,primaryStage);
  1255.                 }else if(userHandSplit1.points==dealerHand.points && userHandSplit2.points==dealerHand.points && dealerHand.points<22) {
  1256.                     resultsLabel.setText("Split 1 ties!" + '\n'+
  1257.                             "Split 2 ties!");
  1258.                     btHit.setDisable(true);
  1259.                     btRetry.setVisible(true);
  1260.                     btStand.setDisable(true);
  1261.                     btnDouble.setDisable(true);
  1262.                     btnDoubleSplit2.setDisable(true);
  1263.                     split2Tie();
  1264.                     split1Tie();
  1265.                 }
  1266.                
  1267.             }else if (split1Bust == false && split2Bust == true) {
  1268.                 if(userHandSplit1.points<dealerHand.points && dealerHand.points<22) {
  1269.                     resultsLabel.setText("Dealer wins");
  1270.                     btHit.setDisable(true);
  1271.                     btRetry.setVisible(true);
  1272.                     btStand.setDisable(true);
  1273.                     btnDouble.setDisable(true);
  1274.                     btnDoubleSplit2.setDisable(true);
  1275.                     userLose(userHand,dealerHand,primaryStage);
  1276.                 }else if(userHandSplit1.points>dealerHand.points) {
  1277.                     resultsLabel.setText("Split 1 wins!" + '\n'+
  1278.                             "Split 2 bust!");
  1279.                     btHit.setDisable(true);
  1280.                     btRetry.setVisible(true);
  1281.                     btStand.setDisable(true);
  1282.                     btnDouble.setDisable(true);
  1283.                     btnDoubleSplit2.setDisable(true);
  1284.                     split1Win();
  1285.                    
  1286.                 }else if(dealerHand.points==userHandSplit1.points) {
  1287.                     resultsLabel.setText("Split 1 ties!" + '\n'+
  1288.                             "Split 2 bust!");
  1289.                     btHit.setDisable(true);
  1290.                     btRetry.setVisible(true);
  1291.                     btStand.setDisable(true);
  1292.                     btnDouble.setDisable(true);
  1293.                     btnDoubleSplit2.setDisable(true);
  1294.                     //adds user's bet back to hand
  1295.                     split1Tie();
  1296.                    
  1297.                 }else if (dealerHand.points>21) {
  1298.                     resultsLabel.setText("Split 1 wins!" + '\n'+
  1299.                             "Dealer Bust");
  1300.                     btHit.setDisable(true);
  1301.                     btStand.setDisable(true);
  1302.                     btRetry.setVisible(true);
  1303.                     btnDouble.setDisable(true);
  1304.                     btnDoubleSplit2.setDisable(true);
  1305.                     //Adds the user win to bank
  1306.                     split1Win();
  1307.                
  1308.                 }
  1309.             }else if (split2Bust == false && split1Bust == true) {
  1310.                 if(userHandSplit2.points<dealerHand.points && dealerHand.points<22) {
  1311.                     resultsLabel.setText("Split 1 bust!" + '\n'+
  1312.                             "Split 2 loses!");
  1313.                     btHit.setDisable(true);
  1314.                     btRetry.setVisible(true);
  1315.                     btStand.setDisable(true);
  1316.                     btnDouble.setDisable(true);
  1317.                     btnDoubleSplit2.setDisable(true);
  1318.                     userLose(userHand,dealerHand,primaryStage);
  1319.                 }else if(userHandSplit2.points>dealerHand.points) {
  1320.                     resultsLabel.setText("Split 2 wins!" + '\n'+
  1321.                             "Split 1 bust!");
  1322.                     btHit.setDisable(true);
  1323.                     btRetry.setVisible(true);
  1324.                     btStand.setDisable(true);
  1325.                     btnDouble.setDisable(true);
  1326.                     btnDoubleSplit2.setDisable(true);
  1327.                     split2Win();
  1328.                    
  1329.                 }else if(dealerHand.points==userHandSplit2.points) {
  1330.                     resultsLabel.setText("Split 2 ties!" + '\n'+
  1331.                             "Split 1 bust!");
  1332.                     btHit.setDisable(true);
  1333.                     btRetry.setVisible(true);
  1334.                     btStand.setDisable(true);
  1335.                     btnDouble.setDisable(true);
  1336.                     btnDoubleSplit2.setDisable(true);
  1337.                     //adds user's bet back to hand
  1338.                     split2Tie();
  1339.                    
  1340.                 }else if (dealerHand.points>21) {
  1341.                     resultsLabel.setText("Split 2 wins!" + '\n'+
  1342.                             "Dealer Bust");
  1343.                     btHit.setDisable(true);
  1344.                     btStand.setDisable(true);
  1345.                     btRetry.setVisible(true);
  1346.                     btnDouble.setDisable(true);
  1347.                     btnDoubleSplit2.setDisable(true);
  1348.                     //Adds the user win to bank
  1349.                     split2Win();
  1350.                
  1351.                 }
  1352.                
  1353.             }
  1354.         //This line of codes determines if the dealer wins with just their two initial cards
  1355.         }else if(userHand.points<dealerHand.points && dealerHand.points<22) {
  1356.             resultsLabel.setText("Dealer wins");
  1357.             btHit.setDisable(true);
  1358.             btRetry.setVisible(true);
  1359.             btStand.setDisable(true);
  1360.             btnDouble.setDisable(true);
  1361.             btnDoubleSplit2.setDisable(true);
  1362.         }else if(userHand.points>dealerHand.points) {
  1363.             resultsLabel.setText("Player wins");
  1364.             btHit.setDisable(true);
  1365.             btRetry.setVisible(true);
  1366.             btStand.setDisable(true);
  1367.             btnDouble.setDisable(true);
  1368.             btnDoubleSplit2.setDisable(true);
  1369.             userWin();
  1370.            
  1371.         }else if(dealerHand.points==userHand.points) {
  1372.             imageView4.setImage(dealerHand.handArray.get(1).image);
  1373.             resultsLabel.setText("Tie");
  1374.             btHit.setDisable(true);
  1375.             btRetry.setVisible(true);
  1376.             btStand.setDisable(true);
  1377.             btnDouble.setDisable(true);
  1378.             btnDoubleSplit2.setDisable(true);
  1379.             //adds user's bet back to hand
  1380.             tie();
  1381.            
  1382.         }else if (dealerHand.points>21) {
  1383.             imageView4.setImage(dealerHand.handArray.get(1).image);
  1384.             resultsLabel.setText("Dealer Bust");
  1385.             btHit.setDisable(true);
  1386.             btStand.setDisable(true);
  1387.             btRetry.setVisible(true);
  1388.             btnDouble.setDisable(true);
  1389.             btnDoubleSplit2.setDisable(true);
  1390.             //Adds the user win to bank
  1391.             userWin();
  1392.            
  1393.            
  1394.        
  1395.        
  1396.            
  1397.         }
  1398.     }      
  1399.  
  1400.  
  1401.                
  1402.  
  1403. private void split1Tie() {
  1404.     bank = bank + split1Bet;       
  1405.     }
  1406.  
  1407.  
  1408.  
  1409. private void split2Tie() {
  1410.     bank = bank + split2Bet;   
  1411.     }
  1412.  
  1413.  
  1414.  
  1415. private void split2Win() {
  1416.     bank = bank + (split2Bet*2);
  1417.        
  1418.     }
  1419.  
  1420.  
  1421.  
  1422. private void split1Win() {
  1423.     bank = bank + (split1Bet*2);
  1424.        
  1425.     }
  1426.  
  1427.  
  1428.  
  1429.  
  1430. int dealerCount=2;
  1431.     //Determines the consequences of a dealer hit
  1432.     private int dealerHit(Hand dealerHand, ListIterator<Card> iterator, Hand userHand, ImageView imageView4) {
  1433.         //imageView4.setImage(dealerHand.handArray.get(1).image);
  1434.    
  1435.         //adds card to userhand
  1436.         dealerHand.handArray.add(iterator.next());
  1437.         hitSound();
  1438.    
  1439.         //imageView4.setImage(dealerHand.handArray.get(1).image);                  
  1440.     //adds dealer hit cards
  1441.     if (dealerCount==2) {
  1442.          
  1443.            
  1444.         ImageView dealerCardHit1 =new ImageView(dealerHand.handArray.get(dealerCount).image);
  1445.          
  1446.        
  1447.         dealerCardHit1Label.setGraphic(dealerCardHit1);
  1448.         dealerCardHit1Label.setLayoutX(105);
  1449.         dealerCardHit1Label.setLayoutY(-114);
  1450.         dealerCardHit1Label.setScaleX(.2);
  1451.         dealerCardHit1Label.setScaleY(.19);
  1452.         dealerCount++; 
  1453.        
  1454.  
  1455.     }else if(dealerCount == 3) {
  1456.        
  1457.         ImageView dealerCardHit2 =new ImageView(dealerHand.handArray.get(dealerCount).image);
  1458.  
  1459.         dealerCardHit2Label.setGraphic(dealerCardHit2);
  1460.         dealerCardHit2Label.setTranslateX(-35);
  1461.         dealerCardHit2Label.setTranslateY(-140);
  1462.         dealerCardHit2Label.setScaleX(.2);
  1463.         dealerCardHit2Label.setScaleY(.19);
  1464.         dealerCount++;                         
  1465.                
  1466.                    
  1467.            
  1468.        
  1469.     }else if(dealerCount == 4) {
  1470.        
  1471.         hitSound();
  1472.         ImageView dealerCardHit3 =new ImageView(dealerHand.handArray.get(dealerCount).image);
  1473.  
  1474.         dealerCardHit3Label.setGraphic(dealerCardHit3);
  1475.         dealerCardHit3Label.setTranslateX(-25);
  1476.         dealerCardHit3Label.setTranslateY(-140);
  1477.         dealerCardHit3Label.setScaleX(.2);
  1478.         dealerCardHit3Label.setScaleY(.19);
  1479.         dealerCount++; 
  1480.                    
  1481.        
  1482.        
  1483.    
  1484.     }else if (dealerCount ==5) {
  1485.        
  1486.         ImageView dealerCardHit4 =new ImageView(dealerHand.handArray.get(dealerCount).image);
  1487.  
  1488.         dealerCardHit4Label.setGraphic(dealerCardHit4);
  1489.         dealerCardHit4Label.setTranslateX(-35);
  1490.         dealerCardHit4Label.setTranslateY(-140);
  1491.         dealerCardHit4Label.setScaleX(.2);
  1492.         dealerCardHit4Label.setScaleY(.19);
  1493.         dealerCount++; 
  1494.                    
  1495.             }
  1496.                        
  1497.            
  1498.             //Adds up the userHand points
  1499.             dealerHand.points= 0;
  1500.             boolean ace = false;
  1501.             for(int i = 0; i < dealerHand.handArray.size(); i++) {
  1502.                
  1503.                
  1504.                 //Checks dealer hand for an ace
  1505.                 if(dealerHand.handArray.get(i).type=="Ace") {
  1506.                     ace = true;
  1507.                 }
  1508.            
  1509.                 dealerHand.points += dealerHand.handArray.get(i).value;
  1510.                
  1511.                 //if the hand breaks 21 and has an ace, the ace value is reassigned to one and the
  1512.                 //hand points value is recalculated
  1513.                 if (dealerHand.points>21 && ace==true) {
  1514.                     dealerHand.points = 0;
  1515.                     for( i = 0; i < dealerHand.handArray.size(); i++) {
  1516.                         if(dealerHand.handArray.get(i).type=="Ace") {
  1517.                             dealerHand.handArray.get(i).value=dealerHand.handArray.get(i).otherValue;
  1518.                            
  1519.                            
  1520.                         }
  1521.                         dealerHand.points += dealerHand.handArray.get(i).value;
  1522.                     }
  1523.                
  1524.                 }
  1525.            
  1526.              
  1527.             }
  1528.                
  1529.             return dealerHand.points;  
  1530.            
  1531.                
  1532.                 }
  1533.     int split2Count =1;
  1534.     private void split2Hit(Hand userHandSplit2, Hand userHandSplit1, ListIterator<Card> iterator, Hand userHand, Hand dealerHand,
  1535.             Stage primaryStage, ImageView imageView4) {
  1536.         hitSound();
  1537.         userHandSplit2.handArray.add(iterator.next());
  1538.        
  1539.         if (split2Count==1) {
  1540.             ImageView userSplit2CardHit1 =new ImageView(userHandSplit2.handArray.get(split2Count).image);
  1541.        
  1542.             userSplit2CardHit1Label.setGraphic(userSplit2CardHit1);
  1543.             userSplit2CardHit1Label.setTranslateX(85);
  1544.             userSplit2CardHit1Label.setTranslateY(127);
  1545.             userSplit2CardHit1Label.setScaleX(.2);
  1546.             userSplit2CardHit1Label.setScaleY(.19);
  1547.             split2Count++;
  1548.         }else if (split2Count==2) {
  1549.             ImageView userSplit2CardHit1 =new ImageView(userHandSplit2.handArray.get(split2Count).image);
  1550.        
  1551.             userSplit2CardHit2Label.setGraphic(userSplit2CardHit1);
  1552.             userSplit2CardHit2Label.setTranslateX(108);
  1553.             userSplit2CardHit2Label.setTranslateY(127);
  1554.             userSplit2CardHit2Label.setScaleX(.2);
  1555.             userSplit2CardHit2Label.setScaleY(.19);
  1556.             split2Count++;
  1557.         }else if (split2Count==3) {
  1558.             ImageView userSplit2CardHit1 =new ImageView(userHandSplit2.handArray.get(split2Count).image);
  1559.        
  1560.             userSplit2CardHit3Label.setGraphic(userSplit2CardHit1);
  1561.             userSplit2CardHit3Label.setTranslateX(131);
  1562.             userSplit2CardHit3Label.setTranslateY(127);
  1563.             userSplit2CardHit3Label.setScaleX(.2);
  1564.             userSplit2CardHit3Label.setScaleY(.19);
  1565.             split2Count++;
  1566.         }else if (split2Count==4) {
  1567.             ImageView userSplit2CardHit1 =new ImageView(userHandSplit2.handArray.get(split2Count).image);
  1568.        
  1569.             userSplit2CardHit4Label.setGraphic(userSplit2CardHit1);
  1570.             userSplit2CardHit4Label.setTranslateX(154);
  1571.             userSplit2CardHit4Label.setTranslateY(127);
  1572.             userSplit2CardHit4Label.setScaleX(.2);
  1573.             userSplit2CardHit4Label.setScaleY(.19);
  1574.             split1Count++;
  1575.            
  1576.         }
  1577.         userHandSplit2.points= 0;
  1578.             boolean ace = false;
  1579.             for(int i = 0; i < userHandSplit2.handArray.size(); i++) {
  1580.                
  1581.                
  1582.                
  1583.                 if(userHandSplit2.handArray.get(i).type=="Ace") {  
  1584.                 }
  1585.            
  1586.                 userHandSplit2.points += userHandSplit2.handArray.get(i).value;;
  1587.                
  1588.                 //if the hand breaks 21 and has an ace, the ace value is reassigned to one and the
  1589.                 //hand points value is recalculated
  1590.                 if (userHandSplit2.points>21 && ace==true) {
  1591.                     userHandSplit2.points = 0;
  1592.                     for( i = 0; i < userHandSplit2.handArray.size(); i++) {
  1593.                         if(userHandSplit2.handArray.get(i).type=="Ace") {
  1594.                             userHandSplit2.handArray.get(i).value=userHandSplit2.handArray.get(i).otherValue;
  1595.                            
  1596.                            
  1597.                         }userHandSplit2.points += userHandSplit2.handArray.get(i).value;
  1598.                     }
  1599.                
  1600.                 }
  1601.            
  1602.                 if (userHandSplit2.points>21) {
  1603.                     resultsLabel.setText("Split 2 Bust");
  1604.                     split2Bust = true;
  1605.                     btnHitSplit1.setDisable(true);
  1606.                     btnStandSplit1.setDisable(true);
  1607.                     btnHitSplit2.setDisable(true);
  1608.                     btnStandSplit2.setDisable(true);
  1609.                     userLose(userHand,dealerHand,primaryStage);
  1610.                     if(split1Bust == true) {
  1611.                         resultsLabel.setText("Split 1 and 2 bust!");
  1612.                         btHit.setDisable(true);
  1613.                         btRetry.setVisible(true);
  1614.                         btStand.setDisable(true);
  1615.                         btnDouble.setDisable(true);
  1616.                         btnDoubleSplit2.setDisable(true);
  1617.                     }else {
  1618.                         stand(iterator,userHand,dealerHand,userHandSplit1,userHandSplit2,imageView4,primaryStage);
  1619.                     }
  1620.        
  1621.                 }
  1622.            
  1623.             }
  1624.             //return userHandSplit1.points;                
  1625.                
  1626.         }
  1627.    
  1628.        
  1629.    
  1630.     //hits the split 1 hand
  1631.     int split1Count = 1;
  1632.     private void split1Hit(Hand userHandSplit1, ListIterator<Card> iterator, Hand userHand, Hand dealerHand, Stage primaryStage) {
  1633.         hitSound();
  1634.         userHandSplit1.handArray.add(iterator.next());
  1635.        
  1636.         if (split1Count==1) {
  1637.             ImageView userSplit1CardHit1 =new ImageView(userHandSplit1.handArray.get(split1Count).image);
  1638.             userSplit1CardHit1Label.setGraphic(userSplit1CardHit1);
  1639.             userSplit1CardHit1Label.setTranslateX(85);
  1640.             userSplit1CardHit1Label.setTranslateY(26);
  1641.             userSplit1CardHit1Label.setScaleX(.2);
  1642.             userSplit1CardHit1Label.setScaleY(.19);
  1643.             split1Count++;
  1644.         }else if (split1Count==2) {
  1645.             ImageView userSplit1CardHit2 =new ImageView(userHandSplit1.handArray.get(split1Count).image);
  1646.        
  1647.             userSplit1CardHit2Label.setGraphic(userSplit1CardHit2);
  1648.             userSplit1CardHit2Label.setTranslateX(108);
  1649.             userSplit1CardHit2Label.setTranslateY(26);
  1650.             userSplit1CardHit2Label.setScaleX(.2);
  1651.             userSplit1CardHit2Label.setScaleY(.19);
  1652.             split1Count++;
  1653.         }else if (split1Count==3) {
  1654.             ImageView userSplit1CardHit3 =new ImageView(userHandSplit1.handArray.get(split1Count).image);
  1655.        
  1656.             userSplit1CardHit3Label.setGraphic(userSplit1CardHit3);
  1657.             userSplit1CardHit3Label.setTranslateX(131);
  1658.             userSplit1CardHit3Label.setTranslateY(26);
  1659.             userSplit1CardHit3Label.setScaleX(.2);
  1660.             userSplit1CardHit3Label.setScaleY(.19);
  1661.             split1Count++;
  1662.         }else if (split1Count==4) {
  1663.             ImageView userSplit1CardHit4 =new ImageView(userHandSplit1.handArray.get(split1Count).image);
  1664.        
  1665.             userSplit1CardHit4Label.setGraphic(userSplit1CardHit4);
  1666.             userSplit1CardHit4Label.setTranslateX(154);
  1667.             userSplit1CardHit4Label.setTranslateY(26);
  1668.             userSplit1CardHit4Label.setScaleX(.2);
  1669.             userSplit1CardHit4Label.setScaleY(.19);
  1670.             split1Count++;
  1671.            
  1672.         }
  1673.             userHandSplit1.points= 0;
  1674.             boolean ace = false;
  1675.             for(int i = 0; i < userHandSplit1.handArray.size(); i++) {
  1676.                
  1677.                
  1678.                
  1679.                 if(userHandSplit1.handArray.get(i).type=="Ace") {
  1680.                     ace = true;
  1681.                 }
  1682.            
  1683.                 userHandSplit1.points += userHandSplit1.handArray.get(i).value;;
  1684.                
  1685.                 //if the hand breaks 21 and has an ace, the ace value is reassigned to one and the
  1686.                 //hand points value is recalculated
  1687.                 if (userHandSplit1.points>21 && ace==true) {
  1688.                     userHandSplit1.points = 0;
  1689.                     for( i = 0; i < userHandSplit1.handArray.size(); i++) {
  1690.                         if(userHandSplit1.handArray.get(i).type=="Ace") {
  1691.                             userHandSplit1.handArray.get(i).value=userHandSplit1.handArray.get(i).otherValue;
  1692.                            
  1693.                            
  1694.                         }userHandSplit1.points += userHandSplit1.handArray.get(i).value;
  1695.                     }
  1696.                
  1697.                 }
  1698.            
  1699.                 if (userHandSplit1.points>21) {
  1700.                     resultsLabel.setText("Split 1 Bust");
  1701.                     split1Bust = true;
  1702.                     btnHitSplit1.setDisable(true);
  1703.                     btnStandSplit1.setDisable(true);
  1704.                     btnHitSplit2.setDisable(false);
  1705.                     btnStandSplit2.setDisable(false);
  1706.                     btnDoubleSplit1.setDisable(true);
  1707.                     btnDoubleSplit2.setDisable(false);
  1708.                     userLose(userHand,dealerHand,primaryStage);
  1709.        
  1710.                 }
  1711.            
  1712.             }
  1713.             //return userHandSplit1.points;                
  1714.                
  1715.         }
  1716.        
  1717.    
  1718.  
  1719.     //counter adds cards to userHand
  1720.     int count=2;
  1721.     @SuppressWarnings("unchecked")
  1722.     public int userHit( ListIterator<Card> iterator, Hand userHand,Hand dealerHand, ImageView imageView4) {
  1723.        
  1724.         //Disables the double down feature after the user hits, per Blackjack rules
  1725.         btnDouble.setDisable(true);
  1726.        
  1727.         //adds card to userhand
  1728.         userHand.handArray.add(iterator.next());
  1729.         //calls the hit sound effect method
  1730.         hitSound();
  1731.    
  1732.        
  1733.         if (count==2) {
  1734.             ImageView userCardHit1 =new ImageView(userHand.handArray.get(count).image);
  1735.        
  1736.             userCardHit1Label.setGraphic(userCardHit1);
  1737.             userCardHit1Label.setTranslateX(-35);
  1738.             userCardHit1Label.setTranslateY(61);
  1739.             userCardHit1Label.setScaleX(.2);
  1740.             userCardHit1Label.setScaleY(.19);
  1741.             count++;
  1742.         }else if(count == 3) {
  1743.             ImageView userCardHit2 =new ImageView(userHand.handArray.get(count).image);
  1744.            
  1745.             userCardHit2Label.setGraphic(userCardHit2);
  1746.             userCardHit2Label.setTranslateX(-25);
  1747.             userCardHit2Label.setTranslateY(61);
  1748.             userCardHit2Label.setScaleX(.2);
  1749.             userCardHit2Label.setScaleY(.19);
  1750.             count++;
  1751.         }else if(count == 4) {
  1752.             ImageView userCardHit3 =new ImageView(userHand.handArray.get(count).image);
  1753.            
  1754.             userCardHit3Label.setGraphic(userCardHit3);
  1755.             userCardHit3Label.setTranslateX(-15);
  1756.             userCardHit3Label.setTranslateY(61);
  1757.             userCardHit3Label.setScaleX(.2);
  1758.             userCardHit3Label.setScaleY(.19);
  1759.             count++;
  1760.        
  1761.         }else if (count ==5) {
  1762.             ImageView userCardHit4 =new ImageView(userHand.handArray.get(count).image);
  1763.             userCardHit4Label.setGraphic(userCardHit4);
  1764.             userCardHit4Label.setTranslateX(-5);
  1765.             userCardHit4Label.setTranslateY(61);
  1766.             userCardHit4Label.setScaleX(.2);
  1767.             userCardHit4Label.setScaleY(.19);
  1768.             count++;
  1769.         }
  1770.         //Adds up the userHand points
  1771.         userHand.points= 0;
  1772.         boolean ace = false;
  1773.         for(int i = 0; i < userHand.handArray.size(); i++) {
  1774.            
  1775.            
  1776.            
  1777.             if(userHand.handArray.get(i).type=="Ace") {
  1778.                 ace = true;
  1779.             }
  1780.        
  1781.             userHand.points += userHand.handArray.get(i).value;;
  1782.            
  1783.             //if the hand breaks 21 and has an ace, the ace value is reassigned to one and the
  1784.             //hand points value is recalculated
  1785.             if (userHand.points>21 && ace==true) {
  1786.                 userHand.points = 0;
  1787.                 for( i = 0; i < userHand.handArray.size(); i++) {
  1788.                     if(userHand.handArray.get(i).type=="Ace") {
  1789.                         userHand.handArray.get(i).value=userHand.handArray.get(i).otherValue;
  1790.                        
  1791.                        
  1792.                     }userHand.points += userHand.handArray.get(i).value;
  1793.                 }
  1794.            
  1795.             }
  1796.        
  1797.             if (userHand.points>21) {
  1798.                 imageView4.setImage(dealerHand.handArray.get(1).image);
  1799.                 resultsLabel.setText("Bust");
  1800.                 btHit.setDisable(true);
  1801.                 btRetry.setVisible(true);
  1802.                 userHand.handArray.removeAll(userHand.handArray);
  1803.                 btStand.setDisable(true);
  1804.                 btHit.setDisable(true);
  1805.                 btRetry.setVisible(true);
  1806.                 btnDouble.setDisable(true);
  1807.                 btnDoubleSplit2.setDisable(false);
  1808.                 userLose(dealerHand, dealerHand, null);
  1809.    
  1810.             }
  1811.        
  1812.         }
  1813.         return userHand.points;                
  1814.            
  1815.     }
  1816.     //hit sound sound effect   
  1817.     private void hitSound() {
  1818.         File file = new File("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/CardHit.wav");
  1819.         Clip hit = null;
  1820.         try {
  1821.             hit = AudioSystem.getClip();
  1822.         } catch (LineUnavailableException e) {
  1823.             // TODO Auto-generated catch block
  1824.             e.printStackTrace();
  1825.         }  
  1826.         try {
  1827.             hit.open(AudioSystem.getAudioInputStream(file));
  1828.         } catch (LineUnavailableException e) {
  1829.             // TODO Auto-generated catch block
  1830.             e.printStackTrace();
  1831.         } catch (IOException e) {
  1832.             // TODO Auto-generated catch block
  1833.             e.printStackTrace();
  1834.         } catch (UnsupportedAudioFileException e) {
  1835.             // TODO Auto-generated catch block
  1836.             e.printStackTrace();
  1837.         }
  1838.         hit.start();
  1839.        
  1840.     }  
  1841.            
  1842.  
  1843.     public static void main(String[] args) {
  1844.        
  1845. //Background music
  1846. File file = new File("/Users/dwlakes/Desktop/Java Projects/Black Jack Cards/bensound-theelevatorbossanova.wav");
  1847. Clip song = null;
  1848. try {
  1849.     song = AudioSystem.getClip();
  1850. } catch (LineUnavailableException e) {
  1851.     // TODO Auto-generated catch block
  1852.     e.printStackTrace();
  1853. }  
  1854. try {
  1855.     song.open(AudioSystem.getAudioInputStream(file));
  1856. } catch (LineUnavailableException e) {
  1857.     // TODO Auto-generated catch block
  1858.     e.printStackTrace();
  1859. } catch (IOException e) {
  1860.     // TODO Auto-generated catch block
  1861.     e.printStackTrace();
  1862. } catch (UnsupportedAudioFileException e) {
  1863.     // TODO Auto-generated catch block
  1864.     e.printStackTrace();
  1865. }
  1866.  
  1867. //song.loop(Clip.LOOP_CONTINUOUSLY);
  1868. Application.launch(args);
  1869.    
  1870.     }
  1871.  
  1872.    
  1873. }
  1874.  
Add Comment
Please, Sign In to add comment