Beispiel #1
0
  @Override
  public void start(Stage stage) throws Exception {
    this.primaryStage = stage;
    primaryStage.setTitle("Matrix Digital Rain");

    Group root = new Group();
    Scene scene = new Scene(root, 1024, 768);
    scene.addEventHandler(
        KeyEvent.KEY_PRESSED,
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent keyEvent) {
            if (keyEvent.getCode() == KeyCode.F) {
              primaryStage.setFullScreen(!primaryStage.isFullScreen());
            }
            if (keyEvent.isControlDown() && keyEvent.getCode() == KeyCode.Q) {
              primaryStage.close();
            }
          }
        });

    Canvas canvas = new Canvas();
    canvas.widthProperty().bind(primaryStage.widthProperty());
    canvas.heightProperty().bind(primaryStage.heightProperty());

    final GraphicsContext gc = canvas.getGraphicsContext2D();
    gc.setFont(font);

    setupSimulation();

    new AnimationTimer() {
      @Override
      public void handle(long now) {
        update(now);

        gc.clearRect(0, 0, primaryStage.getWidth(), primaryStage.getHeight());
        gc.setFill(Color.rgb(0, 0, 1));
        gc.fillRect(0, 0, primaryStage.getWidth(), primaryStage.getHeight());

        int y = 0;
        int nbGlyphsPerRow = getNbGlyphsPerRow();
        int nbGlyphsPerColumn = getNbGlyphsPerColumn();

        for (int i = 0; i < nbGlyphsPerRow * nbGlyphsPerColumn; ++i) {
          gc.setFill(Color.rgb(0, path[i], 0));
          String text = String.valueOf(data[i]);
          gc.fillText(text, (i % nbGlyphsPerRow) * 12 + 1, y + 13);

          if (i % nbGlyphsPerRow == nbGlyphsPerRow - 1) {
            y += 12;
          }
        }
      }
    }.start();

    root.getChildren().add(canvas);

    primaryStage.setScene(scene);
    primaryStage.show();
  }
Beispiel #2
0
  @Override
  public void start(Stage ps) throws Exception {
    window = ps;
    control = new WindowControl();

    music = new MediaPlayer(new Media(Util.getResource("music.mp3").toString()));
    breakSound = new MediaPlayer(new Media(Util.getResource("asteroid_break.mp3").toString()));
    explosionSound = new MediaPlayer(new Media(Util.getResource("explosion.mp3").toString()));

    window.setTitle("Asteroids: Space adventure - By macjuul");

    Image icon_128 = Util.getImage("icon_128.png");
    Image icon_32 = Util.getImage("icon_32.png");
    Image icon_16 = Util.getImage("icon_16.png");

    window.getIcons().addAll(icon_128, icon_32, icon_16);

    window.setMinWidth(WIDTH);
    window.setMinHeight(HEIGHT);
    window.setWidth(WIDTH);
    window.setHeight(HEIGHT);

    Parent layout = (Parent) control.loadLayout();

    Scene s = new Scene(layout);

    // Set our stylesheet
    s.getStylesheets().add(Util.getResource("window/style.css").toExternalForm());

    s.setCursor(Cursor.CROSSHAIR);

    window.setScene(s);

    window
        .widthProperty()
        .addListener(
            (ObservableValue<? extends Number> ov, Number oldN, Number newN) -> {
              WIDTH = newN.intValue();

              updateDimensions(true);
            });

    window
        .heightProperty()
        .addListener(
            (ObservableValue<? extends Number> ov, Number oldN, Number newN) -> {
              HEIGHT = (int) newN.intValue();

              updateDimensions(true);
            });

    // Open the window
    window.show();

    window.setOnCloseRequest(
        e -> {
          Platform.exit();
          System.exit(0);
        });
  }
