ソースを参照

modified a few things

ThuyKhong 6 年 前
コミット
750e2830a2

+ 32
- 13
src/main/java/io/zipcoder/casino/cardgames/BlackJack.java ファイルの表示

@@ -1,6 +1,9 @@
1 1
 package io.zipcoder.casino.cardgames;
2 2
 
3
+import io.zipcoder.casino.cardgames.cards.Card;
4
+import io.zipcoder.casino.cardgames.cards.CardHand;
3 5
 import io.zipcoder.casino.cardgames.cards.Deck;
6
+import io.zipcoder.casino.utilities.Console;
4 7
 import io.zipcoder.casino.utilities.Gamble;
5 8
 import io.zipcoder.casino.player.BlackJackPlayer;
6 9
 import io.zipcoder.casino.player.Player;
@@ -15,8 +18,8 @@ public class BlackJack extends CardGame implements Gamble {
15 18
 
16 19
     private Deck deck = new Deck();
17 20
     private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
18
-    ArrayList<Card> playerHand = new ArrayList<>();
19
-    ArrayList<Card> dealerHand = new ArrayList<>();
21
+    CardHand playerHand = new CardHand();
22
+    CardHand dealerHand = new CardHand();
20 23
     long bet;
21 24
 
22 25
 
@@ -46,14 +49,14 @@ public class BlackJack extends CardGame implements Gamble {
46 49
         dealCards(currentPlayer, 2);
47 50
 
48 51
         if (getSum(dealerHand) == 21){
49
-            Console.println("Dealer has " + dealerHand.(0)) + " and " + dealerHand.get(1);
50
-            Console.println(("You have " + playerHand.get(0)) + " and " + playerHand.get(1));
52
+            Console.println("Dealer has " + dealerHand.getCard(0)) + " and " + dealerHand.getCard(1);
53
+            Console.println(("You have " + playerHand.getCard(0)) + " and " + playerHand.getCard(1));
51 54
             Console.println("Dealer wins.");
52 55
         }
53 56
 
54 57
         if (getSum(playerHand) == 21){
55
-            Console.println("Dealer has " + dealerHand.get(0)) + " and " + dealerHand.get(1));
56
-            Console.println(("You have " + playerHand.get(0)) + " and " + playerHand.get(1));
58
+            Console.println("Dealer has " + dealerHand.getCard(0)) + " and " + dealerHand.getCard(1));
59
+            Console.println(("You have " + playerHand.getCard(0)) + " and " + playerHand.getCard(1));
57 60
             Console.println("You wins.");
58 61
         }
59 62
 
@@ -61,9 +64,9 @@ public class BlackJack extends CardGame implements Gamble {
61 64
 
62 65
             Console.println("You have: ");
63 66
             for (int i = 0; i < playerHand.size(); i++) {
64
-                Console.println(" " + playerHand.getCardValue(i) + playerHand.getSuit(i));
67
+                Console.println(" " + playerHand.getCard(i);
65 68
             }
66
-            Console.println("Dealer is showing a " + dealerHand.getCardValue(0) + " of " + dealerHand.getSuit(0));
69
+            Console.println("Dealer is showing a " + dealerHand.getCard(0));
67 70
             String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
68 71
 
69 72
             while (getSum(playerHand) < 21){
@@ -72,20 +75,20 @@ public class BlackJack extends CardGame implements Gamble {
72 75
             } else if (hitOrStand.equals("S")){
73 76
                 break;
74 77
             }else {
75
-                Console.println("Invalid input. Please enter H for Hit or S for Stand");
78
+                String hitOrStand = Console.getStringInput("Invalid input. Please enter H for Hit or S for Stand");
76 79
             }
77 80
             Console.println("You have: ");
78 81
                 for (int i = 0; i < playerHand.size(); i++) {
79
-                    Console.println(" " + playerHand.getVardValue(i) + playerHand.getSuit(i));
82
+                    Console.println(" " + playerHand.getCard(i));
80 83
                 }
81
-                Console.println("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
84
+                String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
82 85
                 }
83 86
                 return false;
84 87
             }
85 88
 
86 89
             Console.println("Dealer's card are: ");
87 90
             for (int i = 0; i < dealerHand.size(); i++) {
88
-            Console.println(" " + dealerHand.getVardValue(i) + dealerHand.getSuit(i));
91
+            Console.println(" " + dealerHand.getCard(i));
89 92
             }
90 93
             while (getSum(dealerHand) < 17) {
91 94
                 Card newCard = drawCard();
@@ -94,6 +97,20 @@ public class BlackJack extends CardGame implements Gamble {
94 97
                     Console.println("Dealer busted. " + currentPlayer + " wins.");
95 98
                 }
96 99
             }
100
+
101
+            if (getSum(dealerHand) == getSum(playerHand)) {
102
+              Console.println("It's a tie. You lose.");
103
+              return false;
104
+            } else if (getSum(dealerHand) > getSum(playerHand)) {
105
+              Console.println("Dealer wins.");
106
+              return false;
107
+            }else {
108
+              Console.println("You win!");
109
+              return false;
110
+            }
111
+
112
+
113
+
97 114
 }
98 115
 
99 116
     public void dealCards(BlackJackPlayer player, int numberOfCards) {
@@ -109,6 +126,7 @@ public class BlackJack extends CardGame implements Gamble {
109 126
         bet = Console.getLongInput("Please enter your bet.");
110 127
     }
111 128
 
129
+
112 130
     public void evaluateBet(Player player, long payout) {
113 131
 
114 132
     }
@@ -140,7 +158,7 @@ public class BlackJack extends CardGame implements Gamble {
140 158
     }
141 159
 
142 160
 
143
-    public int  getSum(ArrayList<Card> cardHands) {
161
+    public int  getSum(CardHand cardHands) {
144 162
         int cardSum = 0;
145 163
         boolean ace = false;
146 164
 
@@ -166,4 +184,5 @@ public class BlackJack extends CardGame implements Gamble {
166 184
 
167 185
     }
168 186
 
187
+
169 188
 }

+ 0
- 1
src/main/java/io/zipcoder/casino/cardgames/cards/Card.java ファイルの表示

@@ -26,5 +26,4 @@ public final class Card {
26 26
         this.cardValue = cardValue;
27 27
     }
28 28
 
29
-
30 29
 }

+ 6
- 0
src/main/java/io/zipcoder/casino/cardgames/cards/CardHand.java ファイルの表示

@@ -12,4 +12,10 @@ public class CardHand {
12 12
     public CardHand() {
13 13
     }
14 14
 
15
+    public Card getCard(int position){
16
+
17
+        return cardHand.get(position);
18
+
19
+    }
20
+
15 21
 }

+ 0
- 3
src/main/java/io/zipcoder/casino/cardgames/cards/Deck.java ファイルの表示

@@ -39,8 +39,5 @@ import java.util.ArrayList;
39 39
 
40 40
     }
41 41
 
42
-    public String getCard(Card card){
43
-        return card.getCardValue() + "of" + card.getSuit();
44
-        }
45 42
 
46 43
 }