@FXML
  private void handlePlay() {

    eGameState = eGameState.StartOfGame;

    // Clear all players hands
    hBoxP1Cards.getChildren().clear();
    hBoxP2Cards.getChildren().clear();
    hBoxP3Cards.getChildren().clear();
    hBoxP4Cards.getChildren().clear();

    // Face down card (will represent the deck)
    ImageView imgBottomCard =
        new ImageView(
            new Image(getClass().getResourceAsStream("/res/img/b1fh.png"), 75, 75, true, true));

    HboxCommonArea.getChildren().clear();
    HboxCommonArea.getChildren().add(imgBottomCard);
    HboxCommunityCards.getChildren().clear();

    // ensures play cannot be pressed without selecting a game type
    // this still allows you to hit draw, so something more robust is needed,
    // or something has to be added to handleDraw()
    if (this.mainApp.getiGameType() == null) {
      displayWarning("you must select a game to play from the menu");
      return;
    }

    // Get the Rule, start the Game
    Rule rle = new Rule(this.mainApp.getiGameType());
    gme = new GamePlay(rle);

    // Add the seated players to the game, create a GPPH for the player
    for (Player p : mainApp.GetSeatedPlayers()) {
      gme.addPlayerToGame(p);
      GamePlayPlayerHand GPPH = new GamePlayPlayerHand();
      GPPH.setGame(gme);
      GPPH.setPlayer(p);
      GPPH.setHand(new Hand());
      gme.addGamePlayPlayerHand(GPPH);
      DealFaceDownCards(gme.getNbrOfCards(), p.getiPlayerPosition());
    }

    // Add the common player (community player) to the game
    GamePlayPlayerHand GPCH = new GamePlayPlayerHand();
    GPCH.setGame(gme);
    GPCH.setPlayer(PlayerCommon);
    GPCH.setHand(new Hand());
    gme.addGamePlayCommonHand(GPCH);
    DealFaceDownCards(gme.getRule().GetCommunityCardsCount(), 0);

    // Add a deck to the game
    gme.setGameDeck(new Deck(rle.GetNumberOfJokers(), rle.GetRuleCards()));

    // Call common code to set the game controls
    SetGameControls(eGameState);
  }
