4.08.2020
This commit is contained in:
parent
ad568e0c77
commit
229204b417
|
@ -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,7 +46,6 @@ public class Main extends Application {
|
|||
Text info;
|
||||
@FXML
|
||||
Label title;
|
||||
|
||||
@FXML
|
||||
RadioButton easy;
|
||||
@FXML
|
||||
|
@ -52,8 +55,6 @@ public class Main extends Application {
|
|||
|
||||
// G A M E
|
||||
|
||||
|
||||
|
||||
private static final int COUNT_LIMIT = 10;
|
||||
|
||||
private String wort;
|
||||
|
@ -79,7 +80,7 @@ public class Main extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
// Button New Game
|
||||
// New Game
|
||||
public void newGame() {
|
||||
try {
|
||||
wort = newWord();
|
||||
|
@ -100,14 +101,15 @@ 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
|
||||
|
|
|
@ -23,14 +23,14 @@
|
|||
<children>
|
||||
<ImageView fitHeight="425.0" fitWidth="634.0">
|
||||
<image>
|
||||
<Image url="@../../../../../Desktop/test.gif" />
|
||||
<Image url="@../images/bg.gif" />
|
||||
</image>
|
||||
</ImageView>
|
||||
<ImageView fx:id="hangmanImage" fitHeight="202.0" fitWidth="256.0" layoutX="378.0" layoutY="223.0" pickOnBounds="true" preserveRatio="true">
|
||||
<effect>
|
||||
<Bloom threshold="0.0" />
|
||||
</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 size="41.0" />
|
||||
</font>
|
||||
|
@ -43,7 +43,7 @@
|
|||
<DropShadow color="#d70a0a" height="15.07" radius="7.775" spread="0.45" width="18.03" />
|
||||
</effect>
|
||||
</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>
|
||||
<Lighting surfaceScale="10.0">
|
||||
<bumpInput>
|
||||
|
|
BIN
HangmanFx/src/images/bg.gif
Normal file
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 |
BIN
HangmanFx/src/sounds/correct.mp3
Normal file
BIN
HangmanFx/src/sounds/correct.mp3
Normal file
Binary file not shown.
BIN
HangmanFx/src/sounds/gameover.mp3
Normal file
BIN
HangmanFx/src/sounds/gameover.mp3
Normal file
Binary file not shown.
BIN
HangmanFx/src/sounds/wrong.mp3
Normal file
BIN
HangmanFx/src/sounds/wrong.mp3
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user