|
@@ -9,11 +9,16 @@ public class BlackJack extends CardGame implements Gamble {
|
9
|
9
|
|
10
|
10
|
private Deck deck = new Deck();
|
11
|
11
|
private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
|
12
|
|
- BlackJackPlayer blackJackPlayer = new BlackJackPlayer();
|
13
|
|
- ArrayList<CardHand> cardHands;
|
|
12
|
+ CardHand playerHand = new CardHand();
|
|
13
|
+ CardHand dealerHand = new CardHand();
|
|
14
|
+ long bet;
|
|
15
|
+
|
14
|
16
|
|
15
|
17
|
public BlackJack(){
|
|
18
|
+
|
16
|
19
|
readyPlayers();
|
|
20
|
+ placeBet();
|
|
21
|
+ run();
|
17
|
22
|
}
|
18
|
23
|
|
19
|
24
|
public void readyPlayers() {
|
|
@@ -22,24 +27,78 @@ public class BlackJack extends CardGame implements Gamble {
|
22
|
27
|
}
|
23
|
28
|
}
|
24
|
29
|
|
|
30
|
+ public void run(){
|
|
31
|
+ for(int i = 0; i < blackJackPlayers.size(); i++){
|
|
32
|
+ play(blackJackPlayers.get(i),blackJackPlayers.get(i).getBet());
|
|
33
|
+ }
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ public void play(BlackJackPlayer currentPlayer, long bet) {
|
|
37
|
+
|
|
38
|
+ this.bet = bet;
|
|
39
|
+
|
|
40
|
+ dealCards();
|
|
41
|
+
|
|
42
|
+ if (getSum(dealerHand) == 21){
|
|
43
|
+ Console.println("Dealer has " + dealerHand.cardHand.get(0)) + " and " + dealerHand.cardHand.get(1));
|
|
44
|
+ Console.println(("You have " + playerHand.cardHand.get(0)) + " and " + playerHand.cardHand.get(1));
|
|
45
|
+ Console.println("Dealer wins.");
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ if (getSum(playerHand) == 21){
|
|
49
|
+ Console.println("Dealer has " + dealerHand.cardHand.get(0)) + " and " + dealerHand.cardHand.get(1));
|
|
50
|
+ Console.println(("You have " + playerHand.cardHand.get(0)) + " and " + playerHand.cardHand.get(1));
|
|
51
|
+ Console.println("You wins.");
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ while(true) {
|
|
55
|
+
|
|
56
|
+ Console.println("You have: ");
|
|
57
|
+ for (int i = 0; i < playerHand.size(); i++) {
|
|
58
|
+ Console.println(" " + playerHand.getVardValue(i) + playerHand.getSuit(i));
|
|
59
|
+ }
|
|
60
|
+ Console.println("Dealer is showing a " + dealerHand.getCardValue(0) + " of " + dealerHand.getSuit(0));
|
|
61
|
+ Console.println("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
|
|
62
|
+ Console.getStringInput();
|
|
63
|
+
|
|
64
|
+ while (getSum(playerHand) < 21){
|
|
65
|
+ if (userInput.equals("H")) {
|
|
66
|
+ dealCards();
|
|
67
|
+ } else if (userInput.equals("S")){
|
|
68
|
+ break;
|
|
69
|
+ }else {
|
|
70
|
+ Console.println("Invalid input. Please enter H for Hit or S for Stand");
|
|
71
|
+ }
|
|
72
|
+ Console.println("You have: ");
|
|
73
|
+ for (int i = 0; i < playerHand.size(); i++) {
|
|
74
|
+ Console.println(" " + playerHand.getVardValue(i) + playerHand.getSuit(i));
|
|
75
|
+ }
|
|
76
|
+ Console.println("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
|
|
77
|
+ }
|
|
78
|
+ return false;
|
|
79
|
+ }
|
|
80
|
+}
|
|
81
|
+
|
25
|
82
|
public void dealCards(BlackJackPlayer player, int numberOfCards) {
|
26
|
|
- dealerHand.cardHand.add(); //deals 2 cards for dealer
|
27
|
83
|
|
28
|
84
|
for(BlackJackPlayer p: blackJackPlayers){ //deal 2 cards to each player
|
29
|
85
|
super.dealCards(p, 2);
|
|
86
|
+
|
30
|
87
|
}
|
31
|
88
|
}
|
32
|
89
|
|
|
90
|
+ public void placeBet() {
|
|
91
|
+ Console.println("Please enter your bet.");
|
|
92
|
+ bet = Console.getLongInput();
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+
|
33
|
96
|
public void drawCard() {
|
34
|
97
|
// draws card from deck and adds it to "upcard" total
|
35
|
98
|
dealerHand.cardHand.add(deck.deckOfCards.get(0));
|
36
|
99
|
deck.deckOfCards.remove(0);
|
37
|
100
|
|
38
|
101
|
upcardsValue += dealerHand.cardHand.(0);
|
39
|
|
-// System.out.println("You have the following cards");
|
40
|
|
-// for(CardHand c:cardHands){
|
41
|
|
-// System.out.println(c);
|
42
|
|
-// }
|
43
|
102
|
}
|
44
|
103
|
|
45
|
104
|
public void evaluateDealerHand() {
|
|
@@ -59,12 +118,8 @@ public class BlackJack extends CardGame implements Gamble {
|
59
|
118
|
}
|
60
|
119
|
}
|
61
|
120
|
|
62
|
|
- public long placeBet(long currentBet) {
|
63
|
|
- return blackJackPlayer.getChipBalance() - currentBet;
|
64
|
|
- }
|
65
|
|
-
|
66
|
121
|
|
67
|
|
- public void getSum(ArrayList<CardHand> cardHands) {
|
|
122
|
+ public int getSum(CardHand cardHands) {
|
68
|
123
|
int cardSum = 0;
|
69
|
124
|
boolean ace = false;
|
70
|
125
|
|
|
@@ -82,49 +137,15 @@ public class BlackJack extends CardGame implements Gamble {
|
82
|
137
|
if (ace == true && cardSum + 10 <= 21) {
|
83
|
138
|
cardSum = cardSum + 10;
|
84
|
139
|
}
|
85
|
|
-
|
|
140
|
+ return cardSum;
|
86
|
141
|
}
|
87
|
142
|
|
88
|
143
|
public void evaluateBet(BlackJackPlayer player, long payout){
|
89
|
144
|
|
90
|
145
|
}
|
91
|
146
|
|
92
|
|
- public int revealCard(CardHand cardHand, int index){
|
93
|
|
- return cardHand.getCardValue(index);
|
94
|
|
- }
|
95
|
|
-
|
96
|
|
- public void evaluatePlayerHand(){
|
97
|
|
-
|
98
|
|
- while (true){
|
99
|
|
- System.out.println("You have:");
|
100
|
|
- for (int i = 0; i < cardHands.size(); i++) {
|
101
|
|
- System.out.println(" " + revealCard(cardHand, i));
|
102
|
|
- }
|
103
|
|
- System.out.println("The dealer is showing a " + revealCard(dealerHand,0));
|
104
|
|
- System.out.println("Would you like to Hit (H) or Stand (S)?");
|
105
|
|
- }
|
106
|
|
- // print player's cardHands and sum
|
107
|
|
- //if player has blackjack (ace + face)
|
108
|
|
- //show dealer's card, player win or tie?
|
109
|
|
-
|
110
|
|
- //while player's sum is <21
|
111
|
|
- //prompt player to "Stand" or "Hit"
|
112
|
|
-
|
113
|
|
-
|
114
|
|
-
|
115
|
|
-
|
116
|
|
- }
|
117
|
|
-
|
118
|
|
- public void run(){
|
119
|
|
- boolean quit = false;
|
120
|
|
- while (quit == false) {
|
121
|
|
- drawCard();
|
122
|
|
-
|
123
|
|
-
|
|
147
|
+ public void revealCard(){
|
124
|
148
|
|
125
|
|
- // at the end of each loop, ask players if they would like to continue
|
126
|
|
- }
|
127
|
149
|
}
|
128
|
150
|
|
129
|
|
-
|
130
|
151
|
}
|