private void rebuild() {
   // update indeterminate indicator
   final int segments = skin.indeterminateSegmentCount.get();
   opacities.clear();
   pathsG.getChildren().clear();
   final double step = 0.8 / (segments - 1);
   for (int i = 0; i < segments; i++) {
     Region region = new Region();
     region.setScaleShape(false);
     region.setCenterShape(false);
     region.getStyleClass().addAll("segment", "segment" + i);
     if (fillOverride instanceof Color) {
       Color c = (Color) fillOverride;
       region.setStyle(
           "-fx-background-color: rgba("
               + ((int) (255 * c.getRed()))
               + ","
               + ""
               + ((int) (255 * c.getGreen()))
               + ","
               + ((int) (255 * c.getBlue()))
               + ","
               + ""
               + c.getOpacity()
               + ");");
     } else {
       region.setStyle(null);
     }
     double opacity = Math.min(1, i * step);
     opacities.add(opacity);
     region.setOpacity(opacity);
     pathsG.getChildren().add(region);
   }
 }
Пример #2
0
  private Parent createContent() throws IOException {
    dealer = new Hand(dealerCards.getChildren());
    player = new Hand(playerCards.getChildren());

    Pane root = new Pane();
    root.setPrefSize(windowWidth, windowHeight);

    Region background = new Region();
    background.setPrefSize(windowWidth, windowHeight);
    background.setStyle("-fx-background-image: url('res/images/casino.jpg')");

    HBox rootLayout = new HBox(5);
    rootLayout.setPadding(new Insets(5, 5, 5, 5));
    //        Rectangle leftBG = new Rectangle(550, 560);
    //        leftBG.setArcWidth(50);
    //        leftBG.setArcHeight(50);
    //        leftBG.setFill(Color.GREEN);
    //
    Canvas canvas = new Canvas(560, 560);

    BufferedImage imgi;
    GraphicsContext gcfx = canvas.getGraphicsContext2D();
    // Graphics gc = canvas.getGraphics();
    Image zbyszek = new Image("/res/images/table.png", 560, 560, true, false);

    gcfx.setFill(DARKSLATEGRAY);
    gcfx.fillRoundRect(0, 0, 550, 300, 10, 100);
    gcfx.setFill(BLACK);
    gcfx.drawImage(zbyszek, 0, 280);

    //        try {
    //            imgi = ImageIO.read(Card.class.getResource("/res/images/table.png"));
    //
    //            gcfx.drawImage(imgi, 300, 300, null);
    //            canvas.setVisible(true);
    //        } catch (Exception e) {
    //        }

    Rectangle rightBG = new Rectangle(230, 560);
    rightBG.setArcWidth(50);
    rightBG.setArcHeight(50);
    rightBG.setFill(Color.ORANGE);

    // LEFT
    VBox leftVBox = new VBox(50);
    leftVBox.setAlignment(Pos.TOP_CENTER);

    Text dealerScore = new Text("Dealer: ");
    Text playerScore = new Text("Player: ");

    leftVBox.getChildren().addAll(dealerScore, dealerCards, message, playerCards, playerScore);

    // RIGHT
    VBox rightVBox = new VBox(20);
    rightVBox.setAlignment(Pos.CENTER);

    // final TextField bet = new TextField("BET");
    // bet.setDisable(true);
    // bet.setMaxWidth(50);
    // Text money = new Text("MONEY");
    Button btnPlay = new Button("PLAY");
    Button btnHit = new Button("HIT");
    Button btnStand = new Button("STAND");

    HBox buttonsHBox = new HBox(15, btnHit, btnStand);
    buttonsHBox.setAlignment(Pos.CENTER);

    // rightVBox.getChildren().addAll(bet, btnPlay, money, buttonsHBox);
    rightVBox.getChildren().addAll(btnPlay, buttonsHBox);

    // ADD BOTH STACKS TO ROOT LAYOUT
    rootLayout
        .getChildren()
        .addAll(new StackPane(canvas, leftVBox), new StackPane(rightBG, rightVBox));
    root.getChildren().addAll(background, rootLayout);

    // BIND PROPERTIES
    btnPlay.disableProperty().bind(playable);
    btnHit.disableProperty().bind(playable.not());
    btnStand.disableProperty().bind(playable.not());

    playerScore
        .textProperty()
        .bind(new SimpleStringProperty("Player: ").concat(player.valueProperty().asString()));
    dealerScore
        .textProperty()
        .bind(new SimpleStringProperty("Dealer: ").concat(dealer.valueProperty().asString()));

    player
        .valueProperty()
        .addListener(
            (obs, old, newValue) -> {
              if (newValue.intValue() >= 21) {
                endGame();
              }
            });

    dealer
        .valueProperty()
        .addListener(
            (obs, old, newValue) -> {
              if (newValue.intValue() >= 21) {
                endGame();
              }
            });

    // INIT BUTTONS
    btnPlay.setOnAction(
        event -> {
          startNewGame();
        });

    btnHit.setOnAction(
        event -> {
          player.takeCard(deck.drawCard());
        });

    btnStand.setOnAction(
        event -> {
          while (dealer.valueProperty().get() < 17) {
            dealer.takeCard(deck.drawCard());
          }

          endGame();
        });

    return root;
  }