示例#1
0
  public void reactOnMouseClick(
      GridPane grid,
      String[] listOfImageAsk,
      Image imgYes,
      Image imgNo,
      ImageView imageViewSourceRef) {
    System.out.println("Level Factor is " + levelFactor);
    String id = imageViewSourceRef.getId();
    System.out.println(id);
    int columnIndex = grid.getColumnIndex(imageViewSourceRef);
    int rowIndex = grid.getRowIndex(imageViewSourceRef);

    if (ifTheRightPictureClicked(id, listOfImageAsk)) {
      grid.add(new ImageView(imgYes), columnIndex, rowIndex);
      correctImageCounter = correctImageCounter + 1;
      System.out.println("Correct image counter is " + correctImageCounter);
      if (correctImageCounter == levelFactor) {
        levelSuccess();
      }
    } else wrongImageClicked(grid, imgNo, columnIndex, rowIndex);
  }
示例#2
0
  public void checkResultScreen(String[] listOfImageAsk) {

    VBox vbox = new VBox(40);
    GridPane grid = new GridPane();
    grid.setGridLinesVisible(false);
    Image imgYes =
        new Image(
            "file:C:\\Users\\emaktse\\Documents\\HITSA\\GIT Repository\\javaProject\\Images library\\yes.gif");
    ImageView imageViewYes = new ImageView(imgYes);
    Image imgNo =
        new Image(
            "file:C:\\Users\\emaktse\\Documents\\HITSA\\GIT Repository\\javaProject\\Images library\\no.gif");
    ImageView imageViewNo = new ImageView(imgNo);

    int i = 0;
    for (int j = 0; j < 7; j++) {
      for (int k = 0; k < 7; k++) {
        Image image = allImages[i];
        ImageView imageCheck = new ImageView(image);
        imageCheck.setId(i + ".gif");
        grid.add(imageCheck, k, j);
        i++;
      }
    }

    grid.setOnMouseClicked(
        e -> {
          ImageView imageViewSourceRef = (ImageView) e.getTarget();
          reactOnMouseClick(grid, listOfImageAsk, imgYes, imgNo, imageViewSourceRef);
        });

    Button tryAgain = new Button("Try again");
    grid.setAlignment(Pos.CENTER);
    vbox.getChildren().addAll(grid, tryAgain);
    vbox.setAlignment(Pos.CENTER);

    scene4 = new Scene(vbox, 1000, 800);
    window1.setScene(scene4);
  }
示例#3
0
 public void wrongImageClicked(GridPane grid, Image imgNo, int columnIndex, int rowIndex) {
   grid.add(new ImageView(imgNo), columnIndex, rowIndex);
   System.out.println("gameover method");
   pause();
 }