Compare commits

..

No commits in common. "70c8716a5f7dcc14643074c7ca4e4d208b9473da" and "2670617bfb70318e98eba81c4dc57e9bfe331675" have entirely different histories.

10 changed files with 154 additions and 257 deletions

View File

@ -1,9 +1,5 @@
package com.example.happy_bird; package com.example.happy_bird;
import javafx.scene.control.Button; public class HappyBird {
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class HappyBird extends HappyBirdMain {
} }

View File

@ -22,46 +22,20 @@ import java.io.IOException;
public class HappyBirdMain extends Application { public class HappyBirdMain extends Application {
private Pane pane = new Pane();
private Scene scene = new Scene(pane, 800, 700);
private Label nameLabel = new Label("NAME");
private Label acronymLabel = new Label("KÜRZEL");
private Label headline = new Label("HAPPY BIRD");
private Label soundLabel = new Label("SOUND");
private Label labels[] = {nameLabel, acronymLabel, soundLabel};
private Label headlineLabels[] = {headline};
private Button startButton = new Button("START");
private Button highscoresButton = new Button("HIGHSCORES");
private Button settingsButton = new Button("EINSTELLUNGEN");
private Button startGameButton = new Button("SPIEL STARTEN");
private Button menuButton = new Button("ZURÜCK");
private Button[] buttons = {startButton, highscoresButton, settingsButton, startGameButton, menuButton};
private TextField name = new TextField();
private TextField acronym = new TextField();
private TextField inputFields[] = {name, acronym};
private Slider soundSlider = new Slider();
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
} }
@Override @Override
public void start(Stage stage) throws IOException { public void start(Stage stage) throws IOException {
Pane pane = new Pane();
Scene scene = new Scene(pane, 800, 700);
stage.setTitle("Happy Bird"); stage.setTitle("Happy Bird");
stage.setScene(scene); stage.setScene(scene);
/**Bild für Hintergrund erstellen:*/ //Backgroundimage
Image image = new Image("file:src/main/resources/com/example/happy_bird/pics/Background.png"); Image backgroundImage = new Image("file:src/main/resources/com/example/happy_bird/pics/Background.png");
/**Hintergrund erstellen:*/
BackgroundImage backgroundImageImg = new BackgroundImage( BackgroundImage backgroundImageImg = new BackgroundImage(
backgroundImage, backgroundImage,
BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT,
@ -70,7 +44,6 @@ public class HappyBirdMain extends Application {
BackgroundSize.DEFAULT BackgroundSize.DEFAULT
); );
/**Hintergrund zu Pane hinzufügen:*/
Image bird = new Image("file:src/main/resources/com/example/happy_bird/pics/bird.png", 50, 35, false, false); Image bird = new Image("file:src/main/resources/com/example/happy_bird/pics/bird.png", 50, 35, false, false);
/*ImageView birdView = new ImageView(); /*ImageView birdView = new ImageView();
birdView.setFitHeight(50); birdView.setFitHeight(50);
@ -86,117 +59,57 @@ public class HappyBirdMain extends Application {
Background background = new Background(backgroundImageImg); Background background = new Background(backgroundImageImg);
pane.setBackground(background); pane.setBackground(background);
//Headline-Label
Label headline = new Label("Happy Bird");
/**Labels erstellen:*/ headline.setPrefSize(300, 75);
headline.setTextAlignment(TextAlignment.CENTER);
headline.setStyle("-fx-background-color: #DED894; " +
/**Labels in Arrays speichern:*/ "-fx-text-fill: #000000; " +
"-fx-font-size: 35px; " +
"-fx-border-width: 5px;" +
/**Labels formatieren:*/ "-fx-border-color: #543847;" +
labelsFormating(labels, pane); "-fx-font-weight: bold;" +
headlineFormating(headlineLabels, pane); "-fx-alignment: center;" +
"-fx-background-radius: 20px;" +
/**alle labels an ihre Stelle:*/ "-fx-border-radius: 15px;");
int yPositionLabels = 225;
for (Label label : labels) {
label.setLayoutX(275);
label.setLayoutY(yPositionLabels);
yPositionLabels += 150;
}
/**headline an ihre Stelle:*/
headline.setLayoutX(250); headline.setLayoutX(250);
headline.setLayoutY(100); headline.setLayoutY(100);
/**soundLabel an seine Stelle:*/ pane.getChildren().add(headline);
soundLabel.setLayoutY(225);
//Buttons:
Button startButton = new Button("START");
Button highscoresButton = new Button("HIGHSCORES");
Button settingsButton = new Button("EINSTELLUNGEN");
Button startGame = new Button("SPIEL STARTEN");
Button buttons[] = {startButton, highscoresButton, settingsButton, startGame};
/**Buttons erstellen:*/ Button menuButton = new Button("ZURÜCK");
menuButton.setStyle("-fx-background-color: #e86000; " +
"-fx-text-fill: #FFFFFF; " +
/**Buttons in Array speichern:*/ "-fx-font-size: 20px; " +
"-fx-border-width: 5px;" +
"-fx-border-color: #FFFFFF;" +
/**Buttons formatieren:*/ "-fx-font-weight: bold;" +
buttonsFormating(buttons, pane); "-fx-border-radius: 15px;" +
"-fx-background-radius: 20px;");
/**alle Buttons an ihre Stelle:*/ pane.getChildren().add(menuButton);
int yPositionButtons = 225; menuButton.setPrefSize(200, 50);
for (Button button : buttons) {
button.setLayoutX(300);
button.setLayoutY(yPositionButtons);
yPositionButtons += 100;
}
/**menuButton an seine Stelle und vorerst ausblenden:*/
menuButton.setLayoutX(575); menuButton.setLayoutX(575);
menuButton.setLayoutY(625); menuButton.setLayoutY(625);
menuButton.setVisible(false); menuButton.setVisible(false);
startGame.setVisible(false);
/**startGameButton unsichtbar*/
startGameButton.setVisible(false);
//Button buttons[] = {startButton, highscoresButton, settingsButton};
/**Textfelder erstellen:*/ int yPosition = 225;
/**Textfelder in Array speichern:*/
/**Textfelder formatieren:*/
textfieldsFormating(inputFields, pane);
/**Textfelder an ihre Position:*/
int yPositionInputFields = 290;
for (TextField feld : inputFields) {
feld.setLayoutX(275);
feld.setLayoutY(yPositionInputFields);
yPositionInputFields += 150;
}
/**SoundSlider erstellen:*/
/**SoundSlicer anpassen:*/
soundSliderFormating(soundSlider, pane);
/**ClickEvents:*/
startButton.setOnAction(event -> {
startButtonClick();
});
settingsButton.setOnAction(event -> {
settingsButtonClick();
});
highscoresButton.setOnAction(event -> {
highscoresButtonClick();
});
menuButton.setOnAction(event -> {
menuButtonClick();
});
stage.show();
}
/***
* 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) { for (Button button : buttons) {
pane.getChildren().add(button);
button.setPrefSize(200, 50); button.setPrefSize(200, 50);
button.setLayoutX(300);
button.setLayoutY(yPosition);
yPosition += 100;
button.setStyle("-fx-background-color: #e86000; " + button.setStyle("-fx-background-color: #e86000; " +
"-fx-text-fill: #FFFFFF; " + "-fx-text-fill: #FFFFFF; " +
@ -206,20 +119,25 @@ public class HappyBirdMain extends Application {
"-fx-font-weight: bold;" + "-fx-font-weight: bold;" +
"-fx-border-radius: 15px;" + "-fx-border-radius: 15px;" +
"-fx-background-radius: 20px;"); "-fx-background-radius: 20px;");
pane.getChildren().add(button);
}
} }
/*** startGame.setVisible(false);
* Formatiert alle kleinen Labels (keine Überschrift) und fügt sie der Pane hinzu
* @param labels LabelArray mit allen Labels Label nameLabel = new Label("Name:");
* @param pane Pane, auf der die Labels angezeigt werden Label acronymLabel = new Label("Kürzel:");
*/
public void labelsFormating(Label[] labels, Pane pane) { Label startLabels[] = {nameLabel, acronymLabel};
for (Label label : labels) { startButton.setOnAction(event -> {
headline.setText("Start");
for (Button button : buttons) {
button.setVisible(false);
menuButton.setVisible(true);
}
});
int yPositionStartLabels = 225;
for (Label label : startLabels) {
label.setPrefSize(250, 50); label.setPrefSize(250, 50);
label.setStyle("-fx-background-color: #DED894; " + label.setStyle("-fx-background-color: #DED894; " +
"-fx-text-fill: #000000; " + "-fx-text-fill: #000000; " +
"-fx-font-size: 20px; " + "-fx-font-size: 20px; " +
@ -230,73 +148,55 @@ public class HappyBirdMain extends Application {
"-fx-background-radius: 20px;" + "-fx-background-radius: 20px;" +
"-fx-border-radius: 15px;"); "-fx-border-radius: 15px;");
pane.getChildren().add(label); label.setLayoutX(275);
label.setLayoutY(yPositionStartLabels);
yPositionStartLabels += 150;
pane.getChildren().add(label);
label.setVisible(false); label.setVisible(false);
} }
}
/*** TextField name = new TextField();
* Formatiert alle Überschriften-Labels und fügt sie der Pane hinzu TextField acronym = new TextField();
* @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; " + TextField inputFields[] = {name, acronym};
"-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); int yPositionInputFields = 290;
} for (TextField feld : inputFields) {
} feld.setPrefSize(250, 50);
feld.setStyle("-fx-font-size: 20px;" +
/***
* 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;"); "-fx-font-weight: bold;");
pane.getChildren().add(field); feld.setLayoutX(275);
feld.setLayoutY(yPositionInputFields);
yPositionInputFields += 150;
field.setVisible(false); pane.getChildren().add(feld);
} feld.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); startButton.setOnAction(event -> {
headline.setText("Start");
for(Button button : buttons) {
button.setVisible(false);
slider.setVisible(false);
} }
/*** startGame.setVisible(true);
* Hauptmenü wird ausgeblendet, Nameneingabe folgt menuButton.setVisible(true);
*/ startGame.setLayoutY(520);
public void startButtonClick() {
headline.setText("START"); for(TextField feld : inputFields) {
feld.setVisible(true);
}
for (Label label : startLabels )
{
label.setVisible(true);
}
});
startGame.setOnAction(event -> { startGame.setOnAction(event -> {
for(TextField feld : inputFields) { for(TextField feld : inputFields) {
feld.setVisible(false); feld.setVisible(false);
@ -324,29 +224,35 @@ public class HappyBirdMain extends Application {
lowerPipeView.setLayoutY(430); lowerPipeView.setLayoutY(430);
}); });
for(Button button : buttons) {
button.setVisible(false);
}
startGameButton.setVisible(true); //Slider:
menuButton.setVisible(true); Slider soundSlider = new Slider();
startGameButton.setLayoutY(520); pane.getChildren().add(soundSlider);
soundSlider.setPrefSize(200, 5);
soundSlider.setLayoutX(300);
soundSlider.setLayoutY(295);
soundSlider.setVisible(false);
for(TextField feld : inputFields) { Label soundLabel = new Label("SOUND");
feld.setVisible(true); soundLabel.setPrefSize(200, 55);
} soundLabel.setTextAlignment(TextAlignment.CENTER);
for (Label label : labels ) { soundLabel.setStyle("-fx-background-color: #DED894; " +
label.setVisible(true); "-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;");
soundLabel.setLayoutX(300);
soundLabel.setLayoutY(225);
pane.getChildren().add(soundLabel);
soundLabel.setVisible(false); soundLabel.setVisible(false);
}
/*** settingsButton.setOnAction(event -> {
* Hauptmenü wird ausgeblendet, Einstellungen folgen
*/
public void settingsButtonClick() {
headline.setText("EINSTELLUNGEN"); headline.setText("EINSTELLUNGEN");
startButton.setVisible(false); startButton.setVisible(false);
highscoresButton.setVisible(false); highscoresButton.setVisible(false);
@ -354,24 +260,17 @@ public class HappyBirdMain extends Application {
menuButton.setVisible(true); menuButton.setVisible(true);
soundSlider.setVisible(true); soundSlider.setVisible(true);
soundLabel.setVisible(true); soundLabel.setVisible(true);
} });
/*** highscoresButton.setOnAction(event -> {
* Hauptmenü wird ausgeblendet, Highscores folgen
*/
public void highscoresButtonClick() {
headline.setText("HIGHSCORES"); headline.setText("HIGHSCORES");
startButton.setVisible(false); startButton.setVisible(false);
highscoresButton.setVisible(false); highscoresButton.setVisible(false);
settingsButton.setVisible(false); settingsButton.setVisible(false);
menuButton.setVisible(true); menuButton.setVisible(true);
} });
/*** menuButton.setOnAction(event -> {
* Nameneingabe, Einstellungen und Highscores werden ausgeblendet
* Erneutes Anzeigen des Hauptmenüs
*/
public void menuButtonClick() {
headline.setText("HAPPY BIRD"); headline.setText("HAPPY BIRD");
startButton.setVisible(true); startButton.setVisible(true);
highscoresButton.setVisible(true); highscoresButton.setVisible(true);
@ -379,14 +278,16 @@ public class HappyBirdMain extends Application {
menuButton.setVisible(false); menuButton.setVisible(false);
soundSlider.setVisible(false); soundSlider.setVisible(false);
soundLabel.setVisible(false); soundLabel.setVisible(false);
startGameButton.setVisible(false); startGame.setVisible(false);
for(TextField feld : inputFields) { for(TextField feld : inputFields) {
feld.setVisible(false); feld.setVisible(false);
} }
for (Label label : startLabels )
for (Label label : labels ) { {
label.setVisible(false); label.setVisible(false);
} }
});
stage.show();
} }
} }