Пример #1
1
  private void playAudio(Media media) {
    if (mediaView.isVisible() == true) {
      mediaView.setVisible(false);
      display.setVisible(true);
    }
    if (mp != null) {
      mp.dispose();
    }

    mp = new MediaPlayer(media);
    mp.play();

    mp.setAudioSpectrumListener(
        (double timestamp, double duration1, float[] magnitudes, float[] phases) -> {
          display.getChildren().clear();
          int i = 0;
          int x = 10;
          double y = root.getScene().getHeight() / 2;
          Random rand = new Random(System.currentTimeMillis());
          for (float phase : phases) {
            int red = rand.nextInt(255);
            int green = rand.nextInt(255);
            int blue = rand.nextInt(255);
            Circle circle = new Circle(10);
            circle.setCenterX(x + i);
            circle.setCenterY(y + (phase * 100));
            circle.setFill(Color.rgb(red, green, blue, .70));
            display.getChildren().add(circle);
            i += 10;
          }
        });
  }
Пример #2
0
 private void check() {
   if (checkTile(0) == true
       && checkTile(1) == true
       && checkTile(2) == true
       && checkTile(3) == true
       && checkTile(4) == true
       && checkTile(5) == true
       && checkTile(6) == true
       && checkTile(7) == true
       && checkTile(8) == true
       && checkTile(9) == true
       && checkTile(10) == true
       && checkTile(11) == true
       && checkTile(12) == true
       && checkTile(13) == true
       && checkTile(14) == true) {
     done = true;
   }
   if (done == true && timer != 0) {
     timeline.stop();
     mv.setText("YOU WON !!!!!!!! IN :" + moves + " Moves");
     lvl.setText("Level : " + level);
     iv[15].setViewport(rct[16]);
     sp.setText("Next");
     mediaPlayer.stop();
     songName = new TextField("w.mp3");
     songPath =
         "C:\\Users\\Nihal\\Google Drive\\SCHOOL\\Java 2\\Programs\\JavaFinalProject\\src\\javafinalproject\\";
     MiniMP3Player();
     mediaPlayer.play();
     level++;
     sp.setOnAction(
         e -> {
           mediaPlayer.stop();
           songName = new TextField("s.mp3");
           songPath =
               "C:\\Users\\Nihal\\Google Drive\\SCHOOL\\Java 2\\Programs\\JavaFinalProject\\src\\javafinalproject\\";
           MiniMP3Player();
           mediaPlayer.stop();
           mediaPlayer.play();
           nextGame();
         });
   }
   if (timer == 0) {
     lvl.setText("Level : " + level);
     mv.setText("Sorry You Loose, Time out!!");
   }
   lvl.setText("Level : " + level);
   hc.setText("Your Score : " + ((level * 10) - 10) + " HS : " + getHS());
   setHS();
 }
Пример #3
0
  @FXML
  private void Play(MouseEvent event) {
    if (event.getButton() == MouseButton.PRIMARY) {
      if (j == 0) {
        listView.getSelectionModel().select(j);
        listView.getFocusModel().focus(j);
      }

      if (mp != null) {
        MediaPlayer.Status status = mp.getStatus();
        if (status == MediaPlayer.Status.UNKNOWN || status == MediaPlayer.Status.HALTED) {
          return;
        }
        if (status == MediaPlayer.Status.PAUSED
            || status == MediaPlayer.Status.READY
            || status == MediaPlayer.Status.STOPPED) {
          if (atEndOfMedia) {
            atEndOfMedia = false;
          }
          onPlay();
          mp.play();
          statusDisplay.toBack();
          play = true;

        } else {
          mp.pause();
          statusDisplay.toFront();
          play = false;
        }
      }
    }
  }
Пример #4
0
 public void PlaySound(String soundFileName) {
   if (soundIsOn) {
     Media sound = new Media(new File(soundFileName).toURI().toString());
     MediaPlayer mediaPlayer = new MediaPlayer(sound);
     mediaPlayer.play();
   }
 }
Пример #5
0
  private void playVideo(Media media) {
    timeProgress.setTextFill(Color.WHITE);
    npView.setVisible(true);
    mView.toBack();
    btnPaFull.setImage(new Image("icon/Full_button/full.png"));
    go = true;

    if (mediaView.isVisible() == false) {
      mediaView.setVisible(true);
      display.setVisible(false);
    }

    if (mp != null) {
      mp.dispose();
    }

    mp = new MediaPlayer(media);
    mediaView.setMediaPlayer(mp);
    mediaView.setPreserveRatio(true);

    final DoubleProperty width = mediaView.fitWidthProperty();
    final DoubleProperty height = mediaView.fitHeightProperty();

    width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
    height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));

    mp.play();
  }
Пример #6
0
 private static void playMp3(String name, boolean loop, double volume) {
   new javafx.embed.swing.JFXPanel();
   String uriString = new File(path + name).toURI().toString();
   MediaPlayer mp = new MediaPlayer(new Media(uriString));
   if (loop) {
     mp.setCycleCount(INDEFINITE);
   }
   mp.setVolume(volume);
   mp.play();
   mp3Map.put(name, mp);
 }
Пример #7
0
  public void play() {
    Status status = mediaPlayer.getStatus();
    if (status == Status.UNKNOWN || status == Status.HALTED) {
      // System.out.println("Player is in a bad or unknown state, can't play.");
      return;
    }

    if (status == Status.PAUSED || status == Status.STOPPED || status == Status.READY) {
      mediaPlayer.play();
    }
  }
