test anfang
parent
e92aa10094
commit
4f23988517
|
@ -2,6 +2,8 @@ public class Card {
|
||||||
public String card_value = "0";
|
public String card_value = "0";
|
||||||
public String color = "Blue";
|
public String color = "Blue";
|
||||||
|
|
||||||
|
public int ass_value = 11;
|
||||||
|
|
||||||
|
|
||||||
public Card(String color, String card_value) {
|
public Card(String color, String card_value) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
@ -15,7 +17,7 @@ public class Card {
|
||||||
public int get_points(Card card) {
|
public int get_points(Card card) {
|
||||||
|
|
||||||
return switch (card.card_value) {
|
return switch (card.card_value) {
|
||||||
case "Ass" -> 1;
|
case "Ass" -> ass_value;
|
||||||
case "King", "Dame", "Bube", "10" -> 10;
|
case "King", "Dame", "Bube", "10" -> 10;
|
||||||
case "9" -> 9;
|
case "9" -> 9;
|
||||||
case "8" -> 8;
|
case "8" -> 8;
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class CardStack {
|
||||||
|
|
||||||
public Card draw_card() {
|
public Card draw_card() {
|
||||||
|
|
||||||
if (card_draw_counter > 52) {
|
if (card_draw_counter > 51) {
|
||||||
throw new RuntimeException("Keine Karten mehr");
|
throw new RuntimeException("Keine Karten mehr");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,11 @@ public class Hand {
|
||||||
private Card[] current_hand = new Card[11];
|
private Card[] current_hand = new Card[11];
|
||||||
private int current_points;
|
private int current_points;
|
||||||
CardStack cs;
|
CardStack cs;
|
||||||
|
public int old_hand_counter;
|
||||||
|
|
||||||
public Hand(CardStack cs) {
|
public Hand(CardStack cs) {
|
||||||
cs.card_draw_counter = 0;
|
old_hand_counter = cs.card_draw_counter;
|
||||||
|
|
||||||
this.cs = cs;
|
this.cs = cs;
|
||||||
current_hand[0] = cs.draw_card();
|
current_hand[0] = cs.draw_card();
|
||||||
current_hand[1] = cs.draw_card();
|
current_hand[1] = cs.draw_card();
|
||||||
|
@ -15,7 +17,7 @@ public class Hand {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String return_message = "Die Karten sind: ";
|
String return_message = "Die Karten sind: ";
|
||||||
|
|
||||||
for (int i = 0; i < cs.card_draw_counter; i++) {
|
for (int i = 0; i < cs.card_draw_counter - old_hand_counter; i++) {
|
||||||
Card card = current_hand[i];
|
Card card = current_hand[i];
|
||||||
System.out.print(card.card_value + " in " + card.color + " , ");
|
System.out.print(card.card_value + " in " + card.color + " , ");
|
||||||
}
|
}
|
||||||
|
@ -28,8 +30,11 @@ public class Hand {
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < (cs.card_draw_counter); i++) {
|
for (int i = 0; i < (cs.card_draw_counter - old_hand_counter); i++) {
|
||||||
Card card = current_hand[i];
|
Card card = current_hand[i];
|
||||||
|
if (card.card_value.equals("Ass") && (sum + 11) > 21) {
|
||||||
|
card.ass_value = 1;
|
||||||
|
}
|
||||||
sum += card.get_points(card);
|
sum += card.get_points(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +46,10 @@ public class Hand {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw_card() {
|
public void draw_card() {
|
||||||
current_hand[cs.card_draw_counter] = cs.draw_card();
|
Card drawn_card = cs.draw_card();
|
||||||
|
System.out.println("die karte ist " + drawn_card.card_value);
|
||||||
|
|
||||||
|
current_hand[(cs.card_draw_counter - old_hand_counter) - 1] = drawn_card;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class HandTest {
|
||||||
|
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ public class TUI {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Ass und Exception + JUnit + new_hand
|
//TODO Ass und JUnit
|
||||||
|
|
||||||
public void game_loop() {
|
public void game_loop() {
|
||||||
System.out.println(bs);
|
System.out.println(bs);
|
||||||
|
@ -24,11 +24,14 @@ public class TUI {
|
||||||
if (answer.equals("2")) {
|
if (answer.equals("2")) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} else if (!(answer.equals("3"))) {
|
} else if ((answer.equals("1"))) {
|
||||||
bs.hand.draw_card();
|
bs.hand.draw_card();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
bs.get_new_hand();
|
||||||
}
|
}
|
||||||
|
|
||||||
bs.get_new_hand();
|
|
||||||
|
|
||||||
if (bs.hand.get_points() == 21) {
|
if (bs.hand.get_points() == 21) {
|
||||||
System.out.println("Gut gemacht Du hast 21 Punkte mit");
|
System.out.println("Gut gemacht Du hast 21 Punkte mit");
|
||||||
|
|
Loading…
Reference in New Issue