Browse Source

modified a few things

ThuyKhong 6 years ago
parent
commit
750e2830a2

+ 32
- 13
src/main/java/io/zipcoder/casino/cardgames/BlackJack.java View File

1
 package io.zipcoder.casino.cardgames;
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
 import io.zipcoder.casino.cardgames.cards.Deck;
5
 import io.zipcoder.casino.cardgames.cards.Deck;
6
+import io.zipcoder.casino.utilities.Console;
4
 import io.zipcoder.casino.utilities.Gamble;
7
 import io.zipcoder.casino.utilities.Gamble;
5
 import io.zipcoder.casino.player.BlackJackPlayer;
8
 import io.zipcoder.casino.player.BlackJackPlayer;
6
 import io.zipcoder.casino.player.Player;
9
 import io.zipcoder.casino.player.Player;
15
 
18
 
16
     private Deck deck = new Deck();
19
     private Deck deck = new Deck();
17
     private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
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
     long bet;
23
     long bet;
21
 
24
 
22
 
25
 
46
         dealCards(currentPlayer, 2);
49
         dealCards(currentPlayer, 2);
47
 
50
 
48
         if (getSum(dealerHand) == 21){
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
             Console.println("Dealer wins.");
54
             Console.println("Dealer wins.");
52
         }
55
         }
53
 
56
 
54
         if (getSum(playerHand) == 21){
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
             Console.println("You wins.");
60
             Console.println("You wins.");
58
         }
61
         }
59
 
62
 
61
 
64
 
62
             Console.println("You have: ");
65
             Console.println("You have: ");
63
             for (int i = 0; i < playerHand.size(); i++) {
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
             String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
70
             String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
68
 
71
 
69
             while (getSum(playerHand) < 21){
72
             while (getSum(playerHand) < 21){
72
             } else if (hitOrStand.equals("S")){
75
             } else if (hitOrStand.equals("S")){
73
                 break;
76
                 break;
74
             }else {
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
             Console.println("You have: ");
80
             Console.println("You have: ");
78
                 for (int i = 0; i < playerHand.size(); i++) {
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
                 return false;
86
                 return false;
84
             }
87
             }
85
 
88
 
86
             Console.println("Dealer's card are: ");
89
             Console.println("Dealer's card are: ");
87
             for (int i = 0; i < dealerHand.size(); i++) {
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
             while (getSum(dealerHand) < 17) {
93
             while (getSum(dealerHand) < 17) {
91
                 Card newCard = drawCard();
94
                 Card newCard = drawCard();
94
                     Console.println("Dealer busted. " + currentPlayer + " wins.");
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
     public void dealCards(BlackJackPlayer player, int numberOfCards) {
116
     public void dealCards(BlackJackPlayer player, int numberOfCards) {
109
         bet = Console.getLongInput("Please enter your bet.");
126
         bet = Console.getLongInput("Please enter your bet.");
110
     }
127
     }
111
 
128
 
129
+
112
     public void evaluateBet(Player player, long payout) {
130
     public void evaluateBet(Player player, long payout) {
113
 
131
 
114
     }
132
     }
140
     }
158
     }
141
 
159
 
142
 
160
 
143
-    public int  getSum(ArrayList<Card> cardHands) {
161
+    public int  getSum(CardHand cardHands) {
144
         int cardSum = 0;
162
         int cardSum = 0;
145
         boolean ace = false;
163
         boolean ace = false;
146
 
164
 
166
 
184
 
167
     }
185
     }
168
 
186
 
187
+
169
 }
188
 }

+ 0
- 1
src/main/java/io/zipcoder/casino/cardgames/cards/Card.java View File

26
         this.cardValue = cardValue;
26
         this.cardValue = cardValue;
27
     }
27
     }
28
 
28
 
29
-
30
 }
29
 }

+ 6
- 0
src/main/java/io/zipcoder/casino/cardgames/cards/CardHand.java View File

12
     public CardHand() {
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 View File

39
 
39
 
40
     }
40
     }
41
 
41
 
42
-    public String getCard(Card card){
43
-        return card.getCardValue() + "of" + card.getSuit();
44
-        }
45
 
42
 
46
 }
43
 }