示例#1
0
  public void askImageScreen() {

    Integer[] randomImageNumber = new Integer[49];
    for (int i = 0; i < randomImageNumber.length; i++) {
      randomImageNumber[i] = i;
    }
    Collections.shuffle(Arrays.asList((randomImageNumber)));

    String[] listOfImageAsk = new String[levelFactor];

    Group group = new Group();
    for (int i = 0; i < listOfImageAsk.length; i++) {
      Image image = allImages[randomImageNumber[i]];
      ImageView imageAsk = new ImageView(image);
      imageAsk.setId(randomImageNumber[i] + ".gif");
      listOfImageAsk[i] = (randomImageNumber[i] + ".gif");
      imageAsk.setX(i * 83);
      group.getChildren().add(imageAsk);
      System.out.println(listOfImageAsk[i]);
    }

    // scene3 elements

    Label instruction = new Label("RULES TO BE HERE");
    Button nextButton = new Button("NEXT");

    BorderPane layout3 = new BorderPane();

    layout3.setCenter(group);
    layout3.setTop(instruction);
    layout3.setBottom(nextButton);
    layout3.setAlignment(instruction, Pos.TOP_CENTER);
    layout3.setAlignment(nextButton, Pos.BASELINE_CENTER);
    nextButton.setOnAction(e -> checkResultScreen(listOfImageAsk));
    nextButton.setOnKeyPressed(e -> checkResultScreen(listOfImageAsk));

    scene3 = new Scene(layout3, 800, 600);
    window1.setScene(scene3);
  }