Пример #8
0
 private void stopGame() {
   timeline.pause();
   done = true;
   sp.setOnMouseClicked(
       e -> {
         timeline.play();
         done = false;
         mediaPlayer.stop();
         mediaPlayer.play();
         sp.setOnMouseClicked(null);
       });
 }
  @Override
  public void start(final Stage primaryStage) {
    Start.create();
    menu = false;
    playTurn = false;
    URL u = getClass().getResource("start.mp3");
    bgm = new MediaPlayer(new Media(u.toString()));
    bgm.setCycleCount(MediaPlayer.INDEFINITE);
    bgm.play();
    root = new Group();
    Image title = new Image("fantasytactics/images/title.png", 720, 600, false, false);
    ImageView view = new ImageView(title);
    Image cursor = new Image("fantasytactics/images/cursor.png");
    final ImageView point = new ImageView(cursor);
    point.setX(165);
    point.setY(420);
    root.getChildren().add(view);
    root.getChildren().add(point);

    scene = new Scene(root, 720, 600);
    scene.setOnKeyPressed(
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent e) {
            switch (e.getCode()) {
              case DOWN:
                if (point.getY() == 420) {
                  point.setY(460);
                }
                break;
              case UP:
                if (point.getY() == 460) {
                  point.setY(420);
                }
                break;
              case ENTER:
                if (point.getY() == 420) {
                  newGame(primaryStage);
                } else if (point.getY() == 460) {
                  if (loadGame(primaryStage)) {
                    missionSelectPane(primaryStage);
                  } else {

                  }
                }
            }
          }
        });
    primaryStage.setTitle("Fantasy Tactics");
    primaryStage.setScene(scene);
    primaryStage.show();
  }
Пример #10
0
  public Player(String file) {
    media = new Media(file);
    player = new MediaPlayer(media);
    view = new MediaView(player);
    mpane = new Pane();
    mpane.getChildren().add(view);
    setCenter(mpane);

    bar = new MediaBar(player);

    setBottom(bar);
    setStyle("-fx-background-color: #bfc2c7");
    player.play();
  }
Пример #11
0
 @Override
 public void play() {
   if (player != null) {
     if (isPlaying) {
       player.pause();
       isPlaying = false;
       log.log(LogType.PLAYER, "Pause");
     } else {
       player.play();
       isPlaying = true;
       log.log(LogType.PLAYER, "Play");
     }
     UIManager.setPlayPauseIcon(isPlaying);
   }
 }
 public void start() {
   movie = new MediaPlayer(path);
   movie.play();
   VIEW.setMediaPlayer(movie);
   movie
       .currentTimeProperty()
       .addListener(
           new ChangeListener<javafx.util.Duration>() {
             @Override
             public void changed(
                 ObservableValue<? extends javafx.util.Duration> observable,
                 javafx.util.Duration duration,
                 javafx.util.Duration current) {
               timeSlider.setValue(current.toSeconds());
             }
           });
   movie.setOnReady(
       new Runnable() {
         @Override
         public void run() {
           timeSlider.setMin(0);
           timeSlider.setValue(0.0);
           timeSlider.setMax(movie.getTotalDuration().toSeconds());
           volumeSlider.setMin(0);
           volumeSlider.setValue(0.5);
         }
       });
   timeSlider.setOnMouseClicked(
       new EventHandler<MouseEvent>() {
         @Override
         public void handle(MouseEvent event) {
           movie.seek(javafx.util.Duration.seconds(timeSlider.getValue()));
         }
       });
   volumeSlider
       .valueProperty()
       .addListener(
           new InvalidationListener() {
             @Override
             public void invalidated(Observable observable) {
               if (volumeSlider.isValueChanging()) {
                 movie.setVolume(volumeSlider.getValue() / 100);
               }
             }
           });
 }
Пример #13
0
  private void iniGame() {

    getImage();
    moves = 0;
    ep = 15;
    for (int i = 0; i < 16; i++) {
      iv[i] = new ImageView(IMAGE);
      iv[i].setViewport(rct[i]);
      gpane.add(iv[i], i % 4, i / 4);
      String a = "" + i;
      iv[i].setId(a);
    }
    iv[15].setViewport(rct[16]);

    exit.setOnMouseClicked(
        e -> {
          System.out.println("Exit Successful");
          System.exit(1);
        });
    sp.setText("Start");
    sp.setOnMouseClicked(
        e -> {
          if (done != true) {
            iv[15].setViewport(rct[15]);
            randomPic();
            gameTimer();
            startClick();
            songName = new TextField("s.mp3");
            songPath =
                "C:\\Users\\Nihal\\Google Drive\\SCHOOL\\Java 2\\Programs\\JavaFinalProject\\src\\javafinalproject\\";
            MiniMP3Player();
            mediaPlayer.stop();
            mediaPlayer.play();
            sp.setOnMouseClicked(null);
          }
        });
    stop.setOnMouseClicked(
        e -> {
          stopGame();
          mediaPlayer.pause();
        });
  }
Пример #14
0
  public void open(PagedListEntry entry) {
    try {
      if (MediaManager.canPlayProtocol("https"))
        BackgroundLoader.addTaskWithTimeout(
            () -> {
              if (entry instanceof PlayList) {
                // expand inner playlists
                currentPlaylist.remove(entry);
                PagedList<PagedListEntry> innerPlaylist = ((PlayList) entry).getTrackList();
                currentPlaylist.addAll(playlistPosition, innerPlaylist);
                currentTrack = (Track) currentPlaylist.get(++playlistPosition);
              } else {
                currentTrack = (Track) entry;
              }
              String url = currentTrack.getStreamURL();

              currentMedia = new Media(url);
              stop();

              currentTrack.getWaveform().resetProgress();
              player = new MediaPlayer(currentMedia);

              player.volumeProperty().bindBidirectional(volumeSliderProb);
              player.setOnEndOfMedia(this::next);
              // TODO: append listener to new player
              player.setAudioSpectrumListener(audioSpectrumListener);

              player.play();
              isPlaying = true;

              UIManager.setTrackForPlayerUI(currentTrack, currentPlaylist);
              UIManager.setPlayPauseIcon(isPlaying);
            },
            3 * 1000);
    } catch (NoSuchMethodError error) {
      // the support came together with that method
      String version = com.sun.javafx.runtime.VersionInfo.getRuntimeVersion();
      log.log(LogType.PLAYER, "JavaFx version does not support https protocol");
      log.log(LogType.PLAYER, "Min version = 8.0.72. Current version " + version);
    }
  }
