Bläddra i källkod

refactored BlackJack

ThuyKhong 6 år sedan
förälder
incheckning
a609a568ce
1 ändrade filer med 10 tillägg och 1 borttagningar
  1. 10
    1
      src/main/java/io/zipcoder/casino/cardgames/BlackJack.java

+ 10
- 1
src/main/java/io/zipcoder/casino/cardgames/BlackJack.java Visa fil

@@ -54,9 +54,10 @@ public class BlackJack extends CardGame implements Gamble {
54 54
 
55 55
             playersTurn();
56 56
 
57
-            if (dealersTurn()) continueGame = false;
57
+            continueGame = dealersTurn(); // IMPLEMENT: if dealer loses, all players should receive payout
58 58
 
59 59
             evalWinner();
60
+
60 61
         }
61 62
 
62 63
         if (dealerWins == true) {
@@ -80,6 +81,13 @@ public class BlackJack extends CardGame implements Gamble {
80 81
         }
81 82
     }
82 83
 
84
+    public void payoutAll() {
85
+        for (BlackJackPlayer p: this.blackJackPlayers){ // collects bet from all players
86
+            long winnings = p.getBet()*2;
87
+            evaluateBet(p, winnings);
88
+        }
89
+    }
90
+
83 91
     public void dealerCollect(BlackJackPlayer p) {
84 92
         evaluateBet(p, -p.getBet());
85 93
     }
@@ -126,6 +134,7 @@ public class BlackJack extends CardGame implements Gamble {
126 134
 
127 135
         if (getSum(dealerHand) > 21) {
128 136
             Console.println("Dealer busted. You win.");
137
+            payoutAll();
129 138
             return true;
130 139
         }
131 140