wiso vergisst man so viel

main
Luc Vonnemann 2024-03-25 19:37:45 +01:00
parent 8bcae97759
commit 804494b849
7 changed files with 154 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxProjectSettings">
<option name="commitMessageIssueKeyValidationOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
<option name="commitMessageValidationEnabledOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
</component>
</project>

View File

@ -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;
}
}

32
Test/src/Card.java 100644
View File

@ -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;
};
}
}

View File

@ -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;
}
}

31
Test/src/Hand.java 100644
View File

@ -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;
}
}

View File

@ -1,6 +1,7 @@
public class Main {
public static void main(String[] args) {
TUI control = new TUI();
}
}

16
Test/src/TUI.java 100644
View File

@ -0,0 +1,16 @@
public class TUI {
public BlackJack bs;
public TUI() {
bs = new BlackJack();
game_loop();
}
public void game_loop() {
while (true) {
}
}
}