diff --git a/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin b/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin index a5c831f..b256089 100644 Binary files a/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin and b/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin differ diff --git a/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.lock b/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.lock index 0434bd4..f653249 100644 Binary files a/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.lock and b/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.lock differ diff --git a/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.bin b/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.bin index a2b4d78..b4b154e 100644 Binary files a/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.bin and b/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.bin differ diff --git a/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.lock b/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.lock index 87c1573..54bfb98 100644 Binary files a/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.lock and b/Happy_Bird/.gradle/7.1.1/fileHashes/fileHashes.lock differ diff --git a/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 5f005b6..8d9d088 100644 Binary files a/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/Happy_Bird/.gradle/buildOutputCleanup/outputFiles.bin b/Happy_Bird/.gradle/buildOutputCleanup/outputFiles.bin index a1d4ec7..5470d8c 100644 Binary files a/Happy_Bird/.gradle/buildOutputCleanup/outputFiles.bin and b/Happy_Bird/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/Happy_Bird/.gradle/checksums/checksums.lock b/Happy_Bird/.gradle/checksums/checksums.lock index 33c2b88..1964ecb 100644 Binary files a/Happy_Bird/.gradle/checksums/checksums.lock and b/Happy_Bird/.gradle/checksums/checksums.lock differ diff --git a/Happy_Bird/.gradle/checksums/md5-checksums.bin b/Happy_Bird/.gradle/checksums/md5-checksums.bin index be976af..e6fbe73 100644 Binary files a/Happy_Bird/.gradle/checksums/md5-checksums.bin and b/Happy_Bird/.gradle/checksums/md5-checksums.bin differ diff --git a/Happy_Bird/.gradle/checksums/sha1-checksums.bin b/Happy_Bird/.gradle/checksums/sha1-checksums.bin index 4e9e001..44b1816 100644 Binary files a/Happy_Bird/.gradle/checksums/sha1-checksums.bin and b/Happy_Bird/.gradle/checksums/sha1-checksums.bin differ diff --git a/Happy_Bird/build/classes/java/main/com/example/happy_bird/HappyBirdMain.class b/Happy_Bird/build/classes/java/main/com/example/happy_bird/HappyBirdMain.class index bee0caf..f76937b 100644 Binary files a/Happy_Bird/build/classes/java/main/com/example/happy_bird/HappyBirdMain.class and b/Happy_Bird/build/classes/java/main/com/example/happy_bird/HappyBirdMain.class differ diff --git a/Happy_Bird/build/classes/java/main/module-info.class b/Happy_Bird/build/classes/java/main/module-info.class index 9ac6a58..c6bee7e 100644 Binary files a/Happy_Bird/build/classes/java/main/module-info.class and b/Happy_Bird/build/classes/java/main/module-info.class differ diff --git a/Happy_Bird/build/libs/Happy_Bird-1.0-SNAPSHOT.jar b/Happy_Bird/build/libs/Happy_Bird-1.0-SNAPSHOT.jar index 687dcb7..dc7b7c1 100644 Binary files a/Happy_Bird/build/libs/Happy_Bird-1.0-SNAPSHOT.jar and b/Happy_Bird/build/libs/Happy_Bird-1.0-SNAPSHOT.jar differ diff --git a/Happy_Bird/build/tmp/compileJava/previous-compilation-data.bin b/Happy_Bird/build/tmp/compileJava/previous-compilation-data.bin index 0295812..01de109 100644 Binary files a/Happy_Bird/build/tmp/compileJava/previous-compilation-data.bin and b/Happy_Bird/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/Happy_Bird/src/main/java/com/example/happy_bird/FormatingClass.java b/Happy_Bird/src/main/java/com/example/happy_bird/FormatingClass.java new file mode 100644 index 0000000..11bbb9e --- /dev/null +++ b/Happy_Bird/src/main/java/com/example/happy_bird/FormatingClass.java @@ -0,0 +1,239 @@ +package com.example.happy_bird; + +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.Slider; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.layout.*; +import javafx.scene.text.TextAlignment; + +public class FormatingClass { + /*** + * leerer Konstruktor + */ + public FormatingClass() { } + + /*** + * Formatiert alle Buttons und fügt sie der Pane hinzu + * @param buttons ButtonArray mit allen Arrays + * @param pane Pane, auf der die Buttons angezeigt werden + */ + public void buttonsFormating(Button[] buttons, Pane pane) { + for (Button button : buttons) { + button.setPrefSize(200, 50); + + button.setStyle("-fx-background-color: #e86000; " + + "-fx-text-fill: #FFFFFF; " + + "-fx-font-size: 20px; " + + "-fx-border-width: 5px;" + + "-fx-border-color: #FFFFFF;" + + "-fx-font-weight: bold;" + + "-fx-border-radius: 15px;" + + "-fx-background-radius: 20px;"); + + pane.getChildren().add(button); + } + } + + /*** + * Formatiert alle kleinen Labels (keine Überschrift) und fügt sie der Pane hinzu + * @param labels LabelArray mit allen Labels + * @param pane Pane, auf der die Labels angezeigt werden + */ + public void labelsFormating(Label[] labels, Pane pane) { + for (Label label : labels) { + label.setPrefSize(250, 50); + + label.setStyle("-fx-background-color: #DED894; " + + "-fx-text-fill: #000000; " + + "-fx-font-size: 20px; " + + "-fx-border-width: 5px;" + + "-fx-border-color: #543847;" + + "-fx-font-weight: bold;" + + "-fx-alignment: center;" + + "-fx-background-radius: 20px;" + + "-fx-border-radius: 15px;"); + + pane.getChildren().add(label); + + label.setVisible(false); + } + } + + /*** + * Formatiert alle Überschriften-Labels und fügt sie der Pane hinzu + * @param labels LabelArray mit Überschriften-Labels + * @param pane Pane, auf der die Labels angezeigt werden + */ + public void headlineFormating(Label[] labels, Pane pane) { + for (Label label : labels) { + label.setPrefSize(300, 75); + label.setTextAlignment(TextAlignment.CENTER); + + label.setStyle("-fx-background-color: #DED894; " + + "-fx-text-fill: #000000; " + + "-fx-font-size: 35px; " + + "-fx-border-width: 5px;" + + "-fx-border-color: #543847;" + + "-fx-font-weight: bold;" + + "-fx-alignment: center;" + + "-fx-background-radius: 20px;" + + "-fx-border-radius: 15px;"); + + pane.getChildren().add(label); + } + } + + /*** + * Formatiert alle Textfelder und fügt sie der Pane hinzu + * @param textfields TextFieldArray mit allen Textfeldern + * @param pane Pane, auf der die Textfelder angezeigt werden + */ + public void textfieldsFormating(TextField[] textfields, Pane pane) { + for (TextField field : textfields) { + field.setPrefSize(250, 50); + field.setStyle("-fx-font-size: 20px;" + + "-fx-font-weight: bold;"); + + pane.getChildren().add(field); + + field.setVisible(false); + } + } + + /*** + * Formatiert den soundSlider und fügt ihn der Pane hinzu + * @param slider SoundSlider + * @param pane Pane, auf der der Slider angezeigt wird + */ + public void soundSliderFormating(Slider slider, Pane pane) { + slider.setPrefSize(200, 5); + slider.setLayoutX(300); + slider.setLayoutY(295); + + pane.getChildren().add(slider); + + slider.setVisible(false); + } + + /*** + * Formatiert den PauseScreen + */ + public void pauseScreenFormating(Pane pause, Label pauseMenuLabel, Label soundLabelPause) { + /*pause-Pane formatieren*/ + pause.setPrefSize(400, 400); + pause.setLayoutX(200); + pause.setLayoutY(150); + pause.setStyle("-fx-background-color: #DED894; " + + "-fx-border-width: 5px;" + + "-fx-border-color: #543847;" + + "-fx-border-radius: 15px;" + + "-fx-background-radius: 20px;"); + + /*pauseMenuLabel formatieren*/ + pauseMenuLabel.setPrefSize(300,50); + pauseMenuLabel.setLayoutX(50); + pauseMenuLabel.setLayoutY(10); + pauseMenuLabel.setStyle("-fx-background-color: #DED894; " + + "-fx-text-fill: #000000; " + + "-fx-font-size: 35px; " + + "-fx-font-weight: bold;" + + "-fx-alignment: center;"); + + /*soundLabelPause formatieren*/ + soundLabelPause.setPrefSize(100, 50); + soundLabelPause.setLayoutX(150); + soundLabelPause.setLayoutY(100); + soundLabelPause.setStyle("-fx-background-color: #DED894; " + + "-fx-text-fill: #000000; " + + "-fx-font-size: 20px; " + + "-fx-font-weight: bold;" + + "-fx-alignment: center;"); + } + + /*** + * formatiert den End-Screen + */ + public void endScreenFormating(Pane endScreen, Pane pause, Label endScreenHeadline, Label currentScoreEndscreenLabel) { + /*Endscreen-Pane formatieren*/ + endScreen.setPrefSize(400, 500); + pause.setLayoutX(200); + pause.setLayoutY(100); + pause.setStyle("-fx-background-color: #DED894; " + + "-fx-border-width: 5px;" + + "-fx-border-color: #543847;" + + "-fx-border-radius: 15px;" + + "-fx-background-radius: 20px;"); + + endScreenHeadline.setPrefSize(300,50); + endScreenHeadline.setLayoutX(50); + endScreenHeadline.setLayoutY(10); + endScreenHeadline.setStyle("-fx-background-color: #DED894; " + + "-fx-text-fill: #000000; " + + "-fx-font-size: 35px; " + + "-fx-font-weight: bold;" + + "-fx-alignment: center;"); + + currentScoreEndscreenLabel.setPrefSize(250,50); + currentScoreEndscreenLabel.setLayoutX(75); + currentScoreEndscreenLabel.setLayoutY(100); + currentScoreEndscreenLabel.setStyle("-fx-background-color: #DED894; " + + "-fx-text-fill: #000000; " + + "-fx-font-size: 35px; " + + "-fx-font-weight: bold;" + + "-fx-alignment: center;"); + } + + /*** + * Erstellt ein neues BackgroundImage aus einer Source für ein .png + * @param img Source eines .png + * @return backgroundImage + */ + public BackgroundImage backgroundFormating(String img) { + /*Bild für Hintergrund erstellen:*/ + Image image = new Image(img); + + /*Hintergrund erstellen:*/ + BackgroundImage backgroundImage = new BackgroundImage( + image, + BackgroundRepeat.NO_REPEAT, + BackgroundRepeat.NO_REPEAT, + BackgroundPosition.DEFAULT, + BackgroundSize.DEFAULT + ); + + return backgroundImage; + } + + /*** + * Formatiert die Buttons, mit denen man das Hintergrundbild ändern kann + * @param backgroundButtons Array der Buttons + * @param pane Pane, auf der die Buttons angezeigt werden sollen + */ + public void backgroundButtonsFormating(Button[] backgroundButtons, Pane pane) { + int xPosition = 150; + + for(int i=0; i x + width && !isPassedOn; + } + + // Bei Bewegung der X Koordinate werden Röhren generiert + public void moveX(int dx) { + x -= dx; + topPipe.x -= dx; + bottomPipe.x -= dx; + } +} \ No newline at end of file diff --git a/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java b/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java index ad929ed..001b3b9 100644 --- a/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java +++ b/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java @@ -7,28 +7,30 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; import javafx.scene.layout.*; -import javafx.scene.text.TextAlignment; import javafx.stage.Stage; import java.sql.PreparedStatement; import java.sql.ResultSet; public class HappyBirdMain extends Application { + /* Formatierungsklasse */ + private final FormatingClass formatingClass = new FormatingClass(); + /* Testen des Endscreens */ private final Button endscreenTest = new Button("Endscreentest"); - /*Datenbank einlesen*/ - MariaDB datenbank = new MariaDB(); + /* Datenbank einlesen */ + private final MariaDB datenbank = new MariaDB(); - /*Panes erstellen und zuweisen*/ + /* Panes erstellen und zuweisen */ private final Pane pane = new Pane(); private final Pane pause = new Pane(); private final Pane endScreen = new Pane(); - /*Scene erstellen und zuweisen*/ + /* Scene erstellen und zuweisen */ private final Scene scene = new Scene(pane, 800, 700); - /*Labels erstellen und zuweisen*/ + /* Labels erstellen und zuweisen */ private final Label nameLabel = new Label("NAME"); private final Label acronymLabel = new Label("KÜRZEL"); private final Label headline = new Label("HAPPY BIRD"); @@ -38,7 +40,6 @@ public class HappyBirdMain extends Application { private final Label pauseMenuLabel = new Label("PAUSE"); private final Label soundLabelPause = new Label("SOUND"); private final Label highscoreMenuLabel = new Label(); - private final Label currentScoreEndscreenLabel = new Label("YOUR SCORE: "); private final Label endScreenHeadline = new Label("GAME OVER"); @@ -49,7 +50,6 @@ public class HappyBirdMain extends Application { /*Buttons erstellen und zuweisen*/ private final Button startButton = new Button("START"); private final Button highscoresButton = new Button("HIGHSCORES"); - private final Button settingsButton = new Button("EINSTELLUNGEN"); private final Button startGameButton = new Button("SPIEL STARTEN"); private final Button menuButton = new Button("ZURÜCK"); @@ -60,7 +60,6 @@ public class HappyBirdMain extends Application { private final Button backButtonPause = new Button("ZURÜCK"); private final Button background1 = new Button(); private final Button background2 = new Button(); - private final Button backMenuButton = new Button(); private final Button restartGameButton = new Button(); private final Button personalHighscoresButton = new Button ("YOUR SCORES"); @@ -95,8 +94,6 @@ public class HappyBirdMain extends Application { //gameRunning: das Spiel läuft/ GameScreen ist aufgerufen private boolean gameRunning; - - public static void main(String[] args) { launch(args); } @@ -106,7 +103,6 @@ public class HappyBirdMain extends Application { stage.setTitle("Happy Bird"); stage.setScene(scene); - generateMenueScene(); /*ClickEvents:*/ @@ -131,25 +127,19 @@ public class HappyBirdMain extends Application { dataQuery(); menuScreenRunning = true; - /*Bild für Hintergrund erstellen:*/ - Image image = new Image("file:src/main/resources/com/example/happy_bird/pics/Background0.png"); + /*Source als String*/ + String img = "file:src/main/resources/com/example/happy_bird/pics/Background0.png"; - /*Hintergrund erstellen:*/ - BackgroundImage backgroundImage = new BackgroundImage( - image, - BackgroundRepeat.NO_REPEAT, - BackgroundRepeat.NO_REPEAT, - BackgroundPosition.DEFAULT, - BackgroundSize.DEFAULT - ); + /*Bild zu Hintergrund */ + BackgroundImage backgroundImage = formatingClass.backgroundFormating(img); /*Hintergrund zu Pane hinzufügen:*/ Background background = new Background(backgroundImage); pane.setBackground(background); /*Labels formatieren:*/ - labelsFormating(labels, pane); - headlineFormating(headlineLabels, pane); + formatingClass.labelsFormating(labels, pane); + formatingClass.headlineFormating(headlineLabels, pane); /*Überschrift umbenennen, falls aus anderem Screen*/ headline.setText("HAPPY BIRD"); @@ -171,7 +161,7 @@ public class HappyBirdMain extends Application { soundLabel.setLayoutY(225); /*Buttons formatieren:*/ - buttonsFormating(buttons, pane); + formatingClass.buttonsFormating(buttons, pane); /*alle Buttons an ihre Stelle:*/ int yPositionButtons = 225; @@ -197,14 +187,14 @@ public class HappyBirdMain extends Application { settingsButtonPause.setVisible(false); /*Buttons für Hintergründe*/ - backgroundButtonsFormating(); + formatingClass.backgroundButtonsFormating(backgroundButtons, pane); /*Background-Buttons unsichtbar*/ background1.setVisible(false); background2.setVisible(false); /*Textfelder formatieren:*/ - textfieldsFormating(inputFields, pane); + formatingClass.textfieldsFormating(inputFields, pane); /*Textfelder an ihre Position:*/ int yPositionInputFields = 290; @@ -215,7 +205,7 @@ public class HappyBirdMain extends Application { } /*SoundSlicer anpassen:*/ - soundSliderFormating(soundSlider, pane); + formatingClass.soundSliderFormating(soundSlider, pane); } /** @@ -282,194 +272,6 @@ public class HappyBirdMain extends Application { lowerPipeView.setLayoutY(430); } - /*** - * Formatiert alle Buttons und fügt sie der Pane hinzu - * @param buttons ButtonArray mit allen Arrays - * @param pane Pane, auf der die Buttons angezeigt werden - */ - public void buttonsFormating(Button[] buttons, Pane pane) { - for (Button button : buttons) { - button.setPrefSize(200, 50); - - button.setStyle("-fx-background-color: #e86000; " + - "-fx-text-fill: #FFFFFF; " + - "-fx-font-size: 20px; " + - "-fx-border-width: 5px;" + - "-fx-border-color: #FFFFFF;" + - "-fx-font-weight: bold;" + - "-fx-border-radius: 15px;" + - "-fx-background-radius: 20px;"); - - pane.getChildren().add(button); - } - } - - - public void backgroundButtonsFormating() { - - int xPosition = 150; - - for(int i=0; i startGameButtonClick()); } - /*** * Hauptmenü wird ausgeblendet, Einstellungen folgen */ @@ -526,40 +327,21 @@ public class HappyBirdMain extends Application { background1.setVisible(true); background2.setVisible(true); - background1.setOnAction(event -> { - /*Bild für Hintergrund erstellen:*/ - Image image = new Image("file:src/main/resources/com/example/happy_bird/pics/Background0.png"); - - /*Hintergrund erstellen:*/ - BackgroundImage backgroundImage = new BackgroundImage( - image, - BackgroundRepeat.NO_REPEAT, - BackgroundRepeat.NO_REPEAT, - BackgroundPosition.DEFAULT, - BackgroundSize.DEFAULT - ); + /*Source als String*/ + String img = "file:src/main/resources/com/example/happy_bird/pics/Background0.png"; /*Hintergrund zu Pane hinzufügen:*/ - Background background = new Background(backgroundImage); + Background background = new Background(formatingClass.backgroundFormating(img)); pane.setBackground(background); }); background2.setOnAction(event -> { - /*Bild für Hintergrund erstellen:*/ - Image image = new Image("file:src/main/resources/com/example/happy_bird/pics/Background1.png"); - - /*Hintergrund erstellen:*/ - BackgroundImage backgroundImage = new BackgroundImage( - image, - BackgroundRepeat.NO_REPEAT, - BackgroundRepeat.NO_REPEAT, - BackgroundPosition.DEFAULT, - BackgroundSize.DEFAULT - ); + /*Source als String*/ + String img = "file:src/main/resources/com/example/happy_bird/pics/Background1.png"; /*Hintergrund zu Pane hinzufügen:*/ - Background background = new Background(backgroundImage); + Background background = new Background(formatingClass.backgroundFormating(img)); pane.setBackground(background); }); } @@ -731,7 +513,7 @@ public class HappyBirdMain extends Application { * Ruft das Pause-Menü im Spiel auf oder blendet es wieder aus */ public void pauseButtonClick(Boolean gameRuns) { - pauseScreenFormating(); + formatingClass.pauseScreenFormating(pause, pauseMenuLabel, soundLabelPause); /*PauseScreen aufrufen, wenn das Spiel läuft, sonst wieder ausblenden*/ if(!gameRuns) { @@ -842,7 +624,7 @@ public class HappyBirdMain extends Application { try (ResultSet rs = datenbank.st.executeQuery(sql)) { while (rs.next()) { - bestFiveHighscores+= rs.getString(4) + "\t" + rs.getString(3)+"\n"; + bestFiveHighscores += rs.getString(4) + "\t" + rs.getString(3)+"\n"; } } catch (Exception e) @@ -865,7 +647,7 @@ public class HappyBirdMain extends Application { try (ResultSet rs = datenbank.st.executeQuery(sql)) { while (rs.next()) { - bestFiveHighscores+= rs.getString(4) + "\t" + rs.getString(3)+"\n"; + bestFiveHighscores += rs.getString(4) + "\t" + rs.getString(3)+"\n"; } } catch (Exception e) @@ -948,38 +730,7 @@ public class HappyBirdMain extends Application { return true; } - /*** - * formatiert den End-Screen - */ - public void endScreenFormating() { - /*Endscreen-Pane formatieren*/ - endScreen.setPrefSize(400, 500); - pause.setLayoutX(200); - pause.setLayoutY(100); - pause.setStyle("-fx-background-color: #DED894; " + - "-fx-border-width: 5px;" + - "-fx-border-color: #543847;" + - "-fx-border-radius: 15px;" + - "-fx-background-radius: 20px;"); - endScreenHeadline.setPrefSize(300,50); - endScreenHeadline.setLayoutX(50); - endScreenHeadline.setLayoutY(10); - endScreenHeadline.setStyle("-fx-background-color: #DED894; " + - "-fx-text-fill: #000000; " + - "-fx-font-size: 35px; " + - "-fx-font-weight: bold;" + - "-fx-alignment: center;"); - - currentScoreEndscreenLabel.setPrefSize(250,50); - currentScoreEndscreenLabel.setLayoutX(75); - currentScoreEndscreenLabel.setLayoutY(100); - currentScoreEndscreenLabel.setStyle("-fx-background-color: #DED894; " + - "-fx-text-fill: #000000; " + - "-fx-font-size: 35px; " + - "-fx-font-weight: bold;" + - "-fx-alignment: center;"); - } /*** * public void generateEndScreen() generiert den Endscreen - sobald das Spiel beendet ist @@ -989,7 +740,7 @@ public class HappyBirdMain extends Application { * sich seine persänlichen Highscores anzeigen zu lassen */ public void generateEndScreen() { - endScreenFormating(); + formatingClass.endScreenFormating(endScreen, pause, endScreenHeadline, currentScoreEndscreenLabel); /*Name und Highscores ausblenden, Pause-Button ausblenden*/ nameLabel.setVisible(false); highscoreLabel.setVisible(false); diff --git a/Happy_Bird/src/main/java/com/example/happy_bird/Movement.java b/Happy_Bird/src/main/java/com/example/happy_bird/Movement.java new file mode 100644 index 0000000..ec570d5 --- /dev/null +++ b/Happy_Bird/src/main/java/com/example/happy_bird/Movement.java @@ -0,0 +1,7 @@ +package com.example.happy_bird; + +public enum Movement { + Up, + Down, + None +}