Пример #15
0
 void resume(Runnable callback) {
   if (player != null) {
     player.setVolume(0d);
     player.play();
     new Tween(player.getVolume())
         .tweenToValue(
             Settings.currentVolume,
             0.06,
             10L,
             (currentVolume) -> {
               player.setVolume(currentVolume);
             },
             (valueVolume) -> {
               player.setVolume(valueVolume);
               callback.run();
             });
     isPlaying = true;
   } else {
     callback.run();
   }
 }
Пример #16
0
 public void laser() {
   disposeSoundEffect();
   soundEffector = new MediaPlayer(laserSound);
   soundEffector.play();
 }
Пример #17
0
  @FXML
  void playTrack(Track t) {
    if (tweenBlock) return;
    tweenBlock = true;
    stop(
        () -> {
          currentPlaylist = (Playlist) playlistsView.getSelectionModel().getSelectedItem();
          currentTrack = t;
          if (player != null) {
            player.dispose();
          }
          if (t == null) {
            return;
          }
          timeUpdate = 9;
          if (currentPlaylist != null) {
            Tray.announce("[" + currentPlaylist.getTitle() + "] " + t.getTitle());
          }

          Platform.runLater(
              () -> {
                infoLabel.setText(res.getString("playing_offline") + t.getTitle());
                log.info("Playing offline: " + t.getTitle());
              });
          try {
            Media media = new Media(Cache.getContent(t).toURI().toString());
            player = new MediaPlayer(media);
            player.setVolume(Settings.currentVolume);
            player.play();
          } catch (MediaException ex) {
            Platform.runLater(
                () -> {
                  infoLabel.setText(
                      String.format(res.getString("cant_play_offline_not_exist"), t.getTitle()));
                  log.error("Can't play: seems that track does not exist - " + t.getTitle());
                });
          }

          if (player != null) {
            pushToPlayStack(getSelectedPlaylist(), t);
            player.setOnEndOfMedia(
                () -> {
                  String mode = Settings.currentMode;
                  if (mode.equals(Settings.MODE_NEXT)) {
                    playNext();
                  } else if (mode.equals(Settings.MODE_RANDOM)) {
                    playRandom();
                  } else if (mode.equals(Settings.MODE_SAME)) {
                    playSame();
                  }
                });
          }

          Platform.runLater(
              () -> {
                isPlaying = true;
                tweenBlock = false;
                titleLabel.setText(t.getTitle());
                stateButton.setGraphic(imagePause);
              });
        });
  }
  public void missionSelectPane(final Stage stage) {
    bgm.stop();
    URL u = getClass().getResource("menu.mp3");
    bgm = new MediaPlayer(new Media(u.toString()));
    bgm.setCycleCount(MediaPlayer.INDEFINITE);
    bgm.play();
    final Text dText = new Text("Game Saved");
    final Text aText = new Text("Game Was Not Saved");
    root = new Group();
    Button misSelect = new Button();
    misSelect.setLayoutX(100);
    misSelect.setLayoutY(100);
    final Text misText = new Text();
    misText.setText("Click to select the next Mission to go on");
    misText.setX(350);
    misText.setY(100);
    misSelect.setText("Mission Select");
    misSelect.setOnMouseEntered(
        new EventHandler() {
          @Override
          public void handle(Event e) {
            root.getChildren().remove(dText);
            root.getChildren().remove(aText);
            root.getChildren().add(misText);
          }
        });
    misSelect.setOnMouseExited(
        new EventHandler() {
          @Override
          public void handle(Event e) {
            root.getChildren().remove(misText);
          }
        });
    misSelect.setOnAction(
        new EventHandler() {
          @Override
          public void handle(Event e) {
            showMissions(stage);
          }
        });
    root.getChildren().add(misSelect);
    Button setUpC = new Button();
    setUpC.setText("Set Up Clan");
    final Text cText = new Text("Click here to prepare your clan members for battle");
    setUpC.setLayoutX(100);
    setUpC.setLayoutY(200);
    cText.setX(350);
    cText.setY(100);
    setUpC.setOnMouseEntered(
        new EventHandler() {
          @Override
          public void handle(Event e) {
            root.getChildren().remove(dText);
            root.getChildren().remove(aText);
            root.getChildren().add(cText);
          }
        });
    setUpC.setOnMouseExited(
        new EventHandler() {
          @Override
          public void handle(Event e) {
            root.getChildren().remove(cText);
          }
        });
    setUpC.setOnAction(
        new EventHandler() {
          @Override
          public void handle(Event e) {
            showMembers(stage);
          }
        });
    root.getChildren().add(setUpC);
    Button saveGame = new Button();
    final Text sText = new Text("Click Here To Save your Game");

    dText.setX(350);
    dText.setY(100);
    aText.setX(350);
    aText.setY(100);
    saveGame.setLayoutX(100);
    saveGame.setLayoutY(300);
    sText.setX(350);
    sText.setY(100);
    saveGame.setText("Save Game");
    saveGame.setOnMouseEntered(
        new EventHandler() {
          @Override
          public void handle(Event e) {
            root.getChildren().remove(dText);
            root.getChildren().remove(aText);
            root.getChildren().add(sText);
          }
        });
    saveGame.setOnMouseExited(
        new EventHandler() {
          @Override
          public void handle(Event e) {
            root.getChildren().remove(sText);
          }
        });
    saveGame.setOnAction(
        new EventHandler() {
          @Override
          public void handle(Event e) {
            if (saveGame()) {
              root.getChildren().add(dText);
            } else {
              root.getChildren().add(aText);
            }
          }
        });
    root.getChildren().add(saveGame);
    scene = new Scene(root, 720, 600);
    stage.setScene(scene);
    stage.show();
  }
  public void startMission(final Mission m, final Stage stage) {
    root = new Group();
    bgm.stop();
    URL u = getClass().getResource("battle.mp3");
    bgm = new MediaPlayer(new Media(u.toString()));
    bgm.setCycleCount(MediaPlayer.INDEFINITE);
    bgm.play();
    final BattleClan enemy = new BattleClan();
    final BattleClan player = new BattleClan();
    play = player;
    Image map = new Image("fantasytactics/images/" + m.mapName, m.width, m.height, false, false);
    ImageView mapView = new ImageView(map);
    mapView.setX(0);
    mapView.setY(0);

    root.getChildren().add(mapView);
    final Location[][] mapCoor = m.map;
    final ImageView cursor =
        new ImageView(new Image("fantasytactics/images/bcursor.png", 66, 98, false, false));
    cursorLoc = new Location(m.xLimit / 2, m.yLimit / 2);
    cursor.setX(mapCoor[cursorLoc.y][cursorLoc.x].x);
    cursor.setY(mapCoor[cursorLoc.y][cursorLoc.x].y);
    root.getChildren().add(cursor);
    for (Member i : m.enemy.members) {
      int index = m.enemy.members.indexOf(i);
      enemy.group.add(new BattleMem(1, i, m.enmapCoor[index], m.enCoor[index]));
    }
    for (Member i : curClan.members) {
      int index = curClan.members.indexOf(i);
      player.group.add(new BattleMem(0, i, m.playmapCoor[index], m.playCoor[index]));
    }
    final TurnOrder ord = new TurnOrder();
    ord.create(enemy.group, player.group);
    for (BattleMem i : enemy.group) {
      root.getChildren().add(i.anm.view);
    }

    for (BattleMem i : player.group) {
      root.getChildren().add(i.anm.view);
    }

    scene = new Scene(root, m.width, m.height);
    final Button mve = new Button("Move");
    final Button atk = new Button("Attack");
    final Button wait = new Button("Wait");
    mve.setLayoutX(m.width - 100);
    mve.setLayoutY(m.height - 200);
    atk.setLayoutX(m.width - 100);
    atk.setLayoutY(m.height - 150);
    wait.setLayoutX(m.width - 100);
    wait.setLayoutY(m.height - 100);
    mve.setOnAction(
        new EventHandler<ActionEvent>() {
          public void handle(ActionEvent e) {
            menu = false;
            root.getChildren().remove(mve);
            root.getChildren().remove(atk);
            root.getChildren().remove(wait);
            tiles = new ArrayList<ImageView>();
            range = displayRange(tiles, curMove, mapCoor, ord.order);
            root.getChildren().addAll(1, tiles);
            scene.setOnKeyPressed(
                new EventHandler<KeyEvent>() {
                  public void handle(KeyEvent e) {

                    if (e.getCode() == KeyCode.UP) {

                      if (cursorLoc.y >= 0) {

                        if (range.contains(mapCoor[cursorLoc.y - 1][cursorLoc.x])) {
                          cursorLoc.y--;
                        }
                      }
                    }
                    if (e.getCode() == KeyCode.DOWN) {
                      if (cursorLoc.y <= m.yLimit) {
                        if (range.contains(mapCoor[cursorLoc.y + 1][cursorLoc.x])) {
                          cursorLoc.y++;
                        }
                      }
                    }
                    if (e.getCode() == KeyCode.LEFT) {
                      if (cursorLoc.x >= 0) {
                        if (range.contains(mapCoor[cursorLoc.y][cursorLoc.x - 1])) {
                          cursorLoc.x--;
                        }
                      }
                    }
                    if (e.getCode() == KeyCode.RIGHT) {
                      if (cursorLoc.x <= m.xLimit) {
                        if (range.contains(mapCoor[cursorLoc.y][cursorLoc.x + 1])) {
                          cursorLoc.x++;
                        }
                      }
                    }
                    if (e.getCode() == KeyCode.ENTER) {
                      curMove.pixLoc = mapCoor[cursorLoc.y][cursorLoc.x];
                      curMove.mapLoc = new Location(cursorLoc.x, cursorLoc.y);
                      curMove.updatePosition();
                      menu = true;
                      mve.setDisable(true);
                      root.getChildren().removeAll(tiles);
                      root.getChildren().add(atk);
                      root.getChildren().add(wait);
                    }
                    cursor.setX(mapCoor[cursorLoc.y][cursorLoc.x].x);
                    cursor.setY(mapCoor[cursorLoc.y][cursorLoc.x].y);
                  }
                });
            e.consume();
          }
        });
    atk.setOnAction(
        new EventHandler<ActionEvent>() {
          public void handle(ActionEvent e) {
            root.getChildren().remove(mve);
            root.getChildren().remove(atk);
            root.getChildren().remove(wait);
            avail = displayAttackable(curMove, enemy);
            tiles = new ArrayList<ImageView>();
            Image t = new Image("fantasytactics/images/tile.png", 66, 98, false, false);
            if (!avail.isEmpty()) {
              for (BattleMem i : avail) {
                ImageView tile = new ImageView(t);
                tile.setX(i.pixLoc.x);
                tile.setY(i.pixLoc.y);
                tiles.add(tile);
              }
              root.getChildren().addAll(1, tiles);
              cursorLoc.x = avail.get(0).mapLoc.x;
              cursorLoc.y = avail.get(0).mapLoc.y;
              cursor.setX(mapCoor[cursorLoc.y][cursorLoc.x].x);
              cursor.setY(mapCoor[cursorLoc.y][cursorLoc.x].y);
              curSelection = 0;
              confirm = false;
              scene.setOnKeyPressed(
                  new EventHandler<KeyEvent>() {
                    public void handle(KeyEvent e) {
                      if (e.getCode() == KeyCode.UP) {
                        if (curSelection != avail.size() - 1) {
                          curSelection++;

                        } else {
                          curSelection = 0;
                        }
                      }
                      if (e.getCode() == KeyCode.DOWN) {
                        if (curSelection != 0) {
                          curSelection--;
                        }
                      }
                      if (e.getCode() == KeyCode.ENTER) {
                        if (confirm == false) {
                          BattleMem en = avail.get(curSelection);
                          root.getChildren().remove(name);
                          root.getChildren().remove(hp);
                          root.getChildren().remove(mp);
                          name = new Text(en.member.getName());
                          hp = new Text("HP:  " + en.curHP + "/" + en.member.getmaxHp());
                          mp = new Text("MP:  " + en.curMP + "/" + en.member.getmaxMp());
                          name.setFont(Font.font("Impact", 22));
                          hp.setFont(Font.font("Impact", 22));
                          mp.setFont(Font.font("Impact", 22));
                          name.setFill(Color.BLACK);
                          hp.setFill(Color.BLACK);
                          mp.setFill(Color.BLACK);
                          name.setX(0);
                          hp.setX(0);
                          mp.setX(0);
                          name.setY(m.height - 150);
                          hp.setY(m.height - 100);
                          mp.setY(m.height - 50);
                          root.getChildren().add(name);
                          root.getChildren().add(hp);
                          root.getChildren().add(mp);
                          dmg = new Text();
                          int def = en.member.getDef();
                          int aat = curMove.member.getAtk();
                          int damg = (aat - (def / 2)) / 2;
                          double prob = 1 - ((double) en.member.getEvade() / 100);
                          dmg.setText(
                              "Damage: " + damg + "   Chance to Hit: " + (prob * 100) + "%");
                          dmg.setFont(Font.font("Impact", 25));
                          dmg.setFill(Color.BLACK);
                          dmg.setX(m.width - 400);
                          dmg.setY(m.height - 100);

                          DropShadow ds = new DropShadow();
                          ds.setOffsetY(3.0f);
                          ds.setColor(Color.color(0.4f, 0.4f, 0.4f));
                          dmg.setEffect(ds);
                          root.getChildren().add(dmg);
                          dmg.toFront();
                          confirm = true;

                        } else {
                          root.getChildren().removeAll(tiles);
                          root.getChildren().remove(dmg);
                          curMove.executeAttack(avail.get(curSelection));
                          try {
                            Thread.sleep(400);
                          } catch (InterruptedException ex) {
                            Logger.getLogger(FantasyTactics.class.getName())
                                .log(Level.SEVERE, null, ex);
                          }
                          if (avail.get(curSelection).curHP <= 0) {
                            root.getChildren().remove(avail.get(curSelection).anm.view);
                            ord.order.remove(avail.get(curSelection));
                            enemy.group.remove(avail.get(curSelection));
                          }
                          attack = true;
                          turnEnd = true;
                        }
                      }
                      cursorLoc.x = avail.get(curSelection).mapLoc.x;
                      cursorLoc.y = avail.get(curSelection).mapLoc.y;
                      cursor.setX(mapCoor[cursorLoc.y][cursorLoc.x].x);
                      cursor.setY(mapCoor[cursorLoc.y][cursorLoc.x].y);
                    }
                  });

            } else {
              turnEnd = true;
            }
          }
        });
    wait.setOnAction(
        new EventHandler<ActionEvent>() {
          public void handle(ActionEvent e) {
            turnEnd = true;
            root.getChildren().remove(tiles);
          }
        });
    stage.setScene(scene);
    stage.show();

    curIndex = ord.order.size() - 1;
    turnEnd = true;
    timeline =
        new Timeline(
            new KeyFrame(
                Duration.millis(1000),
                new EventHandler() {
                  public void handle(Event e) {
                    if (!missionWon && !missionLose) {
                      if (turnEnd) {
                        if (enemy.group.size() == 0) {
                          missionWon = true;
                        } else if (player.group.size() == 0) {
                          missionLose = true;
                        }
                        for (BattleMem i : ord.order) {
                          if (i.curHP <= 0) {
                            root.getChildren().remove(i.anm.view);
                            ord.order.remove(i);
                            enemy.group.remove(i);
                            play.group.remove(i);
                            curIndex = 0;
                          }
                        }
                        if (curIndex == ord.order.size() - 1) {
                          curIndex = 0;
                        } else {
                          curIndex++;
                        }
                        root.getChildren().remove(mve);
                        root.getChildren().remove(atk);
                        root.getChildren().remove(wait);
                        curMove = ord.order.get(curIndex);
                        cursorLoc.x = curMove.mapLoc.x;
                        cursorLoc.y = curMove.mapLoc.y;
                        cursor.setX(mapCoor[cursorLoc.y][cursorLoc.x].x);
                        cursor.setY(mapCoor[cursorLoc.y][cursorLoc.x].y);
                        if (enemy.group.contains(curMove)) {
                          executeTurn(player, curMove, enemy);
                          try {
                            Thread.sleep(400);
                          } catch (InterruptedException ex) {
                            Logger.getLogger(FantasyTactics.class.getName())
                                .log(Level.SEVERE, null, ex);
                          }
                          turnEnd = true;
                        } else {
                          turnEnd = false;
                          root.getChildren().add(mve);
                          root.getChildren().add(atk);
                          root.getChildren().add(wait);
                          mve.setDisable(false);
                          move = false;
                          attack = false;

                          if (curMove.curMP >= curMove.member.getmaxMp() - 10) {
                            curMove.curMP = curMove.member.getmaxMp();
                          } else {
                            curMove.curMP += 10;
                          }
                          root.getChildren().remove(name);
                          root.getChildren().remove(hp);
                          root.getChildren().remove(mp);
                          name = new Text(curMove.member.getName());
                          hp = new Text("HP:  " + curMove.curHP + "/" + curMove.member.getmaxHp());
                          mp = new Text("MP:  " + curMove.curMP + "/" + curMove.member.getmaxMp());
                          name.setFont(Font.font("Impact", 22));
                          hp.setFont(Font.font("Impact", 22));
                          mp.setFont(Font.font("Impact", 22));
                          name.setFill(Color.BLACK);
                          hp.setFill(Color.BLACK);
                          mp.setFill(Color.BLACK);
                          name.setX(0);
                          hp.setX(0);
                          mp.setX(0);
                          name.setY(m.height - 150);
                          hp.setY(m.height - 100);
                          mp.setY(m.height - 50);
                          root.getChildren().add(name);
                          root.getChildren().add(hp);
                          root.getChildren().add(mp);
                        }

                      } else {
                        if (move && attack) {
                          turnEnd = true;
                        }
                      }
                    } else {
                      if (missionWon) {
                        win();
                      } else if (missionLose) {
                        lose();
                      }
                    }

                    for (int i = m.xLimit; i >= 0; i--) {
                      for (BattleMem j : ord.order) {
                        if (j.mapLoc.x == i) {
                          j.toFront();
                        }
                      }
                    }
                  }
                }));
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();
  }
