From e92aa100943a0d29c035d012646bdfeb9b230607 Mon Sep 17 00:00:00 2001 From: lucvo <3012946@stud.hs-mannheim.de> Date: Mon, 25 Mar 2024 20:53:47 +0100 Subject: [PATCH] bug hunt anfang --- Test/src/BlackJack.java | 1 + Test/src/CardStack.java | 4 ++++ Test/src/Hand.java | 8 +++++++- Test/src/TUI.java | 12 +++++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Test/src/BlackJack.java b/Test/src/BlackJack.java index 9db04c1..f6702dd 100644 --- a/Test/src/BlackJack.java +++ b/Test/src/BlackJack.java @@ -16,4 +16,5 @@ public class BlackJack { public String toString() { return hand.toString(); } + } diff --git a/Test/src/CardStack.java b/Test/src/CardStack.java index 71206ef..7521fca 100644 --- a/Test/src/CardStack.java +++ b/Test/src/CardStack.java @@ -39,6 +39,10 @@ public class CardStack { public Card draw_card() { + if (card_draw_counter > 52) { + throw new RuntimeException("Keine Karten mehr"); + } + Card result = shuffled_cards[card_draw_counter]; card_draw_counter++; return result; diff --git a/Test/src/Hand.java b/Test/src/Hand.java index 05d1a6e..e5b5fa7 100644 --- a/Test/src/Hand.java +++ b/Test/src/Hand.java @@ -5,6 +5,7 @@ public class Hand { CardStack cs; public Hand(CardStack cs) { + cs.card_draw_counter = 0; this.cs = cs; current_hand[0] = cs.draw_card(); current_hand[1] = cs.draw_card(); @@ -26,7 +27,8 @@ public class Hand { public int get_points() { int sum = 0; - for (int i = 0; i < cs.card_draw_counter; i++) { + + for (int i = 0; i < (cs.card_draw_counter); i++) { Card card = current_hand[i]; sum += card.get_points(card); } @@ -37,4 +39,8 @@ public class Hand { public boolean is_black_jack() { return get_points() == 21; } + + public void draw_card() { + current_hand[cs.card_draw_counter] = cs.draw_card(); + } } diff --git a/Test/src/TUI.java b/Test/src/TUI.java index a009594..bdd0e23 100644 --- a/Test/src/TUI.java +++ b/Test/src/TUI.java @@ -18,21 +18,27 @@ public class TUI { while (true) { System.out.println("Weitere Karte Ziehen (1)"); System.out.println("Karten so belassen (2)"); + System.out.println("Neue Hand nehmen (3)"); String answer = sc.nextLine(); if (answer.equals("2")) { break; + + } else if (!(answer.equals("3"))) { + bs.hand.draw_card(); } - bs.cs.draw_card(); + bs.get_new_hand(); if (bs.hand.get_points() == 21) { - System.out.println("Gut gemacht"); + System.out.println("Gut gemacht Du hast 21 Punkte mit"); + System.out.println(bs); break; } + System.out.println(bs); + } - System.out.println(bs); } }