Current Score Zähler einbauen

This commit is contained in:
Mats Pape 2022-01-25 10:58:35 +01:00
parent b5daf848c4
commit af010b5bd8
9 changed files with 16 additions and 9 deletions

View File

@ -21,7 +21,8 @@ import java.sql.ResultSet;
import java.util.ArrayList; import java.util.ArrayList;
public class HappyBirdMain extends Application { public class HappyBirdMain extends Application {
private int currentBirdPosition = 0; private int birdPositionMovedBy = 0;
private int collectedPoints;
/* Formatierungsklasse */ /* Formatierungsklasse */
private final FormatingClass formatingClass = new FormatingClass(); private final FormatingClass formatingClass = new FormatingClass();
@ -44,7 +45,7 @@ public class HappyBirdMain extends Application {
private final Label acronymLabel = new Label("KÜRZEL"); private final Label acronymLabel = new Label("KÜRZEL");
private final Label headline = new Label("HAPPY BIRD"); private final Label headline = new Label("HAPPY BIRD");
private final Label soundLabel = new Label("SOUND"); private final Label soundLabel = new Label("SOUND");
private final Label currentScoreLabel = new Label("SCORE: "); private final Label currentScoreLabel = new Label("SCORE: " + collectedPoints);
private final Label highscoreLabel = new Label("HIGHSCORE: "); private final Label highscoreLabel = new Label("HIGHSCORE: ");
private final Label pauseMenuLabel = new Label("PAUSE"); private final Label pauseMenuLabel = new Label("PAUSE");
private final Label soundLabelPause = new Label("SOUND"); private final Label soundLabelPause = new Label("SOUND");
@ -464,6 +465,12 @@ public class HappyBirdMain extends Application {
timeline.stop(); timeline.stop();
gameRunning = false; gameRunning = false;
} }
if(happyBird.getBoundsInParent().getMaxX() > pipe.getBoundsInParent().getMaxX()) {
collectedPoints++;
int pointstoset = collectedPoints / 2;
currentScoreLabel.setText("SCORE: " + pointstoset);
pipesArrayList.remove(pipe);
}
} }
/*** /***
@ -668,15 +675,15 @@ public class HappyBirdMain extends Application {
} }
}); });
currentBirdPosition = 0; birdPositionMovedBy = 0;
scene.setOnKeyPressed(event -> { scene.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.S) { if (event.getCode() == KeyCode.S) {
moveBirdDown(); moveBirdDown();
System.out.println(currentBirdPosition); System.out.println(birdPositionMovedBy);
} }
if (event.getCode() == KeyCode.W) { if (event.getCode() == KeyCode.W) {
moveBirdUp(); moveBirdUp();
System.out.println(currentBirdPosition); System.out.println(birdPositionMovedBy);
} }
}); });
@ -1080,12 +1087,12 @@ public class HappyBirdMain extends Application {
} }
private void moveBirdUp() { private void moveBirdUp() {
currentBirdPosition = currentBirdPosition - 10; birdPositionMovedBy = birdPositionMovedBy - 10;
happyBird.setLayoutY(currentBirdPosition); happyBird.setLayoutY(birdPositionMovedBy);
} }
private void moveBirdDown() { private void moveBirdDown() {
currentBirdPosition = currentBirdPosition + 10; birdPositionMovedBy = birdPositionMovedBy + 10;
happyBird.setLayoutY(currentBirdPosition); happyBird.setLayoutY(birdPositionMovedBy);
} }
} }