-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDealer.java
More file actions
56 lines (50 loc) · 1.54 KB
/
Dealer.java
File metadata and controls
56 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class Dealer {
private Hand dealerHand = new Hand();
/**
* prints the dealer's output in the window
*/
public Dealer () {
dealerHand.createDeck();
dealerHand.shuffleDeck();
}
/**
* prints cards in dealer's hand
*/
public void initDeal() {
dealerHand.initialDeal();
dealerHand.printHand();
dealerHand.evaluateHand();
}
/**
* returns the numerical value of the cards in dealer's hand
*/
public int getHandValue () {
return dealerHand.evaluateHand();
}
public boolean playHand() {
// draw cards until dealerHand >= 16
while (getHandValue() < 16) {
int handCount = 0;
for (int i = 0; i < dealerHand.hand.length; i++) {
if (dealerHand.hand[i] != null){// && handCount > 10) {
handCount++;
}
} // end for
dealerHand.hand[handCount] = dealerHand.deal();System.out.print(getHandValue());
} // end while
System.out.println ("****************");
System.out.println ("Dealer's Hand");
System.out.println ("****************");
dealerHand.printHand();
System.out.println ("Dealer's Hand Value = " + getHandValue());
// determine if bust
if (getHandValue() > 21) {
System.out.println ("The dealer has busted.");
return true;
}
return false;
}
public void printDealerHand() {
dealerHand.printHand();
}
} //end class