From 804494b849f95ef112039921aa167961864adf28 Mon Sep 17 00:00:00 2001 From: lucvo <3012946@stud.hs-mannheim.de> Date: Mon, 25 Mar 2024 19:37:45 +0100 Subject: [PATCH] wiso vergisst man so viel --- .idea/git_toolbox_prj.xml | 15 +++++++++++++ Test/src/BlackJack.java | 12 ++++++++++ Test/src/Card.java | 32 ++++++++++++++++++++++++++ Test/src/CardStack.java | 47 +++++++++++++++++++++++++++++++++++++++ Test/src/Hand.java | 31 ++++++++++++++++++++++++++ Test/src/Main.java | 1 + Test/src/TUI.java | 16 +++++++++++++ 7 files changed, 154 insertions(+) create mode 100644 .idea/git_toolbox_prj.xml create mode 100644 Test/src/BlackJack.java create mode 100644 Test/src/Card.java create mode 100644 Test/src/CardStack.java create mode 100644 Test/src/Hand.java create mode 100644 Test/src/TUI.java diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml new file mode 100644 index 0000000..02b915b --- /dev/null +++ b/.idea/git_toolbox_prj.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/Test/src/BlackJack.java b/Test/src/BlackJack.java new file mode 100644 index 0000000..7c82c14 --- /dev/null +++ b/Test/src/BlackJack.java @@ -0,0 +1,12 @@ +public class BlackJack { + private Hand hand; + + public BlackJack() { + hand = new Hand(new CardStack()); + } + + public Hand get_new_hand() { + hand = new Hand(new CardStack()); + return hand; + } +} diff --git a/Test/src/Card.java b/Test/src/Card.java new file mode 100644 index 0000000..382de91 --- /dev/null +++ b/Test/src/Card.java @@ -0,0 +1,32 @@ +public class Card { + public String card_value = "0"; + public String color = "Blue"; + + + public Card(String color, String card_value) { + this.color = color; + this.card_value = card_value; + } + + public String toString() { + return "Die Karte ist " + card_value + " in " + color; + } + + public int get_points(Card card) { + + return switch (card.card_value) { + case "Ass" -> 1; + case "King", "Dame", "Bube", "10" -> 10; + case "9" -> 9; + case "8" -> 8; + case "7" -> 7; + case "6" -> 6; + case "5" -> 5; + case "4" -> 4; + case "3" -> 3; + case "2" -> 2; + + default -> 0; + }; + } +} diff --git a/Test/src/CardStack.java b/Test/src/CardStack.java new file mode 100644 index 0000000..44acc65 --- /dev/null +++ b/Test/src/CardStack.java @@ -0,0 +1,47 @@ +import java.util.Arrays; + +public class CardStack { + + public Card[] shuffled_cards = new Card[52]; + + private int[] random_place = new int[52]; + private final String[] card_values = {"Ass", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Bube", "Dame", "King"}; + private final String[] card_colors = {"Piek", "Kreuz", "Karo", "Herz"}; + private int card_draw_counter = 0; + + public CardStack() { + int next_place; + + for (int i = 1; i <= 13; i++) { + for (int j = 1; j <= 4; j++) { + next_place = get_place(); + shuffled_cards[next_place] = get_card(card_values[i], card_colors[j]); + } + } + } + + public Card get_card(String card_color, String card_value) { + return new Card(card_value, card_color); + } + + + private int get_place() { + int chosen_place = (int) (Math.random() * 52); + + while (random_place[chosen_place] == 99) { + chosen_place = (int) (Math.random() * 52); + } + + random_place[chosen_place] = 99; + + return chosen_place; + } + + public Card draw_card() { + + Card result = shuffled_cards[card_draw_counter]; + card_draw_counter++; + return result; + + } +} diff --git a/Test/src/Hand.java b/Test/src/Hand.java new file mode 100644 index 0000000..a87037a --- /dev/null +++ b/Test/src/Hand.java @@ -0,0 +1,31 @@ +public class Hand { + + private Card[] current_hand = new Card[11]; + private int current_points; + CardStack cs; + + public Hand(CardStack cs) { + this.cs = cs; + current_hand[0] = cs.draw_card(); + current_hand[1] = cs.draw_card(); + + } + + public String toString() { + return "al;skdjf;alskdjfsa;lkjfd;lkaj hier die hand beschreiben also 5 karo, ... insgesamt 15"; + } + + public int get_points() { + int sum = 0; + + for (Card card : current_hand) { + sum += card.get_points(card); + } + + return sum; + } + + public boolean is_black_jack() { + return get_points() == 21; + } +} diff --git a/Test/src/Main.java b/Test/src/Main.java index 2c75dd0..b62c519 100644 --- a/Test/src/Main.java +++ b/Test/src/Main.java @@ -1,6 +1,7 @@ public class Main { public static void main(String[] args) { + TUI control = new TUI(); } } diff --git a/Test/src/TUI.java b/Test/src/TUI.java new file mode 100644 index 0000000..3b93a15 --- /dev/null +++ b/Test/src/TUI.java @@ -0,0 +1,16 @@ +public class TUI { + public BlackJack bs; + + public TUI() { + bs = new BlackJack(); + + game_loop(); + } + + + public void game_loop() { + while (true) { + + } + } +}