Пример #20
0
 public void gun() {
   disposeSoundEffect();
   soundEffector = new MediaPlayer(gunSound);
   soundEffector.play();
 }
  public static void createStartTownSaloonView() {
    GridPane gridPane = new GridPane();

    gridPane.setHgap(2);
    gridPane.setVgap(2);
    gridPane.setId("saloonGridBackground");

    Button backBtn = new Button("Back");
    backBtn.setId("mainScreenBtn");
    gridPane.add(backBtn, 0, 0);

    URL url =
        StartTownSaloonView.class.getClassLoader().getResource("resources/saloonPianoMusic.mp3");
    assert url != null;
    final Media media = new Media(url.toString());
    final MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaPlayer.setVolume(25);
    mediaPlayer.setCycleCount(99);
    mediaPlayer.play();

    Scene scene =
        new Scene(
            gridPane,
            Main.getPrimaryStage().getScene().getWidth(),
            Main.getPrimaryStage().getScene().getHeight());

    scene.getStylesheets().add("resources/main.css");

    ArrayList<Tooltip> tooltipArrayList = new ArrayList<>();

    AddKeyListenerToScene.addGeneralKeyListener(scene);
    /**
     * Need to add a bunch of collision detection rectangles for clicking on people and getting a
     * toolip to popup.
     */
    scene.setOnMouseClicked(
        event -> {
          double x = event.getX();
          double y = event.getY();
          for (Tooltip eraseTooltip : tooltipArrayList) {
            eraseTooltip.hide();
          }

          if (x >= 767.0 && x <= 814.0 && y >= 378.0 && y <= 461.0) {
            Tooltip bartender = new Tooltip("What can I get ya?");
            bartender.setId("startTownSaloonTooltip");
            bartender.show(
                gridPane, 776.0 + scene.getWindow().getX(), 407.0 + scene.getWindow().getY());
            tooltipArrayList.add(bartender);
          }
          if (x >= 687.0 && x <= 759.0 && y >= 387.0 && y <= 507.0) {
            Tooltip oldManAtTheBar =
                new Tooltip("Whiskey, Mmm Mmm Mmm down to my belly, yum yum yum...*hiccup*");
            oldManAtTheBar.setId("startTownSaloonTooltip");
            oldManAtTheBar.show(
                gridPane, 745.0 + scene.getWindow().getX(), 432.0 + scene.getWindow().getY());
            tooltipArrayList.add(oldManAtTheBar);
          }
          if (x >= 43.0 && x <= 102.0 && y >= 330.0 && y <= 545.0) {
            Tooltip banjoPlayerInBack = new Tooltip("Yoddle yoddleeeee yoddleeeeheeeehoooo...");
            banjoPlayerInBack.setId("startTownSaloonTooltip");
            banjoPlayerInBack.show(
                gridPane, 83.0 + scene.getWindow().getX(), 356.0 + scene.getWindow().getY());
            tooltipArrayList.add(banjoPlayerInBack);
          }
          if (x >= 606.0 && x <= 662.0 && y >= 383.0 && y <= 688.0) {
            Tooltip secretAlienTechHintDude =
                new Tooltip(
                    "I was out in the fields...staring\n"
                        + "at the sky when suddenly a huge blinding\n"
                        + "light shot up from the ground. Aliens man\n"
                        + "I hope they left something behind for me to\n"
                        + "find!");
            secretAlienTechHintDude.setId("startTownSaloonTooltip");
            secretAlienTechHintDude.show(
                gridPane, 645.0 + scene.getWindow().getX(), 428.0 + scene.getWindow().getY());
            tooltipArrayList.add(secretAlienTechHintDude);
          }
          if (x >= 923.0 && x <= 1029.0 && y >= 385.0 && y <= 752.0) {
            Tooltip guyHittingOnGirlOnRight = new Tooltip("Sup baby gurrllllll");
            guyHittingOnGirlOnRight.setId("startTownSaloonTooltip");
            guyHittingOnGirlOnRight.show(
                gridPane, 952.0 + scene.getWindow().getX(), 427.0 + scene.getWindow().getY());
            tooltipArrayList.add(guyHittingOnGirlOnRight);
          }

          /**
           * Set listeners for window drags. If user drags the window then hide all the tooltips or
           * they will stay where they are until user hides them with the other commands. Aesthetics
           * only really.
           */
          scene
              .getWindow()
              .xProperty()
              .addListener(
                  (observable, oldValue, newValue) -> {
                    for (Tooltip eraseTooltip : tooltipArrayList) {
                      eraseTooltip.hide();
                    }
                  });
          scene
              .getWindow()
              .yProperty()
              .addListener(
                  (observable, oldValue, newValue) -> {
                    for (Tooltip eraseTooltip : tooltipArrayList) {
                      eraseTooltip.hide();
                    }
                  });

          // System.out.println(event.getX());
          // System.out.println(event.getY());
        });

    backBtn.setOnAction(
        event -> {
          Main.getPrimaryStage().setScene(StartingTownView.getStartingTownView());
          mediaPlayer.stop();
          for (Tooltip eraseTooltip : tooltipArrayList) {
            eraseTooltip.hide();
            eraseTooltip = null;
          }
        });

    setStartSaloon(scene);
    Main.getPrimaryStage().setScene(scene);
  }
