I tried to make a simple game with Javafx ① "Let's find happiness game" (unfinished)

I made a simple game with Javafx ①

"Let's find happiness game" (unfinished)

sample.java


package happy_unhappy_game;

import java.util.Random;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;


	public class Sample extends Application {

		public static void main(String[]args) {
			launch();
		}

		 public static Scene scene1 = null;
		 public static Scene scene2 = null;

		 public static String txt=null;
		 public static String txt2=null;
    	 public static Label status=new Label();
    	 public static Button btn2 =null;
    	 public static VBox root=new VBox();
    	 public static TilePane pane=new TilePane();



    @Override
    public void start(Stage stage) throws Exception {

    	stage.setTitle("main");
    	stage.setWidth(380);
    	stage.setHeight(500);
    	  //Creating a stage
    	initScene2(stage);
    	initScene1(stage);

    	stage.setScene(scene1);
    	stage.show();
    }

    public static void initScene1(Stage stage){
    	stage.setWidth(380);
    	stage.setHeight(500);
    	stage.setTitle("1");

    	Random rnd=new Random();

    	Button button[]=new Button[144];
    	for(int i=0;i<144;i++) {
    		button[i]=new Button("Spicy");
    		button[i].setPrefWidth(30);
    		button[i].setPrefHeight(30);
    		String txt=String.format("that is\"Spicy\"is.");
    		button[i].setOnAction(event->status.setText(txt));
    	}

    		int number=rnd.nextInt(144);
			button[number]=new Button("Fortunately");
    		button[number].setPrefWidth(30);
    		button[number].setPrefHeight(30);
    		txt2=String.format("\"Fortunately\"Was clicked.");
    		button[number].setOnAction(event->push(stage));

    	pane=new TilePane();
    	pane.getChildren().addAll(button);

    	root=new VBox();
    	root.getChildren().addAll(pane,status);

    	scene1=new Scene(root);
    }


    public static void initScene2(Stage stage) {
    	stage.setWidth(380);
    	stage.setHeight(500);
    	stage.setTitle("2");

    	Button btn = new Button("Scene change completed! !! !!");
    	    btn.setPrefWidth(100);
    	    btn.setPrefHeight(50);
    	    btn.setOnMouseClicked(event -> setScene2(stage,scene1));

    	    AnchorPane root = new AnchorPane();
    	    root.getChildren().add(btn);
    	    scene2 = new Scene(root);

    }

    public static void push(Stage stage) {
    	status.setText(txt2);
    	btn2 = new Button("next");
		btn2.setPrefWidth(100);
		btn2.setPrefHeight(50);
		btn2.setOnMouseClicked(event -> setScene(stage,scene2));
    	root.getChildren().addAll(btn2);
    }

    public static  void setScene(Stage stage,Scene changeScene) {
        stage.setScene(changeScene);
        stage.show();
     }

    public static  void setScene2(Stage stage,Scene changeScene) {
	    stage.setScene(changeScene);
	    stage.show();
	  }

 	}



Outline of the game and problems at this stage

A game that searches for one "good luck" button from a large number of "spicy" buttons. At the moment, I am struggling because the screen transition is not good. In the future, we have added a time limit and a counting function.

200625.gif

Recommended Posts

I tried to make a simple game with Javafx ① "Let's find happiness game" (unfinished)
I tried to make a group function (bulletin board) with Rails
A simple rock-paper-scissors game with JavaFX and SceneBuilder
I tried to break a block with java (1)
[Android] I tried to make a material list screen with ListView + Bottom Sheet
I tried to make a login function in Java
I want to make a function with kotlin and java!
Let's make a simple API with EC2 + RDS + Spring boot ①
I tried to make a client of RESAS-API in Java
I tried to create a padrino development environment with Docker
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
I tried to interact with Java
Make a typing game with ruby
[Unity] I tried to make a native plug-in UniNWPathMonitor using NWPathMonitor
I tried to build a simple application using Dockder + Rails Scaffold
I tried to make an Android application with MVC now (Java)
I wanted to make JavaFX programming easier with the Spring Framework
[Java] I tried to make a maze by the digging method ♪
I made a virtual currency arbitrage bot and tried to make money
I tried playing with BottomNavigationView a little ①
I tried to make a talk application in Java using AI "A3RT"
I tried to make a program that searches for the target class from the process that is overloaded with Java
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
[Java] I tried to connect using a connection pool with Servlet (tomcat) & MySQL & Java
I tried to automatically generate a class to convert from a data class to a Bundle with APT
I tried to clone a web application full of bugs with Spring Boot
[Small story] I tried to make the java ArrayList a little more convenient
[Android] I want to make QA easier ... That's right! Let's make a debug menu!
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I tried to create a LINE clone app
Let's make a search function with Rails (ransack)
I tried to link JavaFX and Spring Framework.
I tried to develop a website to record expenses.
I tried to implement a server using Netty
I tried to make a product price comparison tool of Amazon around the world with Java, Amazon Product Advertising API, Currency API (2017/01/29)
[Azure] I tried to create a Java application for free ~ Connect with FTP ~ [Beginner]
I tried to create a Clova skill in Java
I want to monitor a specific file with WatchService
Let's make a robot! "A simple demo of Java AWT Robot"
I tried to draw animation with Blazor + canvas API
I tried OCR processing a PDF file with Java
I tried to implement Stalin sort with Java Collector
Let's make a LINE Bot with Ruby + Sinatra --Part 1
I used to make nc (netcat) with JAVA normally
[Introduction to Android application development] Let's make a counter
I tried to find out what changed in Java 9
Implemented a strong API for "I want to display ~~ on the screen" with simple CQRS
Easy to make LINE BOT with Java Servlet Part 2: I tried image messages and templates
Make a simple CRUD with SpringBoot + JPA + Thymeleaf ① ~ Hello World ~
Learning Ruby with AtCoder 13 How to make a two-dimensional array
I tried to make Java Optional and guard clause coexist
I tried to link chat with Minecraft server with Discord API
[Rails] I tried to implement batch processing with Rake task
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I tried to convert a string to a LocalDate type in Java
I tried to implement a buggy web application in Kotlin
Make a simple CRUD with SpringBoot + JPA + Thymeleaf ⑤ ~ Template standardization ~
I tried OCR processing a PDF file with Java part2
I tried to get started with Swagger using Spring Boot
I tried to be able to pass multiple objects with Ractor