Beispiel #3
0
 protected static void adjustHeight(final Stage s, final ScrollBar sb, final VBox vb) {
   s.heightProperty()
       .addListener(
           new ChangeListener<Number>() {
             public void changed(
                 ObservableValue<? extends Number> obervable, Number oldValue, Number newValue) {
               Double height = (Double) newValue;
               vb.setPrefHeight(height);
               sb.setPrefHeight(height - 70);
               sb.setMax(height - 50);
             }
           });
 }
  /** Entry point for the JavaFX application. Configure &amp; show the stage. */
  @Override
  public void start(Stage primaryStage) {

    primaryStage.setTitle("CSSem - Lambda Expression Examples");

    primaryStage.setMinWidth(JavaFXClass.MIN_WIDTH);
    primaryStage.setMaxWidth(JavaFXClass.MAX_WIDTH);
    primaryStage.setMinHeight(JavaFXClass.MIN_HEIGHT);
    primaryStage.setMaxHeight(JavaFXClass.MAX_HEIGHT);

    primaryStage.setScene(new Scene(this.layout));

    Runnable stageResized =
        () -> this.stageResized(primaryStage.getWidth(), primaryStage.getHeight());
    ChangeListener<? super Number> widthHeightListener = (v, o, n) -> stageResized.run();
    primaryStage.widthProperty().addListener(widthHeightListener);
    primaryStage.heightProperty().addListener(widthHeightListener);

    primaryStage.show();
    primaryStage.centerOnScreen();
    stageResized.run();
  }
  /**
   * Lance l'application
   *
   * @param primaryStage objet père qui contient la fenetre principale
   */
  @Override
  public void start(Stage primaryStage) throws Exception {

    // Chargement de la fenetre principale
    FXMLLoader fxmlLoader =
        new FXMLLoader(getClass().getClassLoader().getResource("fxml/VuePrincipale.fxml"));
    BorderPane root = fxmlLoader.load();
    VuePrincipale vuePrincipaleControleur = (VuePrincipale) fxmlLoader.getController();

    // Création du controleur de l'application
    Controleur controleurApplication = new Controleur();

    // Passage du controleur de l'application au controleur de la vue
    vuePrincipaleControleur.setControleurApplication(controleurApplication);
    vuePrincipaleControleur.setVueGraphiqueControleurApplication(controleurApplication);
    vuePrincipaleControleur.initialiserObserveurs();

    // Chargement de la vue des livraison
    FXMLLoader fxmlLoader2 =
        new FXMLLoader(getClass().getClassLoader().getResource("fxml/VueTextuelle.fxml"));
    AnchorPane anchorPane = fxmlLoader2.load();
    VueTextuelle vueTextuelle = (VueTextuelle) fxmlLoader2.getController();
    vueTextuelle.setAideurVueGraphique(vuePrincipaleControleur.getAideurVueGraphique());
    vueTextuelle.setControleurApplication(controleurApplication);
    vueTextuelle.initialiserObserveurs();

    BorderPane centerBorderPane = (BorderPane) root.getCenter();
    centerBorderPane.setLeft(anchorPane.getChildren().get(0));

    primaryStage.setTitle("Optimod'Lyon");
    primaryStage.setScene(new Scene(root, LARGEUR_FENETRE, HAUTEUR_FENETRE));
    primaryStage.setMinWidth(LARGEUR_FENETRE);
    primaryStage.setMinHeight(HAUTEUR_FENETRE);

    primaryStage.widthProperty().addListener(vuePrincipaleControleur.ecouteurDeRedimensionnement);
    primaryStage.heightProperty().addListener(vuePrincipaleControleur.ecouteurDeRedimensionnement);

    primaryStage.show();
  }