Пример #22
0
 void playSame() {
   player.seek(Duration.ZERO);
   player.play();
 }
Пример #23
0
  @Override
  public void start(Stage primaryStage) {

    VBox loginPane = new VBox();
    loginPane.setAlignment(Pos.CENTER);
    primaryStage.setTitle("Amoeba");
    primaryStage.setScene(new Scene(loginPane, 800, 600));
    primaryStage.show();

    TextField username = new TextField();
    username.setPromptText("Username");
    username.setMaxSize(200, 50);

    Timeline renderTimer = new Timeline();
    Timeline inputTimer = new Timeline();

    ColorPicker colorPicker = new ColorPicker();
    colorPicker.setEditable(true);
    colorPicker.setValue(Color.BLACK);

    lagLabel.setTranslateX(25);
    lagLabel.setTranslateY(10);
    lagLabel.setTextFill(Color.RED);

    TextField address = new TextField("localhost");
    address.setPromptText("Server IP Address");
    address.setMaxSize(200, 50);

    TextField port = new TextField("8080");
    port.setPromptText("Port Number");
    port.setMaxSize(200, 50);

    Button btn = new Button("Play");
    btn.setDefaultButton(true);

    loginPane.getChildren().addAll(username, colorPicker, address, port, btn);

    primaryStage.setResizable(false);
    music.setCycleCount(MediaPlayer.INDEFINITE);
    renderPane.setBackground(new Background(backgroundImage));
    renderPane.setPrefSize(800, 600);

    chatBox.setPrefSize(400, 100);
    chatBox.setTranslateX(0);
    chatBox.setTranslateY(468);
    chatBox.setWrapText(true);
    chatBox.setEditable(false);
    chatBox.setStyle("-fx-opacity: 0.5");

    chatInput.setPrefSize(400, 10);
    chatInput.setTranslateX(0);
    chatInput.setTranslateY(570);
    chatInput.setStyle("-fx-opacity: 0.8");

    highScores.setPrefSize(400, 210);
    highScores.setEditable(false);
    currentScores.setPrefSize(400, 250);
    currentScores.setEditable(false);
    currentScores.setLayoutY(210);
    scores.setTranslateX(-390);
    scores.setTranslateY(0);
    scores.setStyle("-fx-opacity: 0.8");

    scores.setOnMouseEntered(
        (e) -> {
          scores.setTranslateX(0);
        });

    scores.setOnMouseExited(
        (e) -> {
          if (e.getX() > 350) {
            scores.setTranslateX(-390);
          }
        });

    btn.setOnAction(
        (e) -> {
          if (!networkController.isConnected()) {
            networkController.connect(address.getText(), Integer.parseInt(port.getText()));
            if (username.getText().isEmpty()) {
              username.setText("Anonymous");
            }
            networkController.sendMessage(new LoginMessage(username.getText(), ""));

            ArrayList<KeyValuePair> properties = new ArrayList<>();
            properties.add(new KeyValuePair("color", colorPicker.getValue().toString()));
            networkController.sendMessage(new SetBlobPropertiesMessage(properties));

            primaryStage.setScene(new Scene(renderPane));
            renderTimer.play();
            inputTimer.play();
            music.play();
          }
        });

    inputTimer.setCycleCount(Timeline.INDEFINITE);
    inputTimer
        .getKeyFrames()
        .add(
            new KeyFrame(
                Duration.seconds(0.05),
                (e) -> {
                  if (sendCoordinates) {
                    networkController.sendMessage(new MoveTowardCoordinatesMessage(x, y));
                  }
                }));

    renderTimer.setCycleCount(Timeline.INDEFINITE);
    renderTimer
        .getKeyFrames()
        .add(
            new KeyFrame(
                Duration.seconds(0.01),
                (e) -> {
                  render();
                }));

    renderPane.setOnMouseReleased(
        (e) -> {
          this.sendCoordinates = false;
        });

    renderPane.setOnMouseDragged(
        (e) -> {
          this.sendCoordinates = true;
          this.x = e.getX();
          this.y = e.getY();
        });

    renderPane.setOnMouseClicked(
        (e) -> {
          if (e.getButton() == MouseButton.SECONDARY) {
            networkController.sendMessage(new BoostMessage());
          } else if (e.getClickCount() > 1 || e.getButton() == MouseButton.MIDDLE) {
            networkController.sendMessage(new SplitMessage());
          }
        });

    renderPane.setOnKeyPressed(
        (e) -> {
          if (e.getCode().equals(KeyCode.ENTER) && !chatInput.getText().isEmpty()) {
            networkController.sendMessage(new ChatMessage("", chatInput.getText()));
            chatInput.clear();
          }
        });

    primaryStage.setOnCloseRequest(
        (e) -> {
          networkController.sendMessage(new LogoutMessage());
          try {
            Thread.sleep(100);
          } catch (InterruptedException ex) {
            Logger.getLogger(AmoebaClient.class.getName()).log(Level.WARNING, null, ex);
          } finally {
            System.exit(0);
          }
        });
  }
