From 9c64c60544d76357358a4450e71e251503c6efa1 Mon Sep 17 00:00:00 2001 From: 2wenty1ne Date: Mon, 25 Mar 2024 16:55:41 +0100 Subject: [PATCH] Initial commit --- .gitignore | 29 ++++++++++++++++++++++++ .idea/.gitignore | 10 +++++++++ .idea/misc.xml | 6 +++++ .idea/modules.xml | 8 +++++++ src/BlackJackSpiel.java | 10 +++++++++ src/Hand.java | 7 ++++++ src/Karte.java | 26 ++++++++++++++++++++++ src/Kartenstapel.java | 31 ++++++++++++++++++++++++++ src/Main.java | 36 ++++++++++++++++++++++++++++++ tests/KarteTest.java | 15 +++++++++++++ untitled.iml | 49 +++++++++++++++++++++++++++++++++++++++++ 11 files changed, 227 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 src/BlackJackSpiel.java create mode 100644 src/Hand.java create mode 100644 src/Karte.java create mode 100644 src/Kartenstapel.java create mode 100644 src/Main.java create mode 100644 tests/KarteTest.java create mode 100644 untitled.iml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..a9d7db9 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6f29fee --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3007dae --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/BlackJackSpiel.java b/src/BlackJackSpiel.java new file mode 100644 index 0000000..8c868f6 --- /dev/null +++ b/src/BlackJackSpiel.java @@ -0,0 +1,10 @@ +public class BlackJackSpiel { + + void BlackJackSpiel(){ + + } + + Hand getNeueHand(){ + return new Hand(new Kartenstapel()); + } +} diff --git a/src/Hand.java b/src/Hand.java new file mode 100644 index 0000000..d25d7a0 --- /dev/null +++ b/src/Hand.java @@ -0,0 +1,7 @@ +public class Hand { + Kartenstapel ks; + + public Hand(Kartenstapel ks) { + this.ks = ks; + } +} diff --git a/src/Karte.java b/src/Karte.java new file mode 100644 index 0000000..c1d3a53 --- /dev/null +++ b/src/Karte.java @@ -0,0 +1,26 @@ +public class Karte { + String farbe; + String wert; + + public Karte(String farbe, String wert) { + this.farbe = farbe; + this.wert = wert; + } + + public int getPunkte() { + // 2, 3, 4, 5, 6, 7, 8, 9, 10, Bube, Dame, König, Ass + // 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 , 1 o. 11 + if ((this.wert.equals("Bube")) || (this.wert.equals("Dame")) || (this.wert.equals("König"))){ + return 10; + } + if (this.wert.equals("Ass")){ + return 11; + } + return Integer.parseInt(this.wert); + } + + @Override + public String toString() { + return String.format("%s %s", this.farbe, this.wert); + } +} diff --git a/src/Kartenstapel.java b/src/Kartenstapel.java new file mode 100644 index 0000000..cf792d0 --- /dev/null +++ b/src/Kartenstapel.java @@ -0,0 +1,31 @@ +public class Kartenstapel { + String[][] stapel; + Kartenstapel(){ + stapel = generateNewStapel(); + } + + String[][] generateNewStapel(){ + String[] possibleFarben = {"Herz", "Karo", "Schippe", "Kreuz"}; + String[] possibleWerte = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Bube", "Dame", "König", "Ass"}; + + String[][] returnStapel = new String[52][2]; + + int counter = 0; + for (String farbe : possibleFarben){ + for (String wert : possibleWerte){ + returnStapel[counter] = new String[]{farbe, wert}; + + counter ++; + } + } + return returnStapel; + } + + public String toString(){ + StringBuilder sb = new StringBuilder(); + for (String[] karte : stapel){ + sb.append(String.format("%s %s \n", karte[0], karte[1])); + } + return sb.toString(); + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..aefe0f1 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,36 @@ +import java.util.Scanner; + +public class Main { + static Scanner keyboard = new Scanner(System.in); + + public static void main(String[] args) { + System.out.println("Willkommen zum PR2 Blackjack!"); + gameLoop(); + } + + private static void gameLoop(){ + while (true){ + Kartenstapel ks = new Kartenstapel(); + System.out.println(ks); + + String newRoundPrombt = "Möchten Sie noch eine Runde spielen? (ja/nein)"; + boolean newRoundDecision = yesNoDecider(newRoundPrombt); + System.out.printf("Decision: %b %n", newRoundDecision); //? TEST + + if (!(newRoundDecision)) { + System.out.println("Auf Wiedersehen :)"); + break; + } + } + } + + + private static boolean yesNoDecider(String prombt){ + System.out.println(prombt); + System.out.print("> "); + String userInput = keyboard.nextLine(); + + return userInput.equalsIgnoreCase("ja"); + } + +} \ No newline at end of file diff --git a/tests/KarteTest.java b/tests/KarteTest.java new file mode 100644 index 0000000..d0c8f2f --- /dev/null +++ b/tests/KarteTest.java @@ -0,0 +1,15 @@ +import static org.junit.jupiter.api.Assertions.*; + +class KarteTest { + + @org.junit.jupiter.api.Test + void getPunkte() { + String[] successTestList = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Bube", "Dame", "König", "Ass"}; + int[] successResultList = {2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11}; + + for (int i = 0; i < successTestList.length; i++){ + Karte testKarte = new Karte("Herz", successTestList[i]); + assertEquals(successResultList[i], testKarte.getPunkte()); + } + } +} \ No newline at end of file diff --git a/untitled.iml b/untitled.iml new file mode 100644 index 0000000..66b6be0 --- /dev/null +++ b/untitled.iml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file