示例#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
 @FXML
 public void loadGame(ActionEvent event) {
   Stage newStage = new Stage();
   if (event.getSource() == loadButton) {
     loadData = LoadSaveGame.load();
     if (loadData != null) {
       Controller.loaded = true;
       GameController.numPasses = (int) Controller.loadData.get(4);
       // GameController.landButton.setDisable(true);
       try {
         gameRoot = FXMLLoader.load(getClass().getResource("UIFiles/MainMap.fxml"));
         gameScene = new Scene(gameRoot);
         Parent startWindow = FXMLLoader.load(getClass().getResource("UIFiles/playerStart.fxml"));
         startScene = new Scene(startWindow);
       } catch (IOException e) {
         e.printStackTrace();
       }
       newStage.setScene(gameScene);
       newStage.setTitle("Game Screen");
       newStage.show();
       GridPane grid = (GridPane) gameRoot;
       landPlots = (Land[][]) loadData.get(0);
       level = (String) loadData.get(1);
       players = (Player[]) loadData.get(3);
       for (Player player : players) {
         for (Land land : player.getLandOwned()) {
           landPlots[land.getCol()][land.getRow()].setOwner(player);
         }
       }
       if (grid != null) {
         for (Land[] landArray : landPlots) {
           for (Land land : landArray) {
             if (land.isOwned()) {
               Player owner = land.getOwner();
               Rectangle color = new Rectangle();
               color.setFill(Color.valueOf(owner.getColor()));
               color.setHeight(25);
               color.setWidth(25);
               color.setOpacity(1);
               GridPane.setHalignment(color, HPos.LEFT);
               GridPane.setValignment(color, VPos.TOP);
               grid.add(color, land.getCol(), land.getRow());
               if (land.hasMule()) {
                 Image mulePic = new Image("gameConfig/UIFiles/Media/aMule.png");
                 ImageView muleView = new ImageView();
                 muleView.setImage(mulePic);
                 muleView.setFitWidth(50);
                 muleView.setPreserveRatio(true);
                 GridPane.setHalignment(muleView, HPos.LEFT);
                 GridPane.setValignment(muleView, VPos.CENTER);
                 muleView.setId(String.valueOf(land.getCol()) + String.valueOf(land.getRow()));
                 grid.add(muleView, land.getCol(), land.getRow());
               }
             }
           }
         }
       }
       numPlayer = players.length;
       Turns turns = new Turns(players);
       turns.setRounds((int) loadData.get(5));
       GameController.beginTurn();
     } else {
       Controller.loaded = false;
     }
   }
 }
  @FXML
  public void handleOk() {
    String tituloAux = titulo.getText().replaceAll(" ", "+").toLowerCase();
    String toJson = readUrl(BASE + tituloAux + "&type=series" + "&r=json");
    resultados.getChildren().clear();
    try {
      JSONObject busqueda = new JSONObject(toJson);
      if (busqueda.getString("Response").equals("True")) {
        JSONArray res = busqueda.getJSONArray("Search");
        resultados.setPrefRows(res.length());
        for (int i = 0; i < res.length(); i++) {
          JSONObject resActual = new JSONObject(res.get(i).toString());
          HBox resultadoActual = new HBox(50);
          resultadoActual.setMaxWidth(Double.MAX_VALUE);
          resultadoActual.setAlignment(Pos.CENTER_LEFT);
          ImageView posterActual = new ImageView();

          try {
            Image image = new Image(resActual.getString("Poster"));
            posterActual.setImage(image);
            posterActual.setFitHeight(240);
            posterActual.setFitWidth(180);
            posterActual.setPreserveRatio(false);
            resultadoActual.getChildren().add(posterActual);
          } catch (IllegalArgumentException e) {
            //                        System.out.println("Bad url");
            Image image =
                new Image(MainApp.class.getResource("resources/no-image.png").toExternalForm());
            posterActual.setImage(image);
            posterActual.setFitHeight(240);
            posterActual.setFitWidth(180);
            posterActual.setPreserveRatio(false);
            resultadoActual.getChildren().add(posterActual);
          }

          String details;
          String nomSerie = new String(resActual.getString("Title").getBytes(), "UTF-8");
          String anoSerie = new String(resActual.getString("Year").getBytes(), "UTF-8");
          if (nomSerie.length() > 15) {
            details = "%-12.12s...\t\t Año: %-10s";
          } else {
            details = "%-12s\t\t Año: %-10s";
          }
          details = String.format(details, nomSerie, anoSerie);
          Label elemento = new Label(details);
          elemento.setMaxWidth(Double.MAX_VALUE);
          elemento.setMaxHeight(Double.MAX_VALUE);
          resultadoActual.getChildren().add(elemento);

          posterActual.setId(resActual.getString("imdbID"));
          posterActual.setOnMouseClicked(
              new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent event) {
                  ImageView clickedButton = (ImageView) event.getSource();
                  Stage stage = (Stage) clickedButton.getScene().getWindow();
                  Task task =
                      new Task() {
                        @Override
                        protected Object call() throws Exception {
                          mainController.mainApp.scene.setCursor(Cursor.WAIT);
                          Serie toAdd = new Serie(clickedButton.getId());
                          boolean possible = true;
                          for (Serie serie : mainController.getSeries()) {
                            if (serie.equals(toAdd)) possible = false;
                          }
                          if (possible) mainController.getSeries().add(toAdd);

                          try {
                            mainController.populateImagenes();
                            mainController.showDetallesMes(mainController.getMesActual());
                          } catch (Exception e) {
                            e.printStackTrace();
                          } finally {
                            mainController.mainApp.scene.setCursor(Cursor.DEFAULT);

                            return mainController.getSeries();
                          }
                        }
                      };
                  Thread th = new Thread(task);
                  th.setDaemon(true);
                  th.start();
                  stage.close();
                }
              });
          resultados.getChildren().add(resultadoActual);
        }
      } else {
        resultados.getChildren().add(new Label("La busqueda no obtuvo resultados"));
      }
    } catch (JSONException e) {
      e.printStackTrace();
    } catch (UnsupportedEncodingException ex) {
      Logger.getLogger(NewSerieController.class.getName()).log(Level.SEVERE, null, ex);
    }
  }