Exemple #2
0
 public void RemovePlayerFromTable(int PlayerPosition) {
   Player playerToRemove = null;
   for (Player p : tbl.getPlayers()) {
     if (p.getiPlayerPosition() == PlayerPosition) {
       playerToRemove = p;
       break;
     }
   }
   tbl.removePlayer(playerToRemove);
 }
  @FXML
  private void handlePlay() {

    eGameState = eGameState.StartOfGame;

    // Clear all players hands
    hBoxP1Cards.getChildren().clear();
    hBoxP2Cards.getChildren().clear();
    hBoxP3Cards.getChildren().clear();
    hBoxP4Cards.getChildren().clear();

    // Face down card (will represent the deck)
    ImageView imgBottomCard =
        new ImageView(
            new Image(getClass().getResourceAsStream("/res/img/b1fh.png"), 75, 75, true, true));

    HboxCommonArea.getChildren().clear();
    HboxCommonArea.getChildren().add(imgBottomCard);
    HboxCommunityCards.getChildren().clear();

    // Get the Rule, start the Game
    Rule rle = new Rule(eGame.Omaha);
    gme = new GamePlay(rle);

    // Add the seated players to the game, create a GPPH for the player
    for (Player p : mainApp.GetSeatedPlayers()) {
      gme.addPlayerToGame(p);
      GamePlayPlayerHand GPPH = new GamePlayPlayerHand();
      GPPH.setGame(gme);
      GPPH.setPlayer(p);
      GPPH.setHand(new Hand());
      gme.addGamePlayPlayerHand(GPPH);
      DealFaceDownCards(gme.getNbrOfCards(), p.getiPlayerPosition());
    }

    // Add the common player (community player) to the game
    GamePlayPlayerHand GPCH = new GamePlayPlayerHand();
    GPCH.setGame(gme);
    GPCH.setPlayer(PlayerCommon);
    GPCH.setHand(new Hand());
    gme.addGamePlayCommonHand(GPCH);
    DealFaceDownCards(gme.getRule().GetCommunityCardsCount(), 0);

    // Add a deck to the game
    gme.setGameDeck(new Deck(rle.GetNumberOfJokers(), rle.GetRuleCards()));

    // Call common code to set the game controls
    SetGameControls(eGameState);
  }
  @FXML
  private void handleDraw() {

    if (this.mainApp.getiGameType() == null) {
      displayWarning("you must select a game to play from the menu");
      return;
    }

    iCardDrawn++;
    iDrawCount++;
    ImageView imView = null;
    eGameState = eGameState.PlayOfGame;

    // Disable the button in case of double-click
    SetGameControls(eGameState.DrawingCard);

    // Create the parent transition
    SequentialTransition tranDealCards = new SequentialTransition();

    // Figure the action based on the game, state of game
    Action act = new Action(gme, iCardDrawnPlayer, iCardDrawnCommon, iDrawCount);

    if (act.geteDrawAction() == eDrawAction.DrawPlayer) {
      // Draw a card for each player seated
      for (int iDraw = 0; iDraw < act.getiCardDrawn(); iDraw++) {
        iCardDrawnPlayer++;
        for (Player p : mainApp.GetSeatedPlayers()) {
          Card c = gme.getGameDeck().drawFromDeck();

          HBox PlayerCardBox = null;

          switch (p.getiPlayerPosition()) {
            case 1:
              PlayerCardBox = hBoxP1Cards;
              imView = imgTransCardP1;
              break;
            case 2:
              PlayerCardBox = hBoxP2Cards;
              imView = imgTransCardP2;
              break;

            case 3:
              PlayerCardBox = hBoxP3Cards;
              imView = imgTransCardP3;
              break;

            case 4:
              PlayerCardBox = hBoxP4Cards;
              imView = imgTransCardP4;
              break;
          }
          gme.FindPlayerGame(gme, p).addCardToHand(c);
          tranDealCards
              .getChildren()
              .add(CalculateTransition(c, PlayerCardBox, imView, iCardDrawnPlayer));
        }
      }

    } else if (act.geteDrawAction() == eDrawAction.DrawCommon) {

      for (int iDraw = 0; iDraw < act.getiCardDrawn(); iDraw++) {
        iCardDrawnCommon++;
        imView = imgTransCardCommon;
        Card c = gme.getGameDeck().drawFromDeck();
        gme.FindCommonHand(gme).addCardToHand(c);
        tranDealCards
            .getChildren()
            .add(CalculateTransition(c, HboxCommunityCards, imView, iCardDrawnCommon));
      }
    }

    // tranDealCards is the master transition... it has deals for every card
    // to every player. Play it.
    tranDealCards.play();

    // If bEvalHand is true, it's time to evaluate the Hand...
    if (act.isbEvaluateHand()) {

      ArrayList<GamePlayPlayerHand> AllPlayersHands = new ArrayList<GamePlayPlayerHand>();
      ArrayList<Hand> BestPlayerHands = new ArrayList<Hand>();
      HashMap hsPlayerHand = new HashMap();

      for (Player p : mainApp.GetSeatedPlayers()) {
        GamePlayPlayerHand GPPH = gme.FindPlayerGame(gme, p);
        Hand PlayerHand = GPPH.getHand();
        GamePlayPlayerHand GPCH = gme.FindCommonHand(gme);

        ArrayList<Hand> AllHands = Hand.ListHands(GPPH.getHand(), GPCH.getHand(), GPPH.getGame());
        Hand hBestHand = Hand.PickBestHand(AllHands);
        GPPH.setBestHand(hBestHand);
        hsPlayerHand.put(hBestHand, GPPH.getPlayer());
        BestPlayerHands.add(hBestHand);
      }

      Hand WinningHand = Hand.PickBestHand(BestPlayerHands);
      Player WinningPlayer = (Player) hsPlayerHand.get(WinningHand);
      System.out.println(
          "Winning Player Position: "
              + WinningPlayer.getiPlayerPosition()
              + "("
              + WinningPlayer.getPlayerName()
              + ")");
      displayWinner(
          "Winning Player Position: "
              + WinningPlayer.getiPlayerPosition()
              + " ("
              + WinningPlayer.getPlayerName()
              + ")");
      SetGameControls(eGameState.EndOfGame);

    } else {
      if (iCardDrawnPlayer + iCardDrawnCommon + 2 >= gme.getRule().getTotalCardsToDraw()) {
        for (Player p : mainApp.GetSeatedPlayers()) {
          Hand hPlayer = gme.FindPlayerGame(gme, p).getHand();
          for (int a = hPlayer.getCards().size(); a < gme.getRule().GetPlayerNumberOfCards(); a++) {
            hPlayer.AddCardToHand(new Card(eSuit.JOKER, eRank.JOKER, 0));
          }

          Hand hCommon = gme.FindCommonHand(gme).getHand();

          if (hCommon.getCards() == null) {
            for (int a = 0; a < gme.getRule().GetCommunityCardsCount(); a++) {
              hCommon.AddCardToHand(new Card(eSuit.JOKER, eRank.JOKER, 0));
            }
          } else {

            for (int a = hCommon.getCards().size();
                a < gme.getRule().GetCommunityCardsCount();
                a++) {
              hCommon.AddCardToHand(new Card(eSuit.JOKER, eRank.JOKER, 0));
            }
          }
          ArrayList<Hand> AllHands = Hand.ListHands(hPlayer, hCommon, gme);

          System.out.println(AllHands.get(0).getHandStrength());
        }
      }

      // Re-enable the draw button
      SetGameControls(eGameState);
    }
  }
  @FXML
  private void handlePlay() {
    // Clear all players hands
    HboxCommonArea.getChildren().clear();
    HboxCommunityCards.getChildren().clear();
    h1P1.getChildren().clear();
    v2P2.getChildren().clear();
    h3P3.getChildren().clear();
    v4P4.getChildren().clear();
    handsInPlay.clear();
    winnerAnnouncement.setText("");

    // Correct the spacing of cards on the East and West sides
    h1P1.setSpacing(-30);
    v2P2.setSpacing(-45);
    h3P3.setSpacing(-30);
    v4P4.setSpacing(-45);

    // Get the Rule, start the Game
    Rule rle = new Rule(eGame.FiveStud);
    gme = new GamePlay(rle);

    NbrCards = gme.getNbrOfCards();
    NbrCommunityCards = gme.getNbrCommunityCards();

    // For purpose of testing when the game is set to Five Card Stud:
    NbrCommunityCards = 5;

    // Add the seated players to the game
    for (Player p : mainApp.GetSeatedPlayers()) {
      gme.addPlayerToGame(p);
      GamePlayPlayerHand GPPH = new GamePlayPlayerHand();
      GPPH.setGame(gme);
      GPPH.setPlayer(p);
      GPPH.setHand(new Hand());
      gme.addGamePlayPlayerHand(GPPH);
    }

    // Add a deck to the game
    gme.setGameDeck(new Deck());

    btnDraw.setVisible(true);
    btnDrawCenter.setVisible(false);
    iCardDrawn = 0;
    communityCardDrawn = 0;

    String strCard = "/res/img/b1fv.png";

    if (bP1Sit == true) {
      for (int i = 0; i < gme.getNbrOfCards(); i++) {
        ImageView img =
            new ImageView(new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));
        h1P1.getChildren().add(img);
      }
    }

    if (bP2Sit == true) {
      for (int i = 0; i < gme.getNbrOfCards(); i++) {
        ImageView img =
            new ImageView(new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));
        img.setRotate(90);
        v2P2.getChildren().add(img);
      }
    }

    if (bP3Sit == true) {
      for (int i = 0; i < gme.getNbrOfCards(); i++) {
        ImageView img =
            new ImageView(new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

        h3P3.getChildren().add(img);
      }
    }

    if (bP4Sit == true) {
      for (int i = 0; i < gme.getNbrOfCards(); i++) {
        ImageView img =
            new ImageView(new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));
        img.setRotate(-90);
        v4P4.getChildren().add(img);
      }
    }

    for (int i = 0; i < this.NbrCommunityCards; i++) {
      ImageView img =
          new ImageView(new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

      HboxCommunityCards.getChildren().add(img);
    }

    ImageView imgBottomCard =
        new ImageView(
            new Image(getClass().getResourceAsStream("/res/img/b2fh.png"), 75, 75, true, true));

    HboxCommonArea.getChildren().add(imgBottomCard);

    // Draw for the number of cards being dealt according to the current game's rules
    for (int i = 0; i < NbrCards; i++) {
      handleDraw();
    }

    // Make an ArrayList for the hands to compare
    ArrayList<Hand> handsAsHands = new ArrayList<Hand>();

    for (GamePlayPlayerHand gpph : handsInPlay) {
      handsAsHands.add(gpph.getHand());
    }

    // Find the best hand of those in play
    Hand winningHand = Hand.PickBestHand(handsAsHands);

    // Establish the winning player
    Player winningPlayer = new Player("null", 0);

    // Match the winning hand to the winning player
    for (GamePlayPlayerHand gpph : handsInPlay) {
      if (gpph.getHand() == winningHand) {
        winningPlayer = gpph.getPlayer();
      }
    }

    // Print the winner to the console and the game itself
    String winner = winningPlayer.getPlayerName() + " wins!";
    System.out.println(winner);
    winnerAnnouncement.setText(winner);
  }
  @FXML
  private void handleDraw() {
    iCardDrawn++;

    // Draw a card for each player seated
    for (Player p : mainApp.GetSeatedPlayers()) {
      Card c = gme.getGameDeck().drawFromDeck();

      // Player 1
      if (p.getiPlayerPosition() == 1) {
        GamePlayPlayerHand GPPH = gme.FindPlayerGame(gme, p);
        GPPH.addCardToHand(c);
        String strCard = "/res/img/" + c.getCardImg();
        ImageView img =
            new ImageView(new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

        ImageView i = (ImageView) h1P1.getChildren().get(iCardDrawn - 1);
        ImageView iCardFaceDown = (ImageView) HboxCommonArea.getChildren().get(0);
        final ParallelTransition transitionForward =
            createTransition(
                i,
                iCardFaceDown,
                new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

        transitionForward.play();
        // h1P1.getChildren().add(img);

        if (iCardDrawn == NbrCards) {
          GPPH.getHand().EvalHand();
          handsInPlay.add(GPPH);
        }
      }

      // Player 2
      if (p.getiPlayerPosition() == 2) {
        GamePlayPlayerHand GPPH = gme.FindPlayerGame(gme, p);
        GPPH.addCardToHand(c);
        String strCard = "/res/img/" + c.getCardImg();
        ImageView img =
            new ImageView(new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

        ImageView i = (ImageView) v2P2.getChildren().get(iCardDrawn - 1);
        ImageView iCardFaceDown = (ImageView) HboxCommonArea.getChildren().get(0);
        final ParallelTransition transitionForward =
            createTransition(
                i,
                iCardFaceDown,
                new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

        transitionForward.play();
        // h1P1.getChildren().add(img);

        if (iCardDrawn == NbrCards) {
          GPPH.getHand().EvalHand();
          handsInPlay.add(GPPH);
        }
      }

      // Player 3
      if (p.getiPlayerPosition() == 3) {
        GamePlayPlayerHand GPPH = gme.FindPlayerGame(gme, p);
        GPPH.addCardToHand(c);
        String strCard = "/res/img/" + c.getCardImg();
        ImageView img =
            new ImageView(new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

        ImageView i = (ImageView) h3P3.getChildren().get(iCardDrawn - 1);
        ImageView iCardFaceDown = (ImageView) HboxCommonArea.getChildren().get(0);
        final ParallelTransition transitionForward =
            createTransition(
                i,
                iCardFaceDown,
                new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

        transitionForward.play();
        // h1P1.getChildren().add(img);

        if (iCardDrawn == NbrCards) {
          GPPH.getHand().EvalHand();
          this.handsInPlay.add(GPPH);
        }
      }

      // Player 4
      if (p.getiPlayerPosition() == 4) {
        GamePlayPlayerHand GPPH = gme.FindPlayerGame(gme, p);
        GPPH.addCardToHand(c);
        String strCard = "/res/img/" + c.getCardImg();
        ImageView img =
            new ImageView(new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

        ImageView i = (ImageView) v4P4.getChildren().get(iCardDrawn - 1);
        ImageView iCardFaceDown = (ImageView) HboxCommonArea.getChildren().get(0);
        final ParallelTransition transitionForward =
            createTransition(
                i,
                iCardFaceDown,
                new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

        transitionForward.play();
        // h1P1.getChildren().add(img);

        if (iCardDrawn == NbrCards) {
          GPPH.getHand().EvalHand();
          handsInPlay.add(GPPH);
        }
      }
    }

    if (iCardDrawn == NbrCards) {
      btnDraw.setVisible(false);

      if (NbrCommunityCards != 0) {
        btnDrawCenter.setVisible(true);
      }
    }
  }