Initial commit

master
2wenty1ne 2024-03-25 16:55:41 +01:00
commit 9c64c60544
11 changed files with 227 additions and 0 deletions

29
.gitignore vendored 100644
View File

@ -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

10
.idea/.gitignore vendored 100644
View File

@ -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

6
.idea/misc.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/untitled.iml" filepath="$PROJECT_DIR$/untitled.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,10 @@
public class BlackJackSpiel {
void BlackJackSpiel(){
}
Hand getNeueHand(){
return new Hand(new Kartenstapel());
}
}

7
src/Hand.java 100644
View File

@ -0,0 +1,7 @@
public class Hand {
Kartenstapel ks;
public Hand(Kartenstapel ks) {
this.ks = ks;
}
}

26
src/Karte.java 100644
View File

@ -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);
}
}

View File

@ -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();
}
}

36
src/Main.java 100644
View File

@ -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");
}
}

View File

@ -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());
}
}
}

49
untitled.iml 100644
View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.idea/copilot/chatSessions" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>