Beispiel #6
0
  @Override
  public void start(Stage theStage) {
    this.tStage = theStage;
    theStage.setTitle("Ball of Duty");
    theStage.setHeight(WINDOW_START_HEIGHT);
    theStage.setWidth(WINDOW_START_WIDTH);
    theStage.centerOnScreen();
    theStage.setResizable(false);
    theStage.setOnCloseRequest(
        new EventHandler<WindowEvent>() {
          public void handle(WindowEvent we) {
            gameManager.quitGame();
            System.exit(0);
          }
        });

    BorderPane startMenuRoot = new BorderPane();
    startMenu = new Scene(startMenuRoot);

    gameBox = new BorderPane();
    Scene gameScene = new Scene(gameBox);

    BorderPane createAccountRoot = new BorderPane();
    BorderPane lohInRoot = new BorderPane();

    theStage.setScene(startMenu);

    gameManager = new GameClient(getRelativeSceneLocation(theStage));

    scale = new Scale();
    scale.xProperty().bind(gameScene.widthProperty().divide(WINDOW_START_WIDTH));
    scale.yProperty().bind(gameScene.heightProperty().divide(WINDOW_START_HEIGHT));
    scale.setPivotX(0);
    scale.setPivotY(0);
    // gameBox.getTransforms().add(scale);
    // gameBox.setBackground(null);
    // TODO scaling

    theStage
        .heightProperty()
        .addListener(
            e -> {
              gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); // This
              // only
              // happens
              // once
              // for
              // some
              // reason.
            });
    theStage
        .widthProperty()
        .addListener(
            e -> {
              gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage));
            });
    theStage
        .xProperty()
        .addListener(
            e -> {
              gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage));
            });
    theStage
        .yProperty()
        .addListener(
            e -> {
              gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage));
            });
    gameScene
        .xProperty()
        .addListener(
            e -> {
              gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage));
            });
    gameScene
        .yProperty()
        .addListener(
            e -> {
              gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage));
            });
    Image image = new Image("images/frontpage.png");
    BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, false);
    // new BackgroundImage(image, repeatX, repeatY, position, size)
    BackgroundImage backgroundImage =
        new BackgroundImage(
            image,
            BackgroundRepeat.REPEAT,
            BackgroundRepeat.NO_REPEAT,
            BackgroundPosition.CENTER,
            backgroundSize);
    // new Background(images...)
    Background background = new Background(backgroundImage);
    startMenuRoot.setBackground(background);

    RadioButton chooseBlaster = new RadioButton("Blaster");
    RadioButton chooseRoller = new RadioButton("Roller");
    RadioButton chooseHeavy = new RadioButton("Heavy");

    final ToggleGroup specializationGroup = new ToggleGroup();

    chooseBlaster.setToggleGroup(specializationGroup);
    chooseRoller.setToggleGroup(specializationGroup);
    chooseHeavy.setToggleGroup(specializationGroup);

    chooseBlaster.setSelected(true);

    HBox specializationBox = new HBox();
    specializationBox.setSpacing(9);
    specializationBox.getChildren().add(chooseBlaster);
    specializationBox.getChildren().add(chooseRoller);
    specializationBox.getChildren().add(chooseHeavy);

    Label lblNickname = new Label("Nickname:");
    TextField tfNickname = new TextField();
    Button loginStart = new Button("Log in");
    Button createStart = new Button("Create Account");
    theStage.getIcons().add(new Image("images/ball_red.png"));
    VBox mainButtonBox = new VBox();
    mainButtonBox.setSpacing(5);
    Button joinBtn = new Button("Join game");

    Button viewLB = new Button("Leaderboard");
    viewLB.setPrefSize(150, 50);
    viewLB.setId("viewLB");
    viewLB.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");

    BorderPane lbBorder = new BorderPane();
    VBox lbBox = new VBox();
    Scene lbScene = new Scene(lbBorder);

    Button lbBack = new Button("Start menu");
    lbBox.getChildren().add(lbBack);
    lbBorder.setLeft(lbBox);
    lbBack.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");

    Label topText = new Label("Only shows scores higher than 100!");
    topText.setStyle("-fx-font-size: 20pt;-fx-font-family: Segoe UI Semibold;");

    viewLB.setOnAction(
        ActionEvent -> {
          HighscoreLeaderboard hBoard = gameManager.getHighscoreLeaderboard();
          hBoard.setFocusTraversable(false);
          lbBorder.setCenter(hBoard);
          if (gameManager.getPlayer() != null) {
            Player client = gameManager.getPlayer();
            Label you =
                new Label(
                    "YOU:    "
                        + client.getNickname()
                        + " ["
                        + client.getId()
                        + "]    | Score: "
                        + client.getHighscore());

            you.setStyle("-fx-font-size: 15pt;-fx-font-family: Segoe UI Semibold;");
            lbBorder.setBottom(you);
          }

          BorderPane.setMargin(hBoard, new Insets(12, 12, 12, 12));

          lbBorder.setTop(topText);
          theStage.setScene(lbScene);

          lbBack.setOnAction(
              ActionEvent1 -> {
                theStage.setScene(startMenu);
                startMenuRoot.setLeft(mainButtonBox);

                BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150));
              });
        });

    joinBtn.setPrefSize(150, 50);
    tfNickname.setPrefSize(150, 20);
    joinBtn.setId("joinBtn");
    joinBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");
    lblNickname.setId("lblNickname");
    lblNickname.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");
    createStart.setId("CreateStart");
    createStart.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");
    loginStart.setId("loginStart");
    loginStart.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");

    joinBtn.setOnAction(
        ActionEvent -> {
          Specializations spec;
          if (chooseRoller.isSelected()) {
            spec = Specializations.ROLLER;
          } else if (chooseHeavy.isSelected()) {
            spec = Specializations.HEAVY;
          } else // Blaster is default, if something goes wrong with radio
          // buttons
          {
            spec = Specializations.BLASTER;
          }

          theStage.setScene(gameScene);
          gameManager.joinAsGuest(gameBox, tfNickname.getText(), spec);
          gameManager.getMap().addObserver(this);
          gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage));
          gameBox.requestFocus();
        });
    tfNickname.setOnAction(
        ActionEvent -> {
          Specializations spec;
          if (chooseRoller.isSelected()) {
            spec = Specializations.ROLLER;
          } else if (chooseHeavy.isSelected()) {
            spec = Specializations.HEAVY;
          } else // Blaster is default, if something goes wrong with radio
          // buttons
          {
            spec = Specializations.BLASTER;
          }
          theStage.setScene(gameScene);
          gameManager.joinAsGuest(gameBox, tfNickname.getText(), spec);
          gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage));
          gameBox.requestFocus();
        });

    mainButtonBox.getChildren().add(lblNickname);
    mainButtonBox.getChildren().add(tfNickname);
    mainButtonBox.getChildren().add(specializationBox);
    mainButtonBox.getChildren().add(joinBtn);
    mainButtonBox.getChildren().add(loginStart);
    mainButtonBox.getChildren().add(createStart);
    mainButtonBox.getChildren().add(viewLB);
    startMenuRoot.setLeft(mainButtonBox);

    createStart.setOnAction(
        ActionEvent -> {
          VBox createAccountButtonBox = new VBox();
          Label lblNickname2 = new Label("Nickname:");
          TextField tfNickname2 = new TextField();
          Label lblUserName = new Label("Name:");
          TextField tfUserName = new TextField();
          Label lblPassword = new Label("Password:"******"Repeat password:"******"Create account");
          Button back = new Button("Start menu");

          createBtn.setId("join-yyyyy");
          createBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");
          lblUserName.setId("join-game");
          lblUserName.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");
          lblPassword.setId("join-game");
          lblPassword.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");
          lblPassword2.setId("join-game");
          lblPassword2.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");
          back.setId("join-game");
          back.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");

          createAccountButtonBox.getChildren().add(lblNickname2);
          createAccountButtonBox.getChildren().add(tfNickname2);
          createAccountButtonBox.getChildren().add(lblUserName);
          createAccountButtonBox.getChildren().add(tfUserName);
          createAccountButtonBox.getChildren().add(lblPassword);
          createAccountButtonBox.getChildren().add(pf);
          createAccountButtonBox.getChildren().add(lblPassword2);
          createAccountButtonBox.getChildren().add(pf2);
          createAccountButtonBox.getChildren().add(createBtn);
          createAccountButtonBox.getChildren().add(back);

          startMenuRoot.setLeft(createAccountButtonBox);
          BorderPane.setMargin(createAccountButtonBox, new Insets(350, 0, 0, 150));

          createBtn.setOnAction(
              ActionEvent1 -> {
                gameManager.createAccount(
                    tfUserName.getText(),
                    tfNickname2.getText(),
                    pf.getText().toCharArray(),
                    pf2.getText().toCharArray());
                startMenuRoot.setLeft(mainButtonBox);
                BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150));
              });

          back.setOnAction(
              ActionEvent1 -> {
                startMenuRoot.setLeft(mainButtonBox);
                BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150));
              });
        });

    loginStart.setOnAction(
        ActionEvent -> {
          VBox loginButtonBox = new VBox();
          Button logInBtn = new Button("Log in");
          Label lblUserName2 = new Label("Name:");
          TextField tfUserName2 = new TextField();
          Label lblPassword2 = new Label("Password:"******"Start Menu");

          logInBtn.setId("join-game");
          logInBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");
          back2.setId("join-game");
          back2.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;");

          loginButtonBox.getChildren().add(lblUserName2);
          loginButtonBox.getChildren().add(tfUserName2);
          loginButtonBox.getChildren().add(lblPassword2);
          loginButtonBox.getChildren().add(pf3);
          loginButtonBox.getChildren().add(logInBtn);
          loginButtonBox.getChildren().add(back2);

          startMenuRoot.setLeft(loginButtonBox);
          BorderPane.setMargin(loginButtonBox, new Insets(350, 0, 0, 150));

          logInBtn.setOnAction(
              ActionEvent1 -> {
                // TODO login
              });

          back2.setOnAction(
              ActionEvent1 -> {
                startMenuRoot.setLeft(mainButtonBox);
                BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150));
              });
        });

    BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150));

    Button quitBtn = new Button("Quit game");
    quitBtn.setPrefSize(80, 40);
    quitBtn.setId("quit-game");

    quitBtn.setOnAction(
        ActionEvent -> {
          gameManager.quitGame();
          theStage.setScene(startMenu);
        });

    canvas = new Canvas(CANVAS_START_WIDTH, CANVAS_START_HEIGHT);
    gameBox.setCenter(canvas);
    BorderPane.setAlignment(canvas, Pos.TOP_LEFT);

    gameBox.setBottom(quitBtn);
    BorderPane.setAlignment(quitBtn, Pos.TOP_LEFT);
    theStage.show();
  }