Пример #24
0
 @Override
 public void playAudio(Object o) {
   Media music = myMusic.get(o).getMusic();
   myMusician = new MediaPlayer(music);
   myMusician.play();
 }
Пример #25
0
  public void animazione(int lancioCorrente, boolean flag) {
    mediaPlayer = new MediaPlayer(media);
    mediaPlayer.play();

    setPrimo((int) ((Math.random() * 6) + 1));
    RotateTransition rt1 = new RotateTransition(Duration.millis(60), imageViewUno);

    rt1.setFromAngle(0.0);
    rt1.setToAngle(360.0);
    rt1.setCycleCount(2);
    rt1.setAutoReverse(true);
    rt1.setAxis(Rotate.X_AXIS);

    rt1.play();

    rt1.setOnFinished(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {

            setPrimo((int) ((Math.random() * 6) + 1));
            RotateTransition rt2 = new RotateTransition(Duration.millis(durata), imageViewUno);

            rt2.setFromAngle(0.0);
            rt2.setToAngle(360.0);
            rt2.setCycleCount(2);
            rt2.setAutoReverse(true);
            rt2.setAxis(Rotate.X_AXIS);

            rt2.play();

            rt2.setOnFinished(
                new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent event) {

                    setPrimo((int) ((Math.random() * 6) + 1));
                    RotateTransition rt3 =
                        new RotateTransition(Duration.millis(durata), imageViewUno);

                    rt3.setFromAngle(0.0);
                    rt3.setToAngle(360.0);
                    rt3.setCycleCount(2);
                    rt3.setAutoReverse(true);
                    rt3.setAxis(Rotate.Y_AXIS);

                    rt3.play();

                    rt3.setOnFinished(
                        new EventHandler<ActionEvent>() {

                          @Override
                          public void handle(ActionEvent event) {

                            setPrimo((int) ((Math.random() * 6) + 1));
                            RotateTransition rt4 =
                                new RotateTransition(Duration.millis(durata), imageViewUno);

                            rt4.setFromAngle(0.0);
                            rt4.setToAngle(360.0);
                            rt4.setCycleCount(2);
                            rt4.setAutoReverse(true);
                            rt4.setAxis(Rotate.Y_AXIS);

                            rt4.play();

                            rt4.setOnFinished(
                                new EventHandler<ActionEvent>() {

                                  @Override
                                  public void handle(ActionEvent event) {

                                    setPrimo((int) ((Math.random() * 6) + 1));
                                    RotateTransition rt5 =
                                        new RotateTransition(Duration.millis(durata), imageViewUno);

                                    rt5.setFromAngle(0.0);
                                    rt5.setToAngle(360.0);
                                    rt5.setCycleCount(2);
                                    rt5.setAutoReverse(true);
                                    rt5.setAxis(Rotate.Z_AXIS);

                                    rt5.play();

                                    rt5.setOnFinished(
                                        new EventHandler<ActionEvent>() {

                                          @Override
                                          public void handle(ActionEvent event) {

                                            setPrimo((int) ((Math.random() * 6) + 1));
                                            RotateTransition rt6 =
                                                new RotateTransition(
                                                    Duration.millis(durata), imageViewUno);

                                            rt6.setFromAngle(0.0);
                                            rt6.setToAngle(360.0);
                                            rt6.setCycleCount(2);
                                            rt6.setAutoReverse(true);
                                            rt6.setAxis(Rotate.Z_AXIS);

                                            rt6.play();

                                            rt6.setOnFinished(
                                                new EventHandler<ActionEvent>() {
                                                  @Override
                                                  public void handle(ActionEvent event) {
                                                    setPrimo(lancioCorrente);
                                                    if (flag) {
                                                      gm.turnoSuccessivo(lancioCorrente);
                                                      System.err.println("1 CASO");
                                                    } else {
                                                      ((GameManagerNetwork) gm)
                                                          .turnoSuccessivoDiRichiesta(
                                                              lancioCorrente);
                                                      System.err.println("2 CASO");
                                                    }
                                                  }
                                                });
                                          }
                                        });
                                  }
                                });
                          }
                        });
                  }
                });
          }
        });
  }
 @FXML
 public void playButton(ActionEvent event) {
   movie.play();
 }