From 8c0e89011ce0156ba5e37d4c280c94703f8d6c67 Mon Sep 17 00:00:00 2001 From: lucvo <3012946@stud.hs-mannheim.de> Date: Mon, 25 Mar 2024 19:59:35 +0100 Subject: [PATCH] wiso vergisst man so viel --- Test/src/BlackJack.java | 13 ++++++++++--- Test/src/Hand.java | 9 ++++++++- Test/src/TUI.java | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Test/src/BlackJack.java b/Test/src/BlackJack.java index 7c82c14..9db04c1 100644 --- a/Test/src/BlackJack.java +++ b/Test/src/BlackJack.java @@ -1,12 +1,19 @@ public class BlackJack { - private Hand hand; + public Hand hand; + public CardStack cs; public BlackJack() { - hand = new Hand(new CardStack()); + cs = new CardStack(); + hand = new Hand(cs); } public Hand get_new_hand() { - hand = new Hand(new CardStack()); + hand = new Hand(cs); return hand; } + + @Override + public String toString() { + return hand.toString(); + } } diff --git a/Test/src/Hand.java b/Test/src/Hand.java index a87037a..95ca208 100644 --- a/Test/src/Hand.java +++ b/Test/src/Hand.java @@ -12,7 +12,14 @@ public class Hand { } public String toString() { - return "al;skdjf;alskdjfsa;lkjfd;lkaj hier die hand beschreiben also 5 karo, ... insgesamt 15"; + String return_message = "Die Karten sind: "; + + for (Card card : current_hand) { + System.out.print(card.card_value + " , " + card.color + " , "); + } + + System.out.println("Insgesamt sind dies " + Integer.toString(get_points()) + " Punkte"); + return return_message; } public int get_points() { diff --git a/Test/src/TUI.java b/Test/src/TUI.java index 3b93a15..6186528 100644 --- a/Test/src/TUI.java +++ b/Test/src/TUI.java @@ -1,16 +1,38 @@ +import java.util.Scanner; + public class TUI { public BlackJack bs; + Scanner sc = new Scanner(System.in); public TUI() { bs = new BlackJack(); game_loop(); + } + //TODO Ass und Exception + JUnit public void game_loop() { + System.out.println(bs); while (true) { + System.out.println("Weitere Karte Ziehen (1)"); + System.out.println("Karten so belassen (2)"); + + String answer = sc.nextLine(); + if (answer.equals("2")) { + break; + } + + bs.cs.draw_card(); + + if (bs.hand.get_points() == 21) { + System.out.println("Gut gemacht"); + break; + } } + + System.out.println(bs); } }