Пример #1
0
  private Scene createMainTetrisScene() {
    mainPane = new BorderPane();

    VBox mainBox = new VBox();
    mainBox.setPadding(new Insets(200, 0, 0, 20));
    mainBox.getChildren().add(mainGrid);
    mainGrid.setOnKeyPressed(new KeyboardHandler());

    mainPane.setBottom(mainBox);
    mainPane.setTop(createActionPane());
    mainPane.setRight(createStatePane());

    Group group = new Group();
    for (int i = 19; i >= 0; i--) {
      for (int j = 0; j < 10; j++) {
        Image img;
        if (mainGrid.getColor(i, j) != Color.DARKGRAY) {
          img = new Image(getClass().getResourceAsStream("RED.png"));
        } else {
          img = new Image(getClass().getResourceAsStream("EMPTY.png"));
        }
        ImageView iView = new ImageView(img);
        iView.setX(j * 17);
        iView.setY(i * 16);
        iView.setOpacity(1);
        iView.setPreserveRatio(true);
        group.getChildren().addAll(iView);
      }
    }
    Scene scene = new Scene(group, 600, 600);
    mainPane.setCenter(group);

    return new Scene(mainPane, 380, 540); // 540
  }
Пример #2
0
  public void repaint3D() {
    mainPane = new BorderPane();
    VBox mainBox = new VBox();
    mainBox.setPadding(new Insets(200, 0, 0, 20));
    mainBox.getChildren().add(mainGrid);
    mainGrid.setOnKeyPressed(new KeyboardHandler());

    mainPane.setBottom(mainBox);
    mainPane.setTop(createActionPane());
    mainPane.setRight(createStatePane());

    Group group = new Group();
    for (int i = 22; i >= 0; i--) {
      for (int j = -1; j < 11; j++) {
        Image img;
        if (i == 22 || (j == -1 || j == 10))
          img = new Image(getClass().getResourceAsStream("GRAY.png"));
        else if (mainGrid.getColor(i, j) == Color.YELLOW)
          img = new Image(getClass().getResourceAsStream("YELLOW.png"));
        else if (mainGrid.getColor(i, j) == Color.MAGENTA)
          img = new Image(getClass().getResourceAsStream("RED.png"));
        else if (mainGrid.getColor(i, j) == Color.GREEN)
          img = new Image(getClass().getResourceAsStream("GREEN.png"));
        else if (mainGrid.getColor(i, j) == Color.ORANGE)
          img = new Image(getClass().getResourceAsStream("ORANGE.png"));
        else if (mainGrid.getColor(i, j) == Color.BLUE)
          img = new Image(getClass().getResourceAsStream("BLUE.png"));
        else if (mainGrid.getColor(i, j) == Color.CYAN)
          img = new Image(getClass().getResourceAsStream("CYAN.png"));
        else if (mainGrid.getColor(i, j) == Color.PINK)
          img = new Image(getClass().getResourceAsStream("VIOLET.png"));
        else img = new Image(getClass().getResourceAsStream("EMPTY.png"));
        ImageView iView = new ImageView(img);
        iView.setX(j * 17);
        iView.setY(i * 16);
        iView.setOpacity(1);
        iView.setPreserveRatio(true);
        group.getChildren().addAll(iView);
      }
    }
    mainPane.setCenter(group);
    // Stage old = stage3D;
    // stage3D = new Stage();
    stage3D.setScene(new Scene(mainPane, 380, 540));
  }