Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* A simple game, the mechanics not yet implemented.
- *
- * This is simply working on the title screen.
- */
- import java.io.File;
- import javafx.application.Application;
- import javafx.application.Platform;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Alert.AlertType;
- import javafx.scene.control.Button;
- import javafx.scene.control.ToggleButton;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.layout.Background;
- import javafx.scene.layout.BackgroundImage;
- import javafx.scene.layout.BackgroundSize;
- import javafx.scene.layout.VBox;
- import javafx.scene.media.Media;
- import javafx.scene.media.MediaPlayer;
- //import javafx.scene.paint.Color;
- import javafx.stage.Stage;
- public class MenuFX extends Application {
- @Override
- public void start (Stage primaryStage) {
- // Make the window a set size...
- primaryStage.setResizable(false);
- // Create media player
- // Rather than inputting the entire absolute URI, which would confine the program
- // to the creator's device, we create a new file, grab the URI on whatever machine
- // the program is running on and convert it to a string...
- // PORTABILITY!
- Media menuMusic = new Media(new File("music/menu.mp3").toURI().toString());
- MediaPlayer menuPlayer = new MediaPlayer(menuMusic);
- // Want to see the absolute URI? Uncomment the next line
- //System.out.println(new File("music/menu.mp3").toURI().toString());
- // Adjust the cycles and volume then start playing menu music
- // Lazy, but it will suffice
- menuPlayer.setCycleCount(999999999);
- menuPlayer.setVolume(0.2);
- menuPlayer.setAutoPlay(true);
- // Create menu vbox and set the background image
- VBox menuVBox = new VBox(30);
- menuVBox.setBackground(new Background(new BackgroundImage(new Image("image/bambooBG.jpg"), null, null, null, new BackgroundSize(45, 45, true, true, true, true))));
- // Create image object from logo image
- ImageView logoImage = new ImageView("image/tiles_logo.png");
- // Create new insets and set them to the image so it's farther away from the buttons
- Insets insetImage = new Insets(0, 0, 200, 0);
- VBox.setMargin(logoImage, insetImage);
- // Create start button
- Button startButton = new Button("Start Game");
- // TODO Call other classes and game stuff
- // Create help button
- Button helpButton = new Button("Help");
- // Create alert popup and bind it to the help button if player needs help- using a lambda handler
- Alert helpAlert = new Alert(AlertType.INFORMATION, "This game, tiles, will test your visual and fine-muscle acuity. When you begin a round, a 5x5 grid of tiles,"
- + " randomly placed, will appear. A timer will always be displayed at the top of the gamescreen. During this short, intense time, you must click all of"
- + " the white tiles, while avoiding the black tiles. Once a round is complete, a new round begins with a new grid of tiles. If you manage to complete "
- + "seven rounds, the game will shift to a 6x6 grid of tiles, with the same amount of time given. You must go until you fail. \n\nWhite tiles -"
- + " Click all of these! \nBlack tiles - Do not click these! \nGreen tiles - These add to your timer. \nRed tiles - These subtract from your timer.");
- helpButton.setOnAction(e -> helpAlert.showAndWait());
- // Create music toggle button
- ToggleButton musicButton = new ToggleButton("Music On/Off");
- // Toggle functionality... pause/play
- // Use lambda handler block
- musicButton.setOnAction(e -> {
- if (musicButton.isSelected()) {
- menuPlayer.pause();
- } else {
- menuPlayer.play();
- }
- });
- // Create credits button
- Button creditsButton = new Button("Credits");
- // Create alert popup and bind it to the credits button so players can see credits
- Alert creditsAlert = new Alert(AlertType.INFORMATION, "-CREDITS-");
- creditsButton.setOnAction(e -> creditsAlert.showAndWait());
- // Create exit button and set it to close the program when clicked, using a lambda handler
- Button endButton = new Button("Exit Game");
- endButton.setOnAction(e -> Platform.exit());
- // Add all nodes to the vbox pane and center it all
- // Must be in order from top to bottom
- menuVBox.getChildren().addAll(logoImage, startButton, helpButton, musicButton, creditsButton, endButton);
- menuVBox.setAlignment(Pos.CENTER);
- // New scene, place pane in it
- Scene scene = new Scene(menuVBox, 630, 730);
- // Place scene in stage
- primaryStage.setTitle("-tiles-");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- // Needed to run JavaFX w/o the use of the command line
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement