Labels für Hinweise zu Namens/Kürzelkonventionen eingefügt
This commit is contained in:
@@ -55,9 +55,11 @@ public class HappyBirdMain extends Application {
|
||||
private final Label highscoreMenuLabel = new Label();
|
||||
private final Label currentScoreEndscreenLabel = new Label("YOUR SCORE: ");
|
||||
private final Label endScreenHeadline = new Label("GAME OVER");
|
||||
private final Label checkNameLabel = new Label("");
|
||||
private final Label checkAcronymLabel = new Label("");
|
||||
|
||||
/*Labels in Arrays speichern*/
|
||||
private final Label[] labels = {nameLabel, acronymLabel, soundLabel, currentScoreLabel, highscoreLabel, highscoreMenuLabel};
|
||||
private final Label[] labels = {nameLabel, acronymLabel, soundLabel, currentScoreLabel, highscoreLabel, highscoreMenuLabel, checkAcronymLabel, checkNameLabel};
|
||||
private final Label[] headlineLabels = {headline};
|
||||
|
||||
/*Buttons erstellen und zuweisen*/
|
||||
@@ -501,6 +503,13 @@ public class HappyBirdMain extends Application {
|
||||
for(Button button : buttons) {
|
||||
button.setVisible(false);
|
||||
}
|
||||
/*Label für Namenskonventionen*/
|
||||
checkNameLabel.setLayoutX(15);
|
||||
checkNameLabel.setLayoutY(290);
|
||||
|
||||
/*Label für Kürzelkonventionen*/
|
||||
checkAcronymLabel.setLayoutX(15);
|
||||
checkAcronymLabel.setLayoutY(440);
|
||||
|
||||
/*gebrauchte Buttons einblenden, ggf. anpassen*/
|
||||
menuButton.setVisible(true);
|
||||
@@ -516,12 +525,15 @@ public class HappyBirdMain extends Application {
|
||||
for (Label label : labels ) {
|
||||
label.setVisible(true);
|
||||
}
|
||||
|
||||
System.out.println(name.getLayoutY());
|
||||
System.out.println(acronym.getLayoutY());
|
||||
/*nicht verwendete Labels ausblenden*/
|
||||
highscoreLabel.setVisible(false);
|
||||
currentScoreLabel.setVisible(false);
|
||||
soundLabel.setVisible(false);
|
||||
highscoreMenuLabel.setVisible(false);
|
||||
checkAcronymLabel.setVisible(false);
|
||||
checkNameLabel.setVisible(false);
|
||||
|
||||
/*Click-Events*/
|
||||
startGameButton.setOnAction(event -> startGameButtonClick());
|
||||
@@ -670,7 +682,7 @@ public class HappyBirdMain extends Application {
|
||||
* Startet Spiel nach Namenseingabe
|
||||
*/
|
||||
public void startGameButtonClick() {
|
||||
if (correctName() && correctAcronym())
|
||||
if (correctName() == 0 && correctAcronym() == 0)
|
||||
{
|
||||
generateGameScreen();
|
||||
System.out.println(gameRunning);
|
||||
@@ -704,6 +716,26 @@ public class HappyBirdMain extends Application {
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
checkNameLabel.setVisible(false);
|
||||
checkAcronymLabel.setVisible(false);
|
||||
if (correctName() == 1) {
|
||||
checkNameLabel.setText("nicht erlaubte Zeichen!");
|
||||
checkNameLabel.setVisible(true);
|
||||
} else if (correctName() == 2) {
|
||||
checkNameLabel.setText("1. Buchstabe muss groß!");
|
||||
checkNameLabel.setVisible(true);
|
||||
} else if (correctName() == 3) {
|
||||
checkNameLabel.setText("Name nicht leer!");
|
||||
checkNameLabel.setVisible(true);
|
||||
}
|
||||
if (correctAcronym() == 1) {
|
||||
checkAcronymLabel.setText("nicht erlaubte Zeichen!");
|
||||
checkAcronymLabel.setVisible(true);
|
||||
} else if (correctAcronym() == 2) {
|
||||
checkAcronymLabel.setText("Länge 3-10 Zeichen!");
|
||||
checkAcronymLabel.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -942,51 +974,56 @@ public class HappyBirdMain extends Application {
|
||||
* Überprüft, ob der eingegebene Name den Vorgaben entspricht
|
||||
* (Erlaubte Zeichen: Groß- und Kleinbuchstaben, Umlaute und Leerzeichen
|
||||
*
|
||||
* @return true, wenn ja, sonst false
|
||||
* @return 0, wenn ja,
|
||||
* sonst: 1, wenn nicht erlaubte Zeichen verwendet
|
||||
* 2, wenn der 1. Buchstabe kleingeschrieben ist
|
||||
* 3, wenn der Name leer ist
|
||||
*/
|
||||
public boolean correctName() {
|
||||
public int correctName() {
|
||||
String nametext = name.getText();
|
||||
if (!nametext.matches("[a-zA-ZÄÖÜäöüß ]*"))
|
||||
{
|
||||
System.out.println("Fehler Schreibweise Name - nicht erlaubte Zeichen");
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
if (nametext.length() > 0)
|
||||
{
|
||||
if (nametext.charAt(0) < 'A' || nametext.charAt(0) > 'Z')
|
||||
{
|
||||
System.out.println("Fehler Schreibweise Name - 1. Buchstabe muss großgeschrieben werden");
|
||||
return false;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Name darf nicht leer sein");
|
||||
return false;
|
||||
return 3;
|
||||
}
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
* Überprüft, ob das eingegebene Akronym den Vorgaben entspricht
|
||||
* ( >= 3 Zeichen, <= 12 Zeichen, Groß- und Kleinbuchstaben, Zahlen 0-9 -- keine Sonderzeichen)
|
||||
* @return true, wenn ja, sonst false
|
||||
* @return 0, wenn ja,
|
||||
* sonst: 1, wenn die Länge nicht korrekt ist
|
||||
* 2, wenn nicht erlaubte Zeichen verwendet werden
|
||||
*/
|
||||
public boolean correctAcronym() {
|
||||
public int correctAcronym() {
|
||||
String acronymtext = acronym.getText();
|
||||
System.out.println(acronymtext.length());
|
||||
System.out.println(acronymtext);
|
||||
if (acronymtext.length() < 3 || acronymtext.length() > 10)
|
||||
{
|
||||
System.out.println("Fehler Länge Kürzel (3-10 Zeichen)");
|
||||
return false;
|
||||
}
|
||||
if (!acronymtext.matches("[A-Za-z0-9]*"))
|
||||
{
|
||||
System.out.println("Fehler Schreibweise Kürzel - nur Buchstaben und Zahlen erlaubt");
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
return true;
|
||||
if (acronymtext.length() < 3 || acronymtext.length() > 10)
|
||||
{
|
||||
System.out.println("Fehler Länge Kürzel (3-10 Zeichen)");
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
|
Reference in New Issue
Block a user