コード例 #1
0
  @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);
  }