Anfänge des EndScreens - Methode für das Anzeigen der persönlichen Highscores
This commit is contained in:
parent
e494439b1c
commit
775085a1ab
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -14,6 +14,8 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class HappyBirdMain extends Application {
|
||||
/* Testen des Endscreens */
|
||||
private final Button endscreenTest = new Button("Endscreentest");
|
||||
|
||||
/*Datenbank einlesen*/
|
||||
MariaDB datenbank = new MariaDB();
|
||||
@ -43,6 +45,7 @@ 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 personalHighscoresButton = new Button ("YOUR HIGHSCORES");
|
||||
private final Button settingsButton = new Button("EINSTELLUNGEN");
|
||||
private final Button startGameButton = new Button("SPIEL STARTEN");
|
||||
private final Button menuButton = new Button("ZURÜCK");
|
||||
@ -55,7 +58,7 @@ public class HappyBirdMain extends Application {
|
||||
private final Button background2 = new Button();
|
||||
|
||||
/*Buttons in Arrays speichern*/
|
||||
private final Button[] buttons = {startButton, highscoresButton, settingsButton, startGameButton, menuButton, pauseButton, continueButton, settingsButtonPause, menuButtonPause, backButtonPause};
|
||||
private final Button[] buttons = {startButton, highscoresButton, personalHighscoresButton, settingsButton, startGameButton, menuButton, pauseButton, continueButton, settingsButtonPause, menuButtonPause, backButtonPause};
|
||||
private final Button[] pauseButtons = {continueButton, settingsButtonPause, menuButtonPause, backButtonPause};
|
||||
private final Button[] backgroundButtons = {background1, background2};
|
||||
|
||||
@ -776,8 +779,7 @@ public class HappyBirdMain extends Application {
|
||||
/***
|
||||
* Erste Datenabfrage als Test - wird später gelöscht
|
||||
*/
|
||||
public void dataQuery()
|
||||
{
|
||||
public void dataQuery() {
|
||||
String dataquery = "SELECT * FROM happybirddb;";
|
||||
try (ResultSet rs = datenbank.st.executeQuery(dataquery)) {
|
||||
while (rs.next())
|
||||
@ -797,8 +799,7 @@ public class HappyBirdMain extends Application {
|
||||
*
|
||||
* @return den Highscore des aktuellen Spielers
|
||||
*/
|
||||
public int getPlayerHighscore()
|
||||
{
|
||||
public int getPlayerHighscore() {
|
||||
int highscore = 0;
|
||||
String playeracronym = acronym.getText();
|
||||
String sql = "SELECT MAX(punkte) FROM happybirddb WHERE kuerzel = '" + playeracronym + "';";
|
||||
@ -817,10 +818,11 @@ public class HappyBirdMain extends Application {
|
||||
}
|
||||
|
||||
/***
|
||||
* writeHighscores() gibt die Highscores aus ( die 5 höchsten Werte, die bis jetzt gespielt wurden )
|
||||
* calculateHighscores() gibt die Highscores aus ( die 5 höchsten Werte, die bis jetzt gespielt wurden )
|
||||
*
|
||||
* @return die 5 höchsten erreichten Scores
|
||||
*/
|
||||
public String calculateHighscores()
|
||||
{
|
||||
public String calculateHighscores() {
|
||||
String bestFiveHighscores = "PLAYER\t\tSCORE\n\n";
|
||||
int i = 0;
|
||||
String sql = "SELECT * FROM happybirddb ORDER BY punkte DESC LIMIT 5;";
|
||||
@ -837,12 +839,34 @@ public class HappyBirdMain extends Application {
|
||||
return bestFiveHighscores;
|
||||
}
|
||||
|
||||
/***
|
||||
* calculatePersonalHighscores() berechnet die 5 höchsten erreichten Scores des aktuellen Spielers
|
||||
*
|
||||
* @return die 5 höchsten erreichten Scores des aktuellen Spielers
|
||||
*/
|
||||
public String calculatePersonalHighscores() {
|
||||
String bestFiveHighscores = "PLAYER\t\tSCORE\n\n";
|
||||
String currentPlayer = acronymLabel.getText();
|
||||
int i = 0;
|
||||
String sql = "SELECT * FROM happybirddb WHERE kuerzel = '" + currentPlayer + "' 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;
|
||||
}
|
||||
|
||||
/***
|
||||
* Fügt die erreichte Punktzahl des Spielers für den Spieler mit seinem Namen und Kürzel in die Datenbank ein
|
||||
* @param points die erreichten Punkte
|
||||
*/
|
||||
public void writeIntoDatabase(int points)
|
||||
{
|
||||
public void writeIntoDatabase(int points) {
|
||||
String playername = name.getText();
|
||||
String playeracronym = acronym.getText();
|
||||
/*String sql = "INSERT INTO happybirddb(name, kuerzel, punkte) VALUES ('" + playername + "', '" + points +
|
||||
@ -866,8 +890,7 @@ public class HappyBirdMain extends Application {
|
||||
*
|
||||
* @return true, wenn ja, sonst false
|
||||
*/
|
||||
public boolean correctName()
|
||||
{
|
||||
public boolean correctName() {
|
||||
String nametext = name.getText();
|
||||
if (!nametext.matches("[a-zA-ZÄÖÜäöüß ]*"))
|
||||
{
|
||||
@ -895,8 +918,7 @@ public class HappyBirdMain extends Application {
|
||||
* ( >= 3 Zeichen, <= 12 Zeichen, Groß- und Kleinbuchstaben, Zahlen 0-9 -- keine Sonderzeichen)
|
||||
* @return true, wenn ja, sonst false
|
||||
*/
|
||||
public boolean correctAcronym()
|
||||
{
|
||||
public boolean correctAcronym() {
|
||||
String acronymtext = acronym.getText();
|
||||
System.out.println(acronymtext.length());
|
||||
System.out.println(acronymtext);
|
||||
@ -912,4 +934,22 @@ public class HappyBirdMain extends Application {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void generateEndScreen() {
|
||||
/*Name und Highscores ausblenden, Pause-Button ausblenden*/
|
||||
nameLabel.setVisible(false);
|
||||
highscoreLabel.setVisible(false);
|
||||
pauseButton.setVisible(false);
|
||||
|
||||
/*Überschrift einblenden - Text auf Game Over setzen */
|
||||
headline.setVisible(true);
|
||||
headline.setText("GAME OVER");
|
||||
/*startGameButton anzeigen, Text zu "neu Starten" ändern und positionieren*/
|
||||
startGameButton.setVisible(true);
|
||||
startGameButton.setText("NEU STARTEN");
|
||||
/*Button fürs Hauptmenü einblenden und positionieren*/
|
||||
menuButton.setVisible(true);
|
||||
/*Button für persönliche Highscores einblenden und positionieren*/
|
||||
personalHighscoresButton.setVisible(true);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user