-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
67 lines (53 loc) · 1.15 KB
/
Player.java
File metadata and controls
67 lines (53 loc) · 1.15 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
import java.util.*;
public class Player{
private String name;
private Card[] hand = new Card[10];
private int numCards;
public Player (String aName){
this.name = aName;
this.emptyHand();
}
public void emptyHand(){
for(int c = 0; c<10;c ++){
this.hand[c] = null;
}
this.numCards = 0;
}
public boolean addCard(Card aCard){
this.hand[this.numCards] = aCard;
this.numCards++;
return (this.getHandSum()<= 21);
}
public int getHandSum(){
int handSum = 0;
int cardNum;
int numAces = 0;
for(int c = 0; c < this.numCards; c++){
cardNum = this.hand[c].getNumber();
if(cardNum == 1){
numAces++;
handSum += 11;
}else if(cardNum > 10){
handSum+= 10;
}else{
handSum += cardNum;
}
}
while(handSum > 21 && numAces > 0){
handSum -= 10;
numAces--;
}
return handSum;
}
public void printHand(boolean showFirstCard){
//NEED TO FIX THIS -->
System.out.printf("Dealers cards:\n",this.name);
for(int c = 0; c< this.numCards; c++){
if(c == 0 && !showFirstCard){
System.out.println(" [hidden]");
} else {
System.out.printf("Players\n", this.hand[c].toString());
}
}
}
}