Added blackbox
Changed that the main methode only uses methods from the BlackJackSpiel.master
parent
8cbe1471a0
commit
84862cf3ba
|
@ -1,18 +1,36 @@
|
|||
public class BlackJackSpiel {
|
||||
Kartenstapel ks;
|
||||
Hand hand;
|
||||
private Hand hand;
|
||||
public BlackJackSpiel(){
|
||||
this.ks = new Kartenstapel();
|
||||
this.hand = new Hand(this.ks);
|
||||
getNeueHand();
|
||||
}
|
||||
|
||||
Hand getNeueHand(){
|
||||
public boolean isHandBlackJack(){
|
||||
return hand.isBlackJack();
|
||||
}
|
||||
|
||||
public boolean isHandOvershot(){
|
||||
return hand.isOvershot();
|
||||
}
|
||||
|
||||
|
||||
void getNeueHand(){
|
||||
this.hand.drawCard(2);
|
||||
return this.hand;
|
||||
// return this.hand;
|
||||
}
|
||||
|
||||
Hand turn(){
|
||||
void turn(){
|
||||
this.hand.drawCard(1);
|
||||
return this.hand;
|
||||
// return this.hand;
|
||||
}
|
||||
|
||||
String handContent(){
|
||||
return hand.toString();
|
||||
}
|
||||
|
||||
int handValue(){
|
||||
return hand.getPunkte();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,20 +10,22 @@ public class Main {
|
|||
|
||||
private static void gameLoop(){
|
||||
BlackJackSpiel game = new BlackJackSpiel();
|
||||
Hand hand = game.getNeueHand();
|
||||
// Hand hand = game.getNeueHand();
|
||||
|
||||
while (true){
|
||||
System.out.printf("%s Ihr Wert beträgt %d \n", hand, hand.getPunkte());
|
||||
System.out.printf("%s Ihr Wert beträgt %d \n", game.handContent(), game.handValue());
|
||||
|
||||
String nextRoundPrompt = "";
|
||||
|
||||
|
||||
if (hand.isBlackJack()){
|
||||
// if (hand.isBlackJack()){
|
||||
if (game.isHandBlackJack()){
|
||||
nextRoundPrompt = "Glückwunsch, sie haben einen BlackJack und damit gewonnen!";
|
||||
}
|
||||
|
||||
if (hand.isOvershot()){
|
||||
nextRoundPrompt = String.format("Leider verloren, der Wert der Hand ist mit %d höher als 21.", hand.getPunkte());
|
||||
// if (hand.isOvershot()){
|
||||
if (game.isHandOvershot()){
|
||||
nextRoundPrompt = String.format("Leider verloren, der Wert der Hand ist mit %d höher als 21.", game.handValue());
|
||||
}
|
||||
|
||||
if (nextRoundPrompt.isEmpty()) {
|
||||
|
@ -32,9 +34,13 @@ public class Main {
|
|||
boolean newCardDecision = yesNoDecider(newCardPrompt);
|
||||
|
||||
if (newCardDecision) {
|
||||
hand = game.turn();
|
||||
// hand = game.turn();
|
||||
game.turn();
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
System.out.printf("Der finale Wert der Hand beträgt %d. \n", game.handValue());
|
||||
}
|
||||
}
|
||||
|
||||
//? Next round decider
|
||||
|
@ -47,7 +53,6 @@ public class Main {
|
|||
break;
|
||||
}
|
||||
game = new BlackJackSpiel();
|
||||
hand = game.getNeueHand();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue