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 5bad4e4..ad929ed 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 @@ -64,12 +64,13 @@ public class HappyBirdMain extends Application { private final Button backMenuButton = new Button(); private final Button restartGameButton = new Button(); private final Button personalHighscoresButton = new Button ("YOUR SCORES"); + private final Button backEndscreenButton = new Button("ZURÜCK"); /*Buttons in Arrays speichern*/ - private final Button[] buttons = {startButton, highscoresButton, settingsButton, startGameButton, menuButton, pauseButton, continueButton, settingsButtonPause, menuButtonPause, backButtonPause, backMenuButton, restartGameButton, personalHighscoresButton}; + private final Button[] buttons = {startButton, highscoresButton, settingsButton, startGameButton, menuButton, pauseButton, continueButton, settingsButtonPause, menuButtonPause, backButtonPause, backMenuButton, restartGameButton, personalHighscoresButton, backEndscreenButton}; private final Button[] pauseButtons = {continueButton, settingsButtonPause, menuButtonPause, backButtonPause}; private final Button[] backgroundButtons = {background1, background2}; - private final Button[] endscreenButtons = {backMenuButton, restartGameButton, personalHighscoresButton}; + private final Button[] endscreenButtons = {backMenuButton, restartGameButton, personalHighscoresButton, backEndscreenButton}; /*Textfelder erstellen und zuweisen*/ private final TextField name = new TextField(); @@ -980,6 +981,13 @@ public class HappyBirdMain extends Application { "-fx-alignment: center;"); } + /*** + * public void generateEndScreen() generiert den Endscreen - sobald das Spiel beendet ist + * (man verloren hat). Es werden die Punkte des Spielers angezeigt, und es bestehen die Möglichkeiten, + * das Spiel neu zu starten + * das zum Hauptmenü zurückzukehren + * sich seine persänlichen Highscores anzeigen zu lassen + */ public void generateEndScreen() { endScreenFormating(); /*Name und Highscores ausblenden, Pause-Button ausblenden*/ @@ -990,12 +998,13 @@ public class HappyBirdMain extends Application { /**/ endScreen.setVisible(true); - endScreen.getChildren().add(currentScoreEndscreenLabel); - currentScoreEndscreenLabel.setVisible(true); endScreen.getChildren().add(endScreenHeadline); endScreenHeadline.setVisible(true); + endScreen.getChildren().add(currentScoreEndscreenLabel); + currentScoreEndscreenLabel.setVisible(true); + /* Buttons einfügen */ int yPosition = 200; for (Button button : endscreenButtons) { @@ -1006,7 +1015,7 @@ public class HappyBirdMain extends Application { button.setVisible(true); } pane.getChildren().add(endScreen); - + backEndscreenButton.setVisible(false); /* Click-Events für die Buttons */ backMenuButton.setOnAction(event -> backMenuButtonClick()); personalHighscoresButton.setOnAction(event -> personalHighscoresButtonClick()); @@ -1029,15 +1038,60 @@ public class HappyBirdMain extends Application { } + /*** + * die Funktion restartGameButtonClick() startet das Spiel neu + */ private void restartGameButtonClick() { pane.getChildren().remove(endScreen); startGameButtonClick(); } + /*** + * personalHighscoresButtonClick() zeigt bei Drücken des Highscore-Buttons im Endscreen + * die persänlichen besten 5 Scores an + */ private void personalHighscoresButtonClick() { - + /* alle Buttons ausblenden */ + for(Button button : endscreenButtons) { + button.setVisible(false); + } + /* Back-Button einblenden */ + backEndscreenButton.setVisible(true); + + /* Überschrift ändern */ + endScreenHeadline.setText("YOUR HIGHSCORES"); + + /* Highscore ausblenden */ + currentScoreEndscreenLabel.setVisible(false); + + /* Highscore-Label (Hintergrund) formatieren und einfügen */ + highscoreMenuLabel.setLayoutX(275); + highscoreMenuLabel.setLayoutY(225); + highscoreMenuLabel.setPrefHeight(300); + highscoreMenuLabel.setPrefSize(250, 250); + highscoreMenuLabel.setVisible(true); + endScreen.getChildren().add(highscoreMenuLabel); + + /* Highscores des Spielers einfügen */ + String personalBestScores = calculatePersonalHighscores(); + highscoreMenuLabel.setText(personalBestScores); + + /* Zurück-Funktion in den Endscreen */ + backEndscreenButton.setOnAction(event -> { + endScreenHeadline.setText("GAME OVER"); + + for(Button button : endscreenButtons) { + button.setVisible(true); + } + currentScoreEndscreenLabel.setVisible(true); + highscoreMenuLabel.setVisible(false); + backEndscreenButton.setVisible(false); + }); } + /*** + * backMenuButtonClick() ruft aus dem Endscreen das Hauptmenü auf + */ private void backMenuButtonClick() { pane.getChildren().remove(endScreen); generateMenueScene();