bug hunt anfang
parent
ebea258044
commit
e92aa10094
|
@ -16,4 +16,5 @@ public class BlackJack {
|
|||
public String toString() {
|
||||
return hand.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue