import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class GUI extends Application {

    @Override
    public void start(Stage stage) throws Exception {

        Parent root = FXMLLoader.load(getClass().getResource("gui.fxml"));

        Scene scene = new Scene(root);
        Controller con = new Controller();
        con.makespinner();

        // One could use CSS to style the GUI elements
        // scene.getStylesheets().add(getClass().getResource("gui.css").toString());

        stage.setTitle("SE SS21 MVC RNG");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

import java.util.Random;

/**
 * The game logic of the dice-guess-game
 */
public class Model {

    int randomNumber;
    private int numberOfTries;

    public Model(){
        dice();
    }

    public Correctness check(int num) throws IllegalArgumentException{

        if (num > 100 || num < 1) {
            throw new IllegalArgumentException();
        }

        if (num > randomNumber) {
            numberOfTries++;
            return Correctness.KLEINER;
        } else if (num < randomNumber) {
            numberOfTries++;
            return Correctness.GROESSER;
        } else {
            dice();
            return Correctness.GLEICH;
        }

    }

    public void dice(){
        Random ran = new Random();
        randomNumber = 1 + ran.nextInt(100);
    }

    public int getNumberOfTries(){
        return numberOfTries;
    }

}


import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;

import java.net.URL;
import java.util.ResourceBundle;

public class Controller implements Initializable {

    Model model = new Model();

    @FXML
    Label label;

    @FXML
    Spinner<Integer> spinner;
    
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        SpinnerValueFactory<Integer> valueFac = new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100);
        spinner.setValueFactory(valueFac);
    }


    @FXML
    Button button;

    public void check(){
        if (model.check(spinner.getValue()) == Correctness.GROESSER) {
            label.setText("Die Zahl ist größer!");
        } else if (model.check(spinner.getValue()) == Correctness.KLEINER) {
            label.setText("Die Zahl ist kleiner!");
        } else {
            label.setText("Die Zahl ist gleich! Rateversuche: " + model.getNumberOfTries());
        }
    }
    
}

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.uni_passau.se.mvc_rng.Controller">
   <children>
      <Spinner id="spinner" layoutX="151.0" layoutY="188.0" prefHeight="25.0" prefWidth="189.0" />
      <Label id="label" layoutX="151.0" layoutY="213.0" text="Please input a number from [1, 100]" />
      <Button id="button" layoutX="350.0" layoutY="188.0" mnemonicParsing="false" onAction="#check" text="Guess!" />
   </children>
</Pane>

