commit c371e9eed6cbbb547447807161ddcae8167c415e Author: blues Date: Tue Jul 28 14:07:10 2020 +0200 Upload files diff --git a/HangmanFx/.classpath b/HangmanFx/.classpath new file mode 100644 index 0000000..ee00ee8 --- /dev/null +++ b/HangmanFx/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HangmanFx/.gitignore b/HangmanFx/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/HangmanFx/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/HangmanFx/.project b/HangmanFx/.project new file mode 100644 index 0000000..b568015 --- /dev/null +++ b/HangmanFx/.project @@ -0,0 +1,23 @@ + + + HangmanFx + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + + org.eclipse.xtext.ui.shared.xtextNature + org.eclipse.jdt.core.javanature + + diff --git a/HangmanFx/.settings/org.eclipse.jdt.core.prefs b/HangmanFx/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e2812ca --- /dev/null +++ b/HangmanFx/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/HangmanFx/build.fxbuild b/HangmanFx/build.fxbuild new file mode 100644 index 0000000..81b7fc3 --- /dev/null +++ b/HangmanFx/build.fxbuild @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/HangmanFx/src/application/HangmanPreload.java b/HangmanFx/src/application/HangmanPreload.java new file mode 100644 index 0000000..07f318b --- /dev/null +++ b/HangmanFx/src/application/HangmanPreload.java @@ -0,0 +1,32 @@ +package application; + +import javafx.application.Preloader; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import javafx.stage.StageStyle; + +public class HangmanPreload extends Preloader { + + private Stage preloaderStage; + private Scene scene; + + @Override + public void init() throws Exception { + Parent root1 = FXMLLoader.load(getClass().getResource("Preloader.fxml")); + scene = new Scene(root1); + } + + @Override + public void start(Stage primaryStage) throws Exception { + this.preloaderStage = primaryStage; + preloaderStage.setScene(scene); + preloaderStage.initStyle(StageStyle.UNDECORATED); + preloaderStage.show(); + + + } + +} + diff --git a/HangmanFx/src/application/Main.java b/HangmanFx/src/application/Main.java new file mode 100644 index 0000000..cd1d0b1 --- /dev/null +++ b/HangmanFx/src/application/Main.java @@ -0,0 +1,139 @@ +package application; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Random; + +import com.sun.javafx.application.LauncherImpl; + +import javafx.application.Application; +import javafx.application.Preloader; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.stage.Stage; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.text.Text; + +public class Main extends Application { + + // Scenebuilder + @FXML + Text text; + @FXML + ImageView hangmanImage; + @FXML + TextField textField; + @FXML + Text info; + + String wort; + String rightletterString; + + char[] wortToArr; + char[] displayWord; + + int counter = 1; + + @Override + public void start(Stage primaryStage) { + try { + Parent root = FXMLLoader.load(getClass().getResource("Ui.fxml")); + + Scene scene = new Scene(root); + scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); + primaryStage.setScene(scene); + primaryStage.setTitle("****HANGMAN****"); + primaryStage.show(); + + + } catch (Exception e) { + e.printStackTrace(); + } + } + + // Button New Game + public void newGame() { + try { + wort = newWord(); + wortToArr = wort.toCharArray(); + displayWord = new char[wortToArr.length]; + } catch (FileNotFoundException e) { + + e.printStackTrace(); + } + + for (int i = 0; i < wort.length(); i++) { + displayWord[i] = '-'; + } + String textfieldString = new String(displayWord); + text.setText(textfieldString); + counter = 1; + hangmanImage.setImage(null); + info.setText(""); + } + + // Check the letter input from Textfield + public boolean letterCheck(char[] wortToArr, char[] displayWord) { + + for (int i = 0; i < wort.length(); i++) { + if (wortToArr[i] == textField.getText().charAt(0)) { + displayWord[i] = wortToArr[i]; + return true; + } + + } + return false; + } + + // Button to confirm\check typed Letter + public void checkLetter() { + info.setText(""); + if (letterCheck(wortToArr, displayWord) == true) { + rightletterString = new String(displayWord); + text.setText(rightletterString); + info.setText("Richtig"); + + } else { + hangmanImage.setImage(new Image("/images/" + counter + ".png")); + info.setText("Falsch"); + counter++; + } + textField.clear(); + } + + // Returns a Word from txt file + public String newWord() throws FileNotFoundException { + Random random = new Random(); + String line; + ArrayList temp = new ArrayList(); + InputStream in = getClass().getResourceAsStream("/wort.txt"); + BufferedReader bf = new BufferedReader(new InputStreamReader(in)); + try { + while ((line = bf.readLine()) != null) { + temp.add(line); + } + } catch (IOException e) { + + e.getMessage(); + } + + return temp.get(random.nextInt(temp.size())).toString(); + } + + + + + + public static void main(String[] args) { + LauncherImpl.launchApplication(Main.class, HangmanPreload.class, args); + } + +} diff --git a/HangmanFx/src/application/Preloader.fxml b/HangmanFx/src/application/Preloader.fxml new file mode 100644 index 0000000..90d2d2f --- /dev/null +++ b/HangmanFx/src/application/Preloader.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/HangmanFx/src/application/Ui.fxml b/HangmanFx/src/application/Ui.fxml new file mode 100644 index 0000000..54d768f --- /dev/null +++ b/HangmanFx/src/application/Ui.fxml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + +