瀏覽代碼

breaking codes in progress

ThuyKhong 6 年之前
父節點
當前提交
46d45c284c

+ 57
- 50
src/main/java/io/zipcoder/casino/cardgames/BlackJack.java 查看文件

@@ -25,9 +25,7 @@ public class BlackJack extends CardGame implements Gamble {
25 25
     public BlackJack(){
26 26
         readyPlayers();
27 27
         dealCards(2);
28
-        for (BlackJackPlayer p : blackJackPlayers) {
29
-          run();
30
-        }
28
+        run();
31 29
     }
32 30
 
33 31
     public void readyPlayers() {
@@ -43,7 +41,6 @@ public class BlackJack extends CardGame implements Gamble {
43 41
     }
44 42
 
45 43
     public boolean play(BlackJackPlayer currentPlayer, long bet) {
46
-        placeBet();
47 44
         // this.bet = bet;
48 45
 
49 46
         Console.println("The dealer is dealing cards to the players.");
@@ -51,7 +48,8 @@ public class BlackJack extends CardGame implements Gamble {
51 48
         dealerHand.add(deck.removeFirst());
52 49
         dealerHand.add(deck.removeFirst());
53 50
 
54
-        Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
51
+        Console.println("Dealer is showing a " + dealerHand.get(0).getCard()); // dealer reveals upcard
52
+
55 53
 
56 54
         if (getSum(dealerHand) == 21){
57 55
             Console.println("Dealer has +," +  dealerHand.display());
@@ -59,65 +57,74 @@ public class BlackJack extends CardGame implements Gamble {
59 57
             Console.println("Dealer has blackjack. Dealer wins.");
60 58
         }
61 59
 
60
+        for (currentPlayer : blackJackPlayers) {
62 61
 
63
-        Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
62
+          Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
64 63
 
65
-        if (getSum(currentPlayer.getHand()) == 21){
66
-            Console.println("Dealer has " + dealerHand.display());
67
-            Console.println("You have " + currentPlayer.getHand().display());
68
-            Console.println("You have blackjack. You win.");
69
-        }
70
-        
71
-        while(true) {
64
+          placeBet();
72 65
 
73
-            Console.println("You have: " + currentPlayer.getHand().display() + "\nYour sum is " + getSum(currentPlayer.getHand()));
66
+          if (getSum(currentPlayer.getHand()) == 21){
67
+              Console.println("Dealer has " + dealerHand.display());
68
+              Console.println("You have " + currentPlayer.getHand().display());
69
+              Console.println("You have blackjack. You win.");
70
+          }
74 71
 
75
-            String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
72
+            while(true) {
76 73
 
77
-            while (getSum(currentPlayer.getHand()) < 21) {
78
-                if (hitOrStand.equalsIgnoreCase("H")) {
79
-                    dealCard(currentPlayer,1);
80
-                } else if (hitOrStand.equalsIgnoreCase("S")) {
81
-                    break;
82
-                } else {
83
-                    hitOrStand = Console.getStringInput("Invalid input. Please enter H for Hit or S for Stand");
84
-                }
85
-            }
74
+                Console.println("You have: " + currentPlayer.getHand().display() + "\nYour sum is " + getSum(currentPlayer.getHand()));
86 75
 
87
-            Console.println("You have: " + currentPlayer.getHand().display());
88
-            Console.println("The sum of your cards is " + getSum(currentPlayer.getHand()));
76
+                String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
89 77
 
90
-            if (getSum(currentPlayer.getHand()) > 21){
91
-                Console.println("You busted. House wins.");
92
-                return false;
93
-            }
78
+                while (getSum(currentPlayer.getHand()) < 21) {
79
+                    if (hitOrStand.equalsIgnoreCase("H")) {
80
+                        dealCard(currentPlayer,1);
81
+                    } else if (hitOrStand.equalsIgnoreCase("S")) {
82
+                        break;
83
+                    } else {
84
+                        hitOrStand = Console.getStringInput("Invalid input. Please enter H for Hit or S for Stand");
85
+                    }
86
+                }
94 87
 
95
-            Console.println("Dealer's card are: " + dealerHand.display());
96
-            Console.println("The sum of dealer's cards is " + getSum(dealerHand));
88
+                Console.println("You have: " + currentPlayer.getHand().display());
89
+                Console.println("The sum of your cards is " + getSum(currentPlayer.getHand()));
97 90
 
98
-            while (getSum(dealerHand) < 17) {
99
-                revealCard();
100
-                Console.println("Dealer's sum is " + getSum(dealerHand));
101
-            }
91
+                if (getSum(currentPlayer.getHand()) > 21){
92
+                    Console.println("You busted. House wins.");
93
+                    return false;
94
+                }
102 95
 
103
-            if (getSum(dealerHand) > 21) {
104
-                Console.println("Dealer busted. You win.");
105
-                return false;
106 96
             }
97
+        }
107 98
 
108
-            if (getSum(dealerHand) == getSum(currentPlayer.getHand())) {
109
-                Console.println("It's a tie. You lose.");
110
-                return false;
111
-            } else if (getSum(dealerHand) <=21 && getSum(dealerHand) > getSum(currentPlayer.getHand())) {
112
-                Console.println("Dealer wins.");
113
-                return false;
114
-            } else {
115
-                Console.println("You win!");
116
-                return false;
117
-            }
99
+        Console.println("Dealer's card are: " + dealerHand.display());
100
+        Console.println("The sum of dealer's cards is " + getSum(dealerHand));
118 101
 
102
+        while (getSum(dealerHand) < 17) {
103
+            revealCard();
104
+            Console.println("Dealer's sum is " + getSum(dealerHand));
119 105
         }
120 106
 
107
+        if (getSum(dealerHand) > 21) {
108
+            Console.println("Dealer busted. You win.");
109
+            return false;
110
+        }
111
+
112
+        if (getSum(dealerHand) == getSum(currentPlayer.getHand())) {
113
+            Console.println("Dealer wins on a tie.");
114
+            evaluateBet(currentPlayer.getP(), -bet);
115
+            return false;
116
+        } else if (getSum(dealerHand) <=21 && getSum(dealerHand) > getSum(currentPlayer.getHand())) {
117
+            Console.println("Dealer wins.");
118
+            evaluateBet(currentPlayer.getP(), -bet);
119
+            return false;
120
+        } else {
121
+            Console.println("You win!");
122
+            evaluateBet(currentPlayer.getP(), bet);
123
+            return false;
124
+        }
125
+
126
+    }
127
+
121 128
 }
122 129
 
123 130
     public void dealCards(int numberOfCards) {
@@ -143,7 +150,7 @@ public class BlackJack extends CardGame implements Gamble {
143 150
 
144 151
 
145 152
     public void evaluateBet(Player player, long payout) {
146
-
153
+        player.setChipBalance(player.getChipBalance()+payout);
147 154
     }
148 155
 
149 156
 

+ 2
- 0
src/main/java/io/zipcoder/casino/player/BlackJackPlayer.java 查看文件

@@ -41,4 +41,6 @@ public class BlackJackPlayer{
41 41
         this.hand = hand;
42 42
     }
43 43
 
44
+
45
+
44 46
 }