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 {
|
public class BlackJackSpiel {
|
||||||
Kartenstapel ks;
|
Kartenstapel ks;
|
||||||
Hand hand;
|
private Hand hand;
|
||||||
public BlackJackSpiel(){
|
public BlackJackSpiel(){
|
||||||
this.ks = new Kartenstapel();
|
this.ks = new Kartenstapel();
|
||||||
this.hand = new Hand(this.ks);
|
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);
|
this.hand.drawCard(2);
|
||||||
return this.hand;
|
// return this.hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hand turn(){
|
void turn(){
|
||||||
this.hand.drawCard(1);
|
this.hand.drawCard(1);
|
||||||
return this.hand;
|
// return this.hand;
|
||||||
|
}
|
||||||
|
|
||||||
|
String handContent(){
|
||||||
|
return hand.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
int handValue(){
|
||||||
|
return hand.getPunkte();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ public class Karte {
|
||||||
this.farbe = farbe;
|
this.farbe = farbe;
|
||||||
this.wert = wert;
|
this.wert = wert;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWert() {
|
public int getWert() {
|
||||||
if ((this.wert.equals("Bube")) || (this.wert.equals("Dame")) || (this.wert.equals("König"))){
|
if ((this.wert.equals("Bube")) || (this.wert.equals("Dame")) || (this.wert.equals("König"))){
|
||||||
return 10;
|
return 10;
|
||||||
|
|
|
@ -10,20 +10,22 @@ public class Main {
|
||||||
|
|
||||||
private static void gameLoop(){
|
private static void gameLoop(){
|
||||||
BlackJackSpiel game = new BlackJackSpiel();
|
BlackJackSpiel game = new BlackJackSpiel();
|
||||||
Hand hand = game.getNeueHand();
|
// Hand hand = game.getNeueHand();
|
||||||
|
|
||||||
while (true){
|
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 = "";
|
String nextRoundPrompt = "";
|
||||||
|
|
||||||
|
|
||||||
if (hand.isBlackJack()){
|
// if (hand.isBlackJack()){
|
||||||
|
if (game.isHandBlackJack()){
|
||||||
nextRoundPrompt = "Glückwunsch, sie haben einen BlackJack und damit gewonnen!";
|
nextRoundPrompt = "Glückwunsch, sie haben einen BlackJack und damit gewonnen!";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hand.isOvershot()){
|
// if (hand.isOvershot()){
|
||||||
nextRoundPrompt = String.format("Leider verloren, der Wert der Hand ist mit %d höher als 21.", hand.getPunkte());
|
if (game.isHandOvershot()){
|
||||||
|
nextRoundPrompt = String.format("Leider verloren, der Wert der Hand ist mit %d höher als 21.", game.handValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextRoundPrompt.isEmpty()) {
|
if (nextRoundPrompt.isEmpty()) {
|
||||||
|
@ -32,9 +34,13 @@ public class Main {
|
||||||
boolean newCardDecision = yesNoDecider(newCardPrompt);
|
boolean newCardDecision = yesNoDecider(newCardPrompt);
|
||||||
|
|
||||||
if (newCardDecision) {
|
if (newCardDecision) {
|
||||||
hand = game.turn();
|
// hand = game.turn();
|
||||||
|
game.turn();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
System.out.printf("Der finale Wert der Hand beträgt %d. \n", game.handValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//? Next round decider
|
//? Next round decider
|
||||||
|
@ -47,7 +53,6 @@ public class Main {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
game = new BlackJackSpiel();
|
game = new BlackJackSpiel();
|
||||||
hand = game.getNeueHand();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue