4.08.2020

This commit is contained in:
blues 2020-08-04 14:51:23 +02:00
parent ad568e0c77
commit 229204b417
7 changed files with 39 additions and 21 deletions

View File

@ -11,6 +11,8 @@ import java.util.Random;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import com.sun.javafx.application.LauncherImpl; 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.Application;
import javafx.application.Preloader; import javafx.application.Preloader;
@ -27,6 +29,8 @@ import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup; import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.media.AudioClip;
import javafx.scene.media.MediaPlayer;
import javafx.scene.text.Text; import javafx.scene.text.Text;
public class Main extends Application { public class Main extends Application {
@ -42,17 +46,14 @@ public class Main extends Application {
Text info; Text info;
@FXML @FXML
Label title; Label title;
@FXML @FXML
RadioButton easy; RadioButton easy;
@FXML @FXML
RadioButton medium; RadioButton medium;
@FXML @FXML
RadioButton hard; RadioButton hard;
// G A M E
// G A M E
private static final int COUNT_LIMIT = 10; private static final int COUNT_LIMIT = 10;
@ -79,7 +80,7 @@ public class Main extends Application {
} }
} }
// Button New Game // New Game
public void newGame() { public void newGame() {
try { try {
wort = newWord(); wort = newWord();
@ -100,16 +101,17 @@ public class Main extends Application {
info.setText(""); info.setText("");
} }
// Check the letter input from Textfield // Check the letter from Textfield
public boolean letterCheck(char[] wortToArr, char[] displayWord) { public boolean letterCheck(char[] wortToArr, char[] displayWord) {
for (int i = 0; i < wort.length(); i++) { for (int i = 0; i < wort.length(); i++) {
if (letter.getText().isEmpty() == false) { if (letter.getText().isEmpty() == false) {
if(wortToArr[i] == letter.getText().toLowerCase().charAt(0) || wortToArr[i] == letter.getText().toUpperCase().charAt(0)) { if (wortToArr[i] == letter.getText().toLowerCase().charAt(0)
displayWord[i] = wortToArr[i]; || wortToArr[i] == letter.getText().toUpperCase().charAt(0)) {
return true; displayWord[i] = wortToArr[i];
return true;
} }
} }
} }
@ -119,21 +121,33 @@ public class Main extends Application {
// Confirm\check typed Letter // Confirm\check typed Letter
public void checkLetter() { public void checkLetter() {
info.setText(""); info.setText("");
if (letterCheck(wortToArr, displayWord) == true) { if (letterCheck(wortToArr, displayWord) == true) {
rightletterString = new String(displayWord); rightletterString = new String(displayWord);
hangmanWord.setText(rightletterString); hangmanWord.setText(rightletterString);
info.setText("Richtig"); info.setText("Richtig");
AudioClip correctLetter = new AudioClip(
this.getClass().getResource("/sounds/correct.mp3").toExternalForm());
correctLetter.play();
} else { } else {
hangmanImage.setImage(new Image("/images/" + counter + ".png")); hangmanImage.setImage(new Image("/images/" + counter + ".png"));
info.setText("Falsch"); info.setText("Falsch");
if (counter < 15) {
AudioClip wrongLetter = new AudioClip(
this.getClass().getResource("/sounds/wrong.mp3").toExternalForm());
wrongLetter.play();
}
counter++; counter++;
} }
letter.clear(); letter.clear();
if (counter == 16) { if (counter == 16) {
hangmanWord.setText(wort); 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(); return temp.get(random.nextInt(temp.size())).toString();
} }
// Returns the difficult wordlist // Returns the difficulty of Wordlist
public InputStream difficult() { public InputStream difficult() {
String easy = "/wordlists/wordeasy.txt"; String easy = "/wordlists/wordeasy.txt";
String medium = "/wordlists/wordmedium.txt"; String medium = "/wordlists/wordmedium.txt";
String hard = "/wordlists/wordhard.txt"; String hard = "/wordlists/wordhard.txt";
InputStream in = null; InputStream difficult = null;
if (this.easy.isSelected()) { if (this.easy.isSelected()) {
in = getClass().getResourceAsStream(easy); difficult = getClass().getResourceAsStream(easy);
} }
if (this.medium.isSelected()) { if (this.medium.isSelected()) {
in = getClass().getResourceAsStream(medium); difficult = getClass().getResourceAsStream(medium);
} }
if (this.hard.isSelected()) { if (this.hard.isSelected()) {
in = getClass().getResourceAsStream(hard); difficult = getClass().getResourceAsStream(hard);
} else { } else {
in = getClass().getResourceAsStream(easy); difficult = getClass().getResourceAsStream(easy);
} }
return in; return difficult;
}
// Exit Game
public void exit() {
System.exit(0);
} }
// Preloader // Preloader

View File

@ -23,14 +23,14 @@
<children> <children>
<ImageView fitHeight="425.0" fitWidth="634.0"> <ImageView fitHeight="425.0" fitWidth="634.0">
<image> <image>
<Image url="@../../../../../Desktop/test.gif" /> <Image url="@../images/bg.gif" />
</image> </image>
</ImageView> </ImageView>
<ImageView fx:id="hangmanImage" fitHeight="202.0" fitWidth="256.0" layoutX="378.0" layoutY="223.0" pickOnBounds="true" preserveRatio="true"> <ImageView fx:id="hangmanImage" fitHeight="202.0" fitWidth="256.0" layoutX="378.0" layoutY="223.0" pickOnBounds="true" preserveRatio="true">
<effect> <effect>
<Bloom threshold="0.0" /> <Bloom threshold="0.0" />
</effect></ImageView> </effect></ImageView>
<TextField fx:id="letter" disable="true" layoutX="37.0" layoutY="298.0" prefHeight="72.0" prefWidth="82.0" promptText="..."> <TextField fx:id="letter" disable="true" layoutX="37.0" layoutY="298.0" onKeyReleased="#checkLetter" prefHeight="72.0" prefWidth="82.0" promptText="...">
<font> <font>
<Font size="41.0" /> <Font size="41.0" />
</font> </font>
@ -43,7 +43,7 @@
<DropShadow color="#d70a0a" height="15.07" radius="7.775" spread="0.45" width="18.03" /> <DropShadow color="#d70a0a" height="15.07" radius="7.775" spread="0.45" width="18.03" />
</effect> </effect>
</Text> </Text>
<Button layoutX="144.0" layoutY="342.0" mnemonicParsing="false" onAction="#checkLetter" prefHeight="33.0" prefWidth="155.0" text="Bestätigen"> <Button layoutX="144.0" layoutY="342.0" mnemonicParsing="false" onAction="#exit" prefHeight="33.0" prefWidth="155.0" text="Exit">
<effect> <effect>
<Lighting surfaceScale="10.0"> <Lighting surfaceScale="10.0">
<bumpInput> <bumpInput>

BIN
HangmanFx/src/images/bg.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 851 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.