Skip to content
Snippets Groups Projects
Commit 2586c1ef authored by Jerusalem Laila's avatar Jerusalem Laila
Browse files

Methode für random placed Food im Screen + Game Stage

parent 648aeb08
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,6 @@ module gui {
opens org.example to javafx.fxml;
exports org.example;
exports org.example.gui;
opens org.example.gui to javafx.fxml;
exports org.example.game;
opens org.example.game to javafx.fxml;
}
\ No newline at end of file
package org.example.GuiHelper;
public class TestMain {
}
package org.example.game;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class Elemente extends Application {
private final static Logger logger = LogManager.getLogger(Elemente.class);
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
VBox layout = new VBox(10);
//Label
Label label = new Label("Das ist eine Beschriftung");
layout.getChildren().add(label);
//Button
Button button = new Button();
button.setText("Hier Klicken");
layout.getChildren().add(button);
//Radio Button
Label radioButtonText = new Label("Radio Button:");
ToggleGroup gruppe = new ToggleGroup();
RadioButton radioButton1 = new RadioButton("Entweder 1");
radioButton1.setToggleGroup(gruppe);
RadioButton radioButton2 = new RadioButton("Oder 2");
radioButton2.setToggleGroup(gruppe);
layout.getChildren().addAll(radioButtonText, radioButton1, radioButton2);
//Toggle Button
Label toggleButtonText = new Label("Toggle Button:");
ToggleGroup toggleGroup = new ToggleGroup();
ToggleButton toggleGroup1 = new ToggleButton("Möglichkeit 1");
toggleGroup1.setSelected(true);
toggleGroup1.setToggleGroup(toggleGroup);
ToggleButton toggleGroup2 = new ToggleButton("Möglichkeit 2");
toggleGroup2.setToggleGroup(toggleGroup);
layout.getChildren().addAll(toggleButtonText, toggleGroup1, toggleGroup2);
//Check Box
Label checkBoxText = new Label("Check Box:");
CheckBox checkBox1 = new CheckBox("Auswahl 1");
CheckBox checkBox2 = new CheckBox("Auswahl 2");
layout.getChildren().addAll(checkBoxText, checkBox1, checkBox2);
//Dropdown
Label dropdownText = new Label("Dropdown:");
ChoiceBox<String> choiceBox = new ChoiceBox<>(
FXCollections.observableArrayList(
"Option 1", "Option 2", "Option 1"));
choiceBox.getSelectionModel().selectFirst();
layout.getChildren().addAll(dropdownText, choiceBox);
//Textfeld
Label textfeldText = new Label("Textfeld");
TextField textFeld = new TextField("Hier den Text eingeben");
layout.getChildren().addAll(textfeldText, textFeld);
//Passwort
Label passwortText = new Label("Passwort:");
PasswordField passwort = new PasswordField();
passwort.setPromptText("Passwort eingabe");
layout.getChildren().addAll(passwortText, passwort);
//Slider
Label sliderText = new Label("Slider");
Slider slider = new Slider();
slider.setMin(0);
slider.setMax(100);
slider.setValue(20);
slider.setShowTickLabels(true);
slider.setShowTickMarks(true);
layout.getChildren().addAll(sliderText, slider);
Scene scene = new Scene(layout, 400,600);
stage.setTitle("Hello HdM!");
stage.setScene(scene);
stage.show();
}
}
package org.example.game;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Random;
public class SnakeGame extends Application {
private final static Logger logger = LogManager.getLogger(SnakeGame.class);
//window
private static final int width = 600;
private static final int height = 500;
private static final int radius = 5;
//food
private Circle food;
private Random random;
private Pane root;
private Circle snake;
/** methode will create the food
* and display it randomly **/
private void newFood(){
food = new Circle(random.nextInt(width-2),random.nextInt(height-2), radius);
food.setFill(Color.RED);
root.getChildren().add(food);
}
private void newSnake(){
snake = new Circle(300,250, radius+2);
root.getChildren().add(snake);
}
@Override
public void start (Stage primaryStage) {
root = new Pane();
root.setPrefSize(width, height);
random = new Random();
newFood();
newSnake();
Scene scene = new Scene (root);
primaryStage.setTitle("Snake Game");
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show();
}
public static void main(String[] args) {
logger.info("Game is activated");
launch(args);
}
}
package org.example.gui;
package org.example.game;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class StartScreen extends Application {
// private final static Logger logger = LogManager.getLogger(SnakeGame.class);
// private static final int width = 600; //width of window
// private static final int height = 500; //height of window
private final static Logger logger = LogManager.getLogger(StartScreen.class);
public static void main(String[] args) {
launch(args);
logger.info("Startscene is activated");
launch(args);
}
@Override
public void start(Stage stage) throws Exception{
public void start(Stage startstage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/fxml/start.fxml"));
Scene scene = new Scene(root);
stage.setTitle("Snake Game");
stage.setScene(scene);
stage.show();
startstage.setTitle("Snake Game");
startstage.setResizable(false);
startstage.setScene(scene);
startstage.show();
}
}
......
......@@ -8,7 +8,7 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/19">
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/19">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment