diff --git a/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin b/Happy_Bird/.gradle/7.1.1/executionHistory/executionHistory.bin index eeec7c9..953fd46 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 d362333..9bab711 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 5ed5863..1a254ae 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 3a7af6b..91e3a99 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 023877c..7d713d0 100644 Binary files a/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/Happy_Bird/.gradle/buildOutputCleanup/buildOutputCleanup.lock 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 1af60f5..0501cbc 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/libs/Happy_Bird-1.0-SNAPSHOT.jar b/Happy_Bird/build/libs/Happy_Bird-1.0-SNAPSHOT.jar index 70879aa..bb0781c 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 03d3caa..44957dd 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/HappyBirdMain.java b/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java index 425a61e..2c61986 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 @@ -2,10 +2,7 @@ package com.example.happy_bird; import javafx.application.Application; import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.Slider; -import javafx.scene.control.TextField; +import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; @@ -13,8 +10,11 @@ import javafx.scene.layout.*; import javafx.scene.text.TextAlignment; import javafx.stage.Stage; +import java.sql.ResultSet; + public class HappyBirdMain extends Application { + /*Datenbank einlesen*/ MariaDB datenbank = new MariaDB(); /*Panes erstellen und zuweisen*/ @@ -29,13 +29,14 @@ public class HappyBirdMain extends Application { private final Label acronymLabel = new Label("KÜRZEL"); private final Label headline = new Label("HAPPY BIRD"); private final Label soundLabel = new Label("SOUND"); - private final Label currentScoreLabel = new Label("SCORE"); - private final Label highscoreLabel = new Label("HIGHSCORE"); + private final Label currentScoreLabel = new Label("SCORE: "); + private final Label highscoreLabel = new Label("HIGHSCORE: "); private final Label pauseMenuLabel = new Label("PAUSE"); private final Label soundLabelPause = new Label("SOUND"); + private final Label highscoreMenuLabel = new Label(); /*Labels in Arrays speichern*/ - private final Label[] labels = {nameLabel, acronymLabel, soundLabel, currentScoreLabel, highscoreLabel}; + private final Label[] labels = {nameLabel, acronymLabel, soundLabel, currentScoreLabel, highscoreLabel, highscoreMenuLabel}; private final Label[] headlineLabels = {headline}; /*Buttons erstellen und zuweisen*/ @@ -110,6 +111,7 @@ public class HappyBirdMain extends Application { public void generateMenueScene() { + dataQuery(); menuScreenRunning = true; /*Bild für Hintergrund erstellen:*/ @@ -198,7 +200,8 @@ public class HappyBirdMain extends Application { */ public void generateGameScreen() { menuScreenRunning = false; - + int playerhighscore = getPlayerHighscore(); + highscoreLabel.setText("HIGHSCORE: " + playerhighscore); /*Headline-Label umbenennen*/ nameLabel.setText("KÜRZEL: " + acronym.getText()); @@ -494,6 +497,16 @@ public class HappyBirdMain extends Application { public void highscoresButtonClick() { /*Überschrift umbenennen*/ headline.setText("HIGHSCORES"); + /*Label für die Highscores einfügen und füllen*/ + highscoreMenuLabel.setLayoutX(275); + highscoreMenuLabel.setLayoutY(225); + highscoreMenuLabel.setPrefHeight(300); + highscoreMenuLabel.setPrefSize(250, 250); + highscoreMenuLabel.setVisible(true); + + String bestFiveHighscores = calculateHighscores(); + System.out.println(bestFiveHighscores); + highscoreMenuLabel.setText(bestFiveHighscores); /*nicht verwendete Buttons ausblenden, verwendete einblenden*/ startButton.setVisible(false); @@ -516,7 +529,7 @@ public class HappyBirdMain extends Application { settingsButton.setVisible(true); menuButton.setVisible(false); startGameButton.setVisible(false); - + highscoreMenuLabel.setVisible(false); /*soundSlider ausblenden*/ soundSlider.setVisible(false); @@ -650,4 +663,68 @@ public class HappyBirdMain extends Application { pane.getChildren().remove(pause); } } + + /*** + * Erste Datenabfrage als Test - wird später gelöscht + */ + public void dataQuery() + { + String dataquery = "SELECT * FROM happybirddb;"; + try (ResultSet rs = datenbank.st.executeQuery(dataquery)) { + while (rs.next()) + { + System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4)); + } + } + catch (Exception e) + { + System.out.println("Falsche Abfrage"); + } + } + + /*** + * getPlayerHighscore() berechnet den höchsten erreichten Wert des aktuellen Spielers + * (nicht den gesamt höchsten Highscore) + * + * @return den Highscore des aktuellen Spielers + */ + public int getPlayerHighscore() + { + int highscore = 0; + String playeracronym = acronym.getText(); + String sql = "SELECT MAX(punkte) FROM happybirddb WHERE kuerzel = '" + playeracronym + "';"; + System.out.println(sql); + try (ResultSet rs = datenbank.st.executeQuery(sql)) { + while (rs.next()) + { + highscore = rs.getInt(1); + } + } + catch (Exception e) + { + System.out.println("Falsche Abfrage"); + } + return highscore; + } + + /*** + * writeHighscores() gibt die Highscores aus ( die 5 höchsten Werte, die bis jetzt gespielt wurden ) + */ + public String calculateHighscores() + { + String bestFiveHighscores = "PLAYER\t\tSCORE\n\n"; + int i = 0; + String sql = "SELECT * FROM happybirddb ORDER BY punkte DESC LIMIT 5;"; + try (ResultSet rs = datenbank.st.executeQuery(sql)) { + while (rs.next()) + { + bestFiveHighscores+= rs.getString(4) + "\t" + rs.getString(3)+"\n"; + } + } + catch (Exception e) + { + System.out.println("Falsche Abfrage"); + } + return bestFiveHighscores; + } } \ No newline at end of file