commit b25c703e0aad42ca3e14a10b19d893b152595b95 Author: 3002652 <3002652@hs-mannheim.de> Date: Sat Jan 14 19:54:58 2023 +0100 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..57bca72 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..e05f1c2 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Galgen + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +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.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/src/Galgenmann.java b/src/Galgenmann.java new file mode 100644 index 0000000..99c7d34 --- /dev/null +++ b/src/Galgenmann.java @@ -0,0 +1,192 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Scanner; + +public class Galgenmann { + + static HashMap memory = new HashMap<>(); + //test + public static void main(String[] args) throws FileNotFoundException { + Scanner sc = new Scanner(new File("src/tiere.txt")); + boolean programm = true; + ArrayList animals = new ArrayList<>(); + ArrayList zufallstier = new ArrayList<>(); + ArrayList kleineschreibweise = new ArrayList<>(); + int fehlversuche = 0; + while (sc.hasNext()) { + String tier = sc.next(); + animals.add(tier); + } + sc.close(); + int zufall = (int) (Math.random() * animals.size() - 1); + String loesung= animals.get(zufall); + String[] buchstaben = loesung.split(""); + + for (int i = 0; i < buchstaben.length; i++) { + zufallstier.add(buchstaben[i]); + memory.put(i, "_ "); + kleineschreibweise.add(buchstaben[i].toLowerCase()); + } + System.out.println("***************************************"); + System.out.println("*****Willkommen bei Galgenmännchen*****"); + System.out.println("***************************************"); + System.out.println(); + System.out.println("Sie können zur jederzeit das Spiel verlassen mit der Eingabe #quit"); + System.out.println(); + System.out.println(); + while (programm) { + Scanner scan = new Scanner(System.in); + System.out.println("Raten sie die Buchstaben"); + // neu + for(int i = 0;i"); + System.out.println(); + System.out.println(); + String geraten = scan.next(); + + + for (int i = 0; i < zufallstier.size(); i++) { + if (zufallstier.get(i).equalsIgnoreCase(geraten)) { + memory.replace(i, zufallstier.get(i)); + } + } + if(geraten.equals("#quit")) { + System.out.println("Sie beenden das Programm"); + break; + } + if (!kleineschreibweise.contains(geraten)) { + + fehlversuche++; + } + for (int i = 0; i < memory.size(); i++) { + System.out.print(memory.get(i) ); + } + if (!memory.containsValue("_ ")) { + System.out.println(" Du hast gewonnen !!"); + programm = false; + fehlversuche = 10; + } + switch (fehlversuche) { + case 0: + System.out.println(); + System.out.println(); + System.out.println(" \\ ||"); + System.out.println(" \\ ||"); + System.out.println(" \\||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println("---------------"); + break; + case 1: + System.out.println(); + System.out.println(); + System.out.println(" ----------"); + System.out.println(" \\ ||"); + System.out.println(" \\ ||"); + System.out.println(" \\||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println("---------------"); + break; + case 2: + System.out.println(); + System.out.println(); + System.out.println(" ----------"); + System.out.println(" | ||"); + System.out.println(" | ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println("---------------"); + break; + case 3: + System.out.println(); + System.out.println(); + System.out.println(" ----------"); + System.out.println(" | ||"); + System.out.println(" | ||"); + System.out.println(" o ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println("---------------"); + break; + case 4: + System.out.println(); + System.out.println(); + System.out.println(" ----------"); + System.out.println(" | ||"); + System.out.println(" | ||"); + System.out.println(" o ||"); + System.out.println(" | ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println("---------------"); + break; + case 5: + System.out.println(); + System.out.println(); + System.out.println(" ----------"); + System.out.println(" | ||"); + System.out.println(" | ||"); + System.out.println(" o ||"); + System.out.println(" -| ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println("---------------"); + break; + case 6: + System.out.println(); + System.out.println(); + System.out.println(" ----------"); + System.out.println(" | ||"); + System.out.println(" | ||"); + System.out.println(" o ||"); + System.out.println(" -|- ||"); + System.out.println(" ||"); + System.out.println(" ||"); + System.out.println("---------------"); + break; + case 7: + System.out.println(); + System.out.println(); + System.out.println(" ----------"); + System.out.println(" | ||"); + System.out.println(" | ||"); + System.out.println(" o ||"); + System.out.println(" -|- ||"); + System.out.println(" / ||"); + System.out.println(" ||"); + System.out.println("---------------"); + break; + case 8: + System.out.println(); + System.out.println(); + System.out.println(" ----------"); + System.out.println(" | ||"); + System.out.println(" | ||"); + System.out.println(" o ||"); + System.out.println(" -|- ||"); + System.out.println(" / \\ ||"); + System.out.println(" ||"); + System.out.println("---------------"); + System.out.println("Du hast verloren"); + System.out.println("Die Lösung lautet : "+loesung); + + programm=false; + + + + } + } + } +} \ No newline at end of file diff --git a/src/tiere.txt b/src/tiere.txt new file mode 100644 index 0000000..edafdaa --- /dev/null +++ b/src/tiere.txt @@ -0,0 +1,79 @@ + Affe + Gorilla + Schimpanse + Schneeaffe + Elefant + Giraffe + Nashorn + Braunbär + Eisbär + Grizzly + Nasenbär + Panda + Hai + Koi + Krebs + Wels + Hund + Katze + Alpaka + Bison + Elch + Esel + Kamel + Lama + Pferd + Reh + Schaf + Tapir + Ziege + Ameise + Biene + Schabe + Delfin + Robbe + Wal + Biber + Chinchilla + Eichhörnchen + Hamster + Kaninchen + Meerschweinchen + Maus + Nacktmull + Alligator + Frosch + Gecko + Leguan + Reptil + Schildkröte + Waran + Schwein + Wildschweie + Adler + Alpensegler + Eule + Falke + Huhn + Mauerseegler + Meise + Papagei + Pinguin + Rotkehlchen + Sittich + Storch + Taube + Vogel + Gepard + Jaguar + Leopard + Luchs + Löwe + Tiger + Erdmännchen + Fledermaus + Koala + Otter + Qualle + Spinne + Wolf \ No newline at end of file