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);
//Eine Bühne schaffen
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("Würzig");
button[i].setPrefWidth(30);
button[i].setPrefHeight(30);
String txt=String.format("das ist\"Würzig\"ist.");
button[i].setOnAction(event->status.setText(txt));
}
int number=rnd.nextInt(144);
button[number]=new Button("Glücklicherweise");
button[number].setPrefWidth(30);
button[number].setPrefHeight(30);
txt2=String.format("\"Glücklicherweise\"Wurde angeklickt.");
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("Szenenwechsel abgeschlossen! !! !!");
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("Nächster");
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();
}
}
Ein Spiel, das aus einer großen Anzahl von "würzigen" Knöpfen nach einem "fröhlichen" Knopf sucht. Im Moment habe ich Probleme, weil der Bildschirmübergang nicht gut ist. In Zukunft haben wir Zeitlimits und Zählfunktionen hinzugefügt.