jpsp91 vor 6 Jahren
Ursprung
Commit
affb20ae99

+ 13
- 132
src/main/java/io/zipcoder/casino/Leviathan/Games/BlackJack.java Datei anzeigen

@@ -16,8 +16,7 @@ public class BlackJack extends CardGame implements Gambling {
16 16
     boolean playAgain = true;
17 17
 
18 18
     public BlackJack(Player aPlayer) {
19
-        this.aPlayer = aPlayer;
20
-    }
19
+        this.aPlayer = aPlayer;}
21 20
 
22 21
     int aPlayerScore = Game.playerScore;
23 22
     int aHouseScore = Game.houseScore;
@@ -49,25 +48,18 @@ public class BlackJack extends CardGame implements Gambling {
49 48
 
50 49
             if (value <= 10) {
51 50
                 sum += value;
52
-            }
53
-            if (rank.equals(Rank.JACK) || rank.equals(Rank.QUEEN) || rank.equals(Rank.KING)) {
51
+            } if (rank.equals(Rank.JACK) || rank.equals(Rank.QUEEN) || rank.equals(Rank.KING)) {
54 52
                 sum += 10;
55
-            }
56
-            if (rank.equals(Rank.ACE)) {
53
+            } if (rank.equals(Rank.ACE)) {
57 54
                 sum += 0;
58
-            }
59
-            if (rank.equals(Rank.ACE)) {
60
-                countAces += 1;
61
-            }
62
-        }
63
-        if (countAces == 0) {
55
+            } if (rank.equals(Rank.ACE)) {
56
+                countAces += 1;}
57
+            } if (countAces == 0) {
64 58
             return sum;
65
-        }
66
-        if ((sum + 11 + (countAces - 1)) <= 21) {
59
+            } if ((sum + 11 + (countAces - 1)) <= 21) {
67 60
             return sum + 11 + (countAces - 1);
68
-        } else {
69
-            return sum + countAces;
70
-        }
61
+            } else {
62
+            return sum + countAces; }
71 63
     }
72 64
 
73 65
     //lets the player know of the starting hand
@@ -75,8 +67,7 @@ public class BlackJack extends CardGame implements Gambling {
75 67
         StringBuilder builder = new StringBuilder();
76 68
         for (Card c : hand) {
77 69
             String cardString = (c.getRank() + " of " + c.getSuit());
78
-            builder.append(cardString).append("\n");
79
-        }
70
+            builder.append(cardString).append("\n"); }
80 71
         return builder.toString();
81 72
     }
82 73
 
@@ -84,27 +75,23 @@ public class BlackJack extends CardGame implements Gambling {
84 75
     public String houseHandToString(List<Card> hand, int cardsToShow) {
85 76
         StringBuilder builder = new StringBuilder();
86 77
         for (int i = 0; i < cardsToShow; i++) {
87
-            builder.append(hand.get(i).getRank() + " of " + hand.get(i).getSuit() + "\n");
88
-        }
78
+            builder.append(hand.get(i).getRank() + " of " + hand.get(i).getSuit() + "\n"); }
89 79
         return builder.toString();
90 80
     }
91 81
 
92 82
 
93 83
     //draws a singe card
94 84
     public Card drawSingleCard() {
95
-
96 85
         return deck.draw();
97 86
     }
98 87
 
99 88
     //Gets the int value of a single drawn card
100 89
     public int getSingleCardValue(List<Card> hand) {
101 90
         int cardValue = 0;
102
-
103 91
         for (Card c : hand) {
104 92
             Rank rank = c.getRank();
105 93
             int value = rank.getValue();
106
-            cardValue += value;
107
-        }
94
+            cardValue += value; }
108 95
         return cardValue;
109 96
     }
110 97
 
@@ -152,7 +139,6 @@ public class BlackJack extends CardGame implements Gambling {
152 139
             aHouseScore = houseHandTotal;
153 140
 
154 141
             //show the player one of house's card
155
-            //I need to figure out how I could only show one card
156 142
             String houseHandString = houseHandToString(houseHand, 1);
157 143
             aConsole.println("-The house has drawn: \n" + houseHandString +
158 144
                     "And has one card faced down\n");
@@ -171,45 +157,9 @@ public class BlackJack extends CardGame implements Gambling {
171 157
                 if (playerDecision.equalsIgnoreCase("Stand")) {
172 158
                     //House start drawing cards
173 159
                     houseDraws(houseHand);
174
-                    break;
175
-                }
160
+                    break; }
176 161
             }
177 162
 
