Alles nochmal korrigiert/optimiert und JUnit Tests für die Punkte Verrechnung.
parent
dde68f1784
commit
a57232941e
|
@ -4,8 +4,25 @@
|
|||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<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>
|
|
@ -3,6 +3,12 @@ package de.hs_mannheim.informatik.blackjack;
|
|||
import java.util.Scanner;
|
||||
|
||||
public class BlackJackSpiel {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
BlackJackSpiel spiel = new BlackJackSpiel();
|
||||
|
||||
}
|
||||
public BlackJackSpiel(){
|
||||
|
||||
System.out.println("Willkommen zum BlackJack Trainer");
|
||||
|
|
|
@ -6,6 +6,13 @@ public class Hand {
|
|||
|
||||
private ArrayList<Karte> hand = new ArrayList<>();
|
||||
|
||||
|
||||
Hand(Karte... karte){
|
||||
for(int i = 0; i<karte.length; i++){
|
||||
hand.add(karte[i]);
|
||||
}
|
||||
|
||||
}
|
||||
Hand(Kartenstapel ks){
|
||||
hand.add(ks.getKarte());
|
||||
hand.add(ks.getKarte());
|
||||
|
@ -22,10 +29,49 @@ public class Hand {
|
|||
|
||||
public int getPunkte(){
|
||||
int ergebnis = 0;
|
||||
int counterAss = 0;
|
||||
|
||||
for(int i = 0; i<hand.size(); i++){
|
||||
ergebnis += hand.get(i).getPunkte(hand);
|
||||
if(hand.get(i).karte.equals("Ass"))
|
||||
counterAss++;
|
||||
}
|
||||
return ergebnis;
|
||||
|
||||
for(int i = 0; i<hand.size(); i++){
|
||||
ergebnis += hand.get(i).getPunkte();
|
||||
}
|
||||
|
||||
if(counterAss==1) {
|
||||
for (int i = 0; i < hand.size(); i++) {
|
||||
if (hand.get(i).karte.equals("Ass") && ergebnis <= 10) {
|
||||
ergebnis += 11;
|
||||
} else if(hand.get(i).karte.equals("Ass"))
|
||||
ergebnis += 1;
|
||||
}
|
||||
} else if(counterAss==2){
|
||||
for (int i = 0; i < hand.size(); i++) {
|
||||
if (hand.get(i).karte.equals("Ass") && ergebnis <= 9) {
|
||||
ergebnis += 11;
|
||||
} else if(hand.get(i).karte.equals("Ass"))
|
||||
ergebnis += 1;
|
||||
}
|
||||
} else if(counterAss==3){
|
||||
for (int i = 0; i < hand.size(); i++) {
|
||||
if (hand.get(i).karte.equals("Ass") && ergebnis <= 8) {
|
||||
ergebnis += 11;
|
||||
} else if(hand.get(i).karte.equals("Ass"))
|
||||
ergebnis += 1;
|
||||
}
|
||||
} else if(counterAss==4){
|
||||
for (int i = 0; i < hand.size(); i++) {
|
||||
if (hand.get(i).karte.equals("Ass") && ergebnis <= 7) {
|
||||
ergebnis += 11;
|
||||
} else if(hand.get(i).karte.equals("Ass"))
|
||||
ergebnis += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ergebnis;
|
||||
}
|
||||
|
||||
public boolean isBlackJack(){
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package de.hs_mannheim.informatik.blackjack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Karte {
|
||||
|
||||
private String farbe;
|
||||
private String karte;
|
||||
String farbe;
|
||||
String karte;
|
||||
|
||||
|
||||
|
||||
|
@ -20,84 +19,12 @@ public class Karte {
|
|||
return farbe + " " + karte;
|
||||
}
|
||||
|
||||
public int getPunkte(ArrayList<Karte> hand){
|
||||
|
||||
int counter = 0;
|
||||
for(int i = 0; i<hand.size(); i++){
|
||||
if(hand.get(i).karte.equals("Ass"))
|
||||
counter ++;
|
||||
}
|
||||
public int getPunkte(){
|
||||
|
||||
if(karte.equals("Bube")||karte.equals("Dame")||karte.equals("König"))
|
||||
return 10;
|
||||
else if(karte.equals("Ass")&&counter==1) {
|
||||
int entscheidung = 0;
|
||||
for(int i = 0; i<hand.size(); i++) {
|
||||
if (hand.get(i).karte.equals("Bube")||hand.get(i).karte.equals("Dame")||hand.get(i).karte.equals("König")) {
|
||||
entscheidung += 10;
|
||||
} else if (!hand.get(i).karte.equals("Ass")) {
|
||||
entscheidung += Integer.parseInt(hand.get(i).karte);
|
||||
}
|
||||
}
|
||||
if (entscheidung<=10)
|
||||
return 11;
|
||||
else
|
||||
return 1;
|
||||
}else if(karte.equals("Ass")&&counter==2) {
|
||||
int entscheidung = 0;
|
||||
int counterAss = 0;
|
||||
for(int i = 0; i<hand.size(); i++) {
|
||||
|
||||
if (hand.get(i).karte.equals("Bube")||hand.get(i).karte.equals("Dame")||hand.get(i).karte.equals("König")) {
|
||||
entscheidung += 10;
|
||||
} else if (!hand.get(i).karte.equals("Ass")) {
|
||||
entscheidung += Integer.parseInt(hand.get(i).karte);
|
||||
} else if(counterAss<1) {
|
||||
entscheidung += 1;
|
||||
counterAss ++;
|
||||
}
|
||||
}
|
||||
if (entscheidung<=10)
|
||||
return 11;
|
||||
else
|
||||
return 1;
|
||||
}else if(karte.equals("Ass")&&counter==3) {
|
||||
int entscheidung = 0;
|
||||
int counterAss = 0;
|
||||
for(int i = 0; i<hand.size(); i++) {
|
||||
|
||||
if (hand.get(i).karte.equals("Bube")||hand.get(i).karte.equals("Dame")||hand.get(i).karte.equals("König")) {
|
||||
entscheidung += 10;
|
||||
} else if (!hand.get(i).karte.equals("Ass")) {
|
||||
entscheidung += Integer.parseInt(hand.get(i).karte);
|
||||
} else if(counterAss<2) {
|
||||
entscheidung += 1;
|
||||
counterAss ++;
|
||||
}
|
||||
}
|
||||
if (entscheidung<=10)
|
||||
return 11;
|
||||
else
|
||||
return 1;
|
||||
}else if(karte.equals("Ass")&&counter==4) {
|
||||
int entscheidung = 0;
|
||||
int counterAss = 0;
|
||||
for(int i = 0; i<hand.size(); i++) {
|
||||
|
||||
if (hand.get(i).karte.equals("Bube")||hand.get(i).karte.equals("Dame")||hand.get(i).karte.equals("König")) {
|
||||
entscheidung += 10;
|
||||
} else if (!hand.get(i).karte.equals("Ass")) {
|
||||
entscheidung += Integer.parseInt(hand.get(i).karte);
|
||||
} else if(counterAss<3) {
|
||||
entscheidung += 1;
|
||||
counterAss ++;
|
||||
}
|
||||
}
|
||||
if (entscheidung<=10)
|
||||
return 11;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
else if(karte.equals("Ass"))
|
||||
return 0;
|
||||
else
|
||||
return Integer.parseInt(karte);
|
||||
}
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package de.hs_mannheim.informatik.blackjack;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
BlackJackSpiel spiel = new BlackJackSpiel();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package de.hs_mannheim.informatik.blackjack;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class HandKarteTest {
|
||||
|
||||
@Test
|
||||
void getPunkte() {
|
||||
|
||||
Kartenstapel ks = new Kartenstapel();
|
||||
Hand handRandom = new Hand(ks);
|
||||
Hand hand1 = new Hand(new Karte("Pik","Bube"),new Karte("Herz","Ass"));
|
||||
Hand hand2 = new Hand(new Karte("Karo","Ass"),new Karte("Herz","9"),new Karte("Herz","5"));
|
||||
Hand hand3 = new Hand(new Karte("Pik","Ass"),new Karte("Herz","Ass"));
|
||||
Hand hand4 = new Hand(new Karte("Herz","9"),new Karte("Karo","Bube"),new Karte("Pik","Ass"));
|
||||
Hand hand5 = new Hand(new Karte("Pik","Ass"),new Karte("Herz","Ass"),new Karte("Karo","Ass"),new Karte("Kreuz","Ass"));
|
||||
|
||||
|
||||
assertNotNull(handRandom);
|
||||
assertTrue(hand1.isBlackJack());
|
||||
|
||||
assertEquals(15,hand2.getPunkte());
|
||||
assertEquals(12,hand3.getPunkte());
|
||||
assertEquals(20,hand4.getPunkte());
|
||||
assertEquals(14,hand5.getPunkte());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue