From 229204b417928054896bd8b18b45457d09686513 Mon Sep 17 00:00:00 2001 From: blues Date: Tue, 4 Aug 2020 14:51:23 +0200 Subject: [PATCH] 4.08.2020 --- HangmanFx/src/application/Main.java | 54 ++++++++++++++++++---------- HangmanFx/src/application/Ui.fxml | 6 ++-- HangmanFx/src/images/bg.gif | Bin 0 -> 871755 bytes HangmanFx/src/images/bg.jpg | Bin 10386 -> 0 bytes HangmanFx/src/sounds/correct.mp3 | Bin 0 -> 86081 bytes HangmanFx/src/sounds/gameover.mp3 | Bin 0 -> 63497 bytes HangmanFx/src/sounds/wrong.mp3 | Bin 0 -> 30477 bytes 7 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 HangmanFx/src/images/bg.gif delete mode 100644 HangmanFx/src/images/bg.jpg create mode 100644 HangmanFx/src/sounds/correct.mp3 create mode 100644 HangmanFx/src/sounds/gameover.mp3 create mode 100644 HangmanFx/src/sounds/wrong.mp3 diff --git a/HangmanFx/src/application/Main.java b/HangmanFx/src/application/Main.java index 513244b..c445adf 100644 --- a/HangmanFx/src/application/Main.java +++ b/HangmanFx/src/application/Main.java @@ -11,6 +11,8 @@ import java.util.Random; import java.util.ResourceBundle; import com.sun.javafx.application.LauncherImpl; +import com.sun.javafx.scene.EnteredExitedHandler; +import com.sun.media.jfxmedia.events.PlayerEvent; import javafx.application.Application; import javafx.application.Preloader; @@ -27,6 +29,8 @@ import javafx.scene.control.TextField; import javafx.scene.control.ToggleGroup; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.media.AudioClip; +import javafx.scene.media.MediaPlayer; import javafx.scene.text.Text; public class Main extends Application { @@ -42,17 +46,14 @@ public class Main extends Application { Text info; @FXML Label title; - @FXML RadioButton easy; @FXML RadioButton medium; @FXML RadioButton hard; - - // G A M E - + // G A M E private static final int COUNT_LIMIT = 10; @@ -79,7 +80,7 @@ public class Main extends Application { } } - // Button New Game + // New Game public void newGame() { try { wort = newWord(); @@ -100,16 +101,17 @@ public class Main extends Application { info.setText(""); } - // Check the letter input from Textfield + // Check the letter from Textfield public boolean letterCheck(char[] wortToArr, char[] displayWord) { for (int i = 0; i < wort.length(); i++) { if (letter.getText().isEmpty() == false) { - if(wortToArr[i] == letter.getText().toLowerCase().charAt(0) || wortToArr[i] == letter.getText().toUpperCase().charAt(0)) { - displayWord[i] = wortToArr[i]; - return true; + if (wortToArr[i] == letter.getText().toLowerCase().charAt(0) + || wortToArr[i] == letter.getText().toUpperCase().charAt(0)) { + displayWord[i] = wortToArr[i]; + return true; } - + } } @@ -119,21 +121,33 @@ public class Main extends Application { // Confirm\check typed Letter public void checkLetter() { info.setText(""); + if (letterCheck(wortToArr, displayWord) == true) { rightletterString = new String(displayWord); hangmanWord.setText(rightletterString); info.setText("Richtig"); + + AudioClip correctLetter = new AudioClip( + this.getClass().getResource("/sounds/correct.mp3").toExternalForm()); + correctLetter.play(); } else { hangmanImage.setImage(new Image("/images/" + counter + ".png")); info.setText("Falsch"); + + if (counter < 15) { + AudioClip wrongLetter = new AudioClip( + this.getClass().getResource("/sounds/wrong.mp3").toExternalForm()); + wrongLetter.play(); + } counter++; } letter.clear(); if (counter == 16) { hangmanWord.setText(wort); - + AudioClip wrongLetter = new AudioClip(this.getClass().getResource("/sounds/gameover.mp3").toExternalForm()); + wrongLetter.play(); } } @@ -159,30 +173,34 @@ public class Main extends Application { return temp.get(random.nextInt(temp.size())).toString(); } - // Returns the difficult wordlist + // Returns the difficulty of Wordlist public InputStream difficult() { String easy = "/wordlists/wordeasy.txt"; String medium = "/wordlists/wordmedium.txt"; String hard = "/wordlists/wordhard.txt"; - InputStream in = null; + InputStream difficult = null; if (this.easy.isSelected()) { - in = getClass().getResourceAsStream(easy); + difficult = getClass().getResourceAsStream(easy); } if (this.medium.isSelected()) { - in = getClass().getResourceAsStream(medium); + difficult = getClass().getResourceAsStream(medium); } if (this.hard.isSelected()) { - in = getClass().getResourceAsStream(hard); + difficult = getClass().getResourceAsStream(hard); } else { - in = getClass().getResourceAsStream(easy); + difficult = getClass().getResourceAsStream(easy); } - return in; + return difficult; + } +// Exit Game + public void exit() { + System.exit(0); } // Preloader diff --git a/HangmanFx/src/application/Ui.fxml b/HangmanFx/src/application/Ui.fxml index d934f01..615b3e7 100644 --- a/HangmanFx/src/application/Ui.fxml +++ b/HangmanFx/src/application/Ui.fxml @@ -23,14 +23,14 @@ - + - + @@ -43,7 +43,7 @@ -