private void reageeriKlikile() {
   laud.setOnMouseClicked(
       event -> {
         Rectangle ruut = (Rectangle) event.getTarget();
         String ruuduId = ruut.getId();
         if (ruuduId.equals("laev")) {
           ruut.setFill(laevaMuster);
           ruut.setId("põhjas");
         } else if (ruuduId.equals("meri")) {
           ruut.setFill(Color.DARKBLUE);
         } else if (ruuduId.equals("põhjas")) {
           System.out.println("ou, juba lasid siia");
         }
         if (!laevasidAlles()) {
           gameover();
         }
       });
 }
Ejemplo n.º 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);
  }