178
-
179
-////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
180
-//
181
-//            //working on extracting methods from the big method
182
-//
183
-//            public void decision() {
184
-//                //House winning situations
185
-//                //Bust
186
-//                if (aPlayerScore > 21) {
187
-//                    playerBust();
188
-//                }
189
-//
190
-//                //House has higher score
191
-//                else if ((aHouseScore >= aPlayerScore && aHouseScore < 21) || aHouseScore == 21) {
192
-//                    houseHigherScore();
193
-//                }
194
-//
195
-//
196
-//                //Player winning situation
197
-//                //houseBust
198
-//                else if (aHouseScore < 21) {
199
-//                    houseBust();
200
-//                }
201
-//
202
-//                //Other winning situations
203
-//                else {
204
-//                    everyPossibleWinningSituation();
205
-//                }
206
-//
207
-//            }
208
-////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
209
-
210
-
211
-
212
-            //House winning situations
213 163
             //Bust
214 164
             if (aPlayerScore > 21) {
215 165
                 aConsole.println("\nBust!\n");
@@ -226,9 +176,6 @@ public class BlackJack extends CardGame implements Gambling {
226 176
                 betChages(bet);
227 177
                 aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips() + "\n");
228 178
             }
229
-
230
-
231
-
232 179
             //Player winning situation
233 180
             else if (aHouseScore < 21) {
234 181
                 aConsole.println("\nYou win!\n");
@@ -243,9 +190,6 @@ public class BlackJack extends CardGame implements Gambling {
243 190
                 betChages(bet);
244 191
                 aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips() + "\n");
245 192
             }
246
-
247
-
248
-
249 193
             //End of the game
250 194
             if ((aPlayer.getTotalChips() == 0) || aConsole.yesOrNo("Would you like to play again?").equalsIgnoreCase("no")) {
251 195
                 playAgain = false;
@@ -313,69 +257,6 @@ public class BlackJack extends CardGame implements Gambling {
313 257
             aPlayer.setTotalChips(totalChips - wageAmount);
314 258
         }
315 259
     }
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
326
-//
327
-//    //working on extracting methods from the big method
328
-//
329
-//
330
-//    public void playerBust() {
331
-//        //if (aPlayerScore > 21) {
332
-//            aConsole.println("\nBust!\n");
333
-//           win = false;
334
-//           betChages(bet);
335
-//           aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips());
336
-//        //}
337
-//    }
338
-//
339
-//    public void  houseHigherScore() {
340
-//        //if ((aHouseScore >= aPlayerScore && aHouseScore < 21) || aHouseScore == 21) {
341
-//            aConsole.println("\nYou lose\n" + "Your score: " + aPlayerScore +
342
-//                    "\nHouse score: " + aHouseScore + "\n");
343
-//            aConsole.println("-Dealer's hand: \n" + handToString(houseHand));
344
-//            win = false;
345
-//            betChages(bet);
346
-//            aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips() + "\n");
347
-//        //}
348
-//    }
349
-//
350
-//
351
-//
352
-//    public void houseBust() {
353
-//        //if (aHouseScore < 21) {
354
-//            aConsole.println("\nYou win!\n");
355
-//            win = true;
356
-//            betChages(bet);
357
-//            aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips() + "\n");
358
-//        //}
359
-//    }
360
-//
361
-//
362
-//
363
-//
364
-//public void everyPossibleWinningSituation() {
365
-//    //else{
366
-//        //aConsole.println("You win!");
367
-//        aConsole.println("\nYou win!\n" + "Your score: " + aPlayerScore +
368
-//                "\nHouse score: " + aHouseScore + "\n");
369
-//        win = true;
370
-//        betChages(bet);
371
-//        aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips() + "\n");
372
-//    //}
373
-//}
374
-//
375
-////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
376
-
377
-
378
-
379 260
 }
380 261
 
381 262
 

+ 0
- 23
src/test/java/io/zipcoder/casino/BlackJackTest.java Datei anzeigen

@@ -23,28 +23,6 @@ public class BlackJackTest {
23 23
         this.testBlackJack = new BlackJack(p);
24 24
     }
25 25
 
26
-//    @Test
27
-//    public void testStartPlayerScore() {
28
-//        //Given
29
-//
30
-//        //When
31
-//        int expected = 8;
32
-//        int actual = 8;
33
-//        //Result
34
-//        assertEquals(actual, expected);
35
-//    }
36
-//
37
-//    @Test
38
-//    public void testStartHouseScore() {
39
-//        //Given
40
-//
41
-//        //When
42
-//        int expected = 21;
43
-//        int actual = 21;
44
-//        //Result
45
-//        assertEquals(actual, expected);
46
-//    }
47
-
48 26
     @Test
49 27
     public void testDrawNewHandHasTwoCards() {
50 28
         int expected = 2;
@@ -102,7 +80,6 @@ public class BlackJackTest {
102 80
         assertEquals(expected, actual);
103 81
     }
104 82
 
105
-
106 83
 @Test
107 84
     public void testPlayerHit() {
108 85
         Card c = new Card(Rank.TWO, Suit.SPADES);