-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHand.java
More file actions
88 lines (66 loc) · 1.46 KB
/
Hand.java
File metadata and controls
88 lines (66 loc) · 1.46 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package Blackjack.src.main.java.model;
/**
* Represents a hand of blackJack
*/
public class Hand
{
private Card[] hand = new Card[0];
private int handValue = 0;
private int bet = 0;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Hand(int bet){
this.bet = bet;
}
public void addCard(Card card){
this.expand();
hand[hand.length-1] = card;
if(card.getFaceValue() == 0)
handValue = handValue + 11;
else if(card.getFaceValue() == 10 || card.getFaceValue() == 11 || card.getFaceValue() == 12)
handValue = handValue + 10;
else
handValue = handValue + card.getFaceValue()+1;
if(handValue > 21){
for(int i = 0 ; i < hand.length ; i++){
if(hand[i].getFaceValue() == 0)
handValue = handValue - 10;
if(handValue < 21)
break;
}
}
}
public int getBet() {
return bet;
}
public void setBet(int bet) {
this.bet = bet;
}
public Card[] getHand() {
return hand;
}
public Card getCard(int cardPosition){
return hand[cardPosition];
}
public void setCard(int cardPosition, Card card){
hand[cardPosition] = card;
}
public int getHandValue() {
return handValue;
}
private void expand(){
Card[] temp = new Card[hand.length+1];
for(int i = 0 ; i < hand.length ; i++)
temp[i] = hand[i];
hand = temp;
}
public String toString(){
String result = "";
for(int i = 0 ; i < hand.length ; i++)
result = result + hand[i];
return result;
}
}