diff --git a/Test/src/Card.java b/Test/src/Card.java index 382de91..c0d0fd8 100644 --- a/Test/src/Card.java +++ b/Test/src/Card.java @@ -2,6 +2,8 @@ public class Card { public String card_value = "0"; public String color = "Blue"; + public int ass_value = 11; + public Card(String color, String card_value) { this.color = color; @@ -15,7 +17,7 @@ public class Card { public int get_points(Card card) { return switch (card.card_value) { - case "Ass" -> 1; + case "Ass" -> ass_value; case "King", "Dame", "Bube", "10" -> 10; case "9" -> 9; case "8" -> 8; diff --git a/Test/src/CardStack.java b/Test/src/CardStack.java index 7521fca..370da1d 100644 --- a/Test/src/CardStack.java +++ b/Test/src/CardStack.java @@ -39,7 +39,7 @@ public class CardStack { public Card draw_card() { - if (card_draw_counter > 52) { + if (card_draw_counter > 51) { throw new RuntimeException("Keine Karten mehr"); } diff --git a/Test/src/Hand.java b/Test/src/Hand.java index e5b5fa7..3929243 100644 --- a/Test/src/Hand.java +++ b/Test/src/Hand.java @@ -3,9 +3,11 @@ public class Hand { private Card[] current_hand = new Card[11]; private int current_points; CardStack cs; + public int old_hand_counter; public Hand(CardStack cs) { - cs.card_draw_counter = 0; + old_hand_counter = cs.card_draw_counter; + this.cs = cs; current_hand[0] = cs.draw_card(); current_hand[1] = cs.draw_card(); @@ -15,7 +17,7 @@ public class Hand { public String toString() { String return_message = "Die Karten sind: "; - for (int i = 0; i < cs.card_draw_counter; i++) { + for (int i = 0; i < cs.card_draw_counter - old_hand_counter; i++) { Card card = current_hand[i]; System.out.print(card.card_value + " in " + card.color + " , "); } @@ -28,8 +30,11 @@ public class Hand { int sum = 0; - for (int i = 0; i < (cs.card_draw_counter); i++) { + for (int i = 0; i < (cs.card_draw_counter - old_hand_counter); i++) { Card card = current_hand[i]; + if (card.card_value.equals("Ass") && (sum + 11) > 21) { + card.ass_value = 1; + } sum += card.get_points(card); } @@ -41,6 +46,10 @@ public class Hand { } public void draw_card() { - current_hand[cs.card_draw_counter] = cs.draw_card(); + Card drawn_card = cs.draw_card(); + System.out.println("die karte ist " + drawn_card.card_value); + + current_hand[(cs.card_draw_counter - old_hand_counter) - 1] = drawn_card; + } } diff --git a/Test/src/HandTest.java b/Test/src/HandTest.java new file mode 100644 index 0000000..e4e52f5 --- /dev/null +++ b/Test/src/HandTest.java @@ -0,0 +1,5 @@ +import static org.junit.jupiter.api.Assertions.*; + +class HandTest { + +} \ No newline at end of file diff --git a/Test/src/TUI.java b/Test/src/TUI.java index bdd0e23..96c1295 100644 --- a/Test/src/TUI.java +++ b/Test/src/TUI.java @@ -11,7 +11,7 @@ public class TUI { } - //TODO Ass und Exception + JUnit + new_hand + //TODO Ass und JUnit public void game_loop() { System.out.println(bs); @@ -24,11 +24,14 @@ public class TUI { if (answer.equals("2")) { break; - } else if (!(answer.equals("3"))) { + } else if ((answer.equals("1"))) { bs.hand.draw_card(); + + } else { + + bs.get_new_hand(); } - bs.get_new_hand(); if (bs.hand.get_points() == 21) { System.out.println("Gut gemacht Du hast 21 Punkte mit");