-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblackJackHand.java
More file actions
61 lines (57 loc) · 1.25 KB
/
blackJackHand.java
File metadata and controls
61 lines (57 loc) · 1.25 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
57
58
59
60
61
public class blackJackHand {
int totalHandValue; // black jack value of the hand
int cardCount; //number of cards in the hand
boolean ace = false;//ace there true or false
boolean aceHigh = false;// used 11 or not
Card [] handCards = new Card[11];
public blackJackHand(){
totalHandValue=0;
cardCount=0;
}
public void addCard(Card newCard){
handCards[cardCount] = newCard;
cardCount++;
}
public Card getCard(int i){
return handCards[i];
}
// clears everything for the hand
public void handClear(){
for (int i=0; i<cardCount; i++) {
handCards[i]=null;
}
totalHandValue=0;
cardCount=0;
aceHigh=false;
ace=false;
}
//card counter illegal
public int getCardCount(){
return cardCount;
}
// value of hand
public int BlackjackValue(){
int cardVal;
totalHandValue=0;
Card temp;
for (int i=0; i < cardCount; i++) {
temp= handCards[i];
cardVal = temp.getValue();
if (cardVal > 10) {
cardVal = 10;
}
if (cardVal == 1) {
ace=true;
}
totalHandValue = totalHandValue + cardVal;
}
if (ace == true && totalHandValue + 10 <= 21) {
totalHandValue = totalHandValue + 10;
aceHigh=true;}
if (totalHandValue > 21 && aceHigh) {
totalHandValue-=10;
aceHigh=false;
}
return totalHandValue;
}
}