-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
87 lines (69 loc) · 1.53 KB
/
Player.java
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
import java.util.Arrays;
public class Player {
/*
* ++ Instance Variables++
*/
public Card[] hand = new Card[11];
public int winCount = 0;
public int nextIndex = 0;
//return the number of cards in hand
public int getHandSize()
{
boolean hasCard = true;
int x = 0;
int cards = 0;
while (hasCard == true) {
if (hand[x] != null) {
cards++;
} else {
hasCard = false;
}
x++;
}
return cards;
}
/*
* ++ Constructor ++
*/
public Player() {
}
/*
* ++ Methods ++
*/
//increment the player's win count
public void countWin()
{
winCount++;
}
//return this player's win count
public int getWinCount()
{
return winCount;
}
//compute the value of
public int getHandValue()
{
int total = 0;
for (int x = 0; x < getHandSize(); x++) {
total += hand[x].getValue();
}
return total;
}
//"discard" the Player's hand when a new round begins
public void resetHand() {
for (int x = 0; x <= 10; x++) {
hand[x] = null;
nextIndex = 0;
}
}
//add temp to this player's hand
public void addCardToHand( Card temp )
{
hand[nextIndex] = temp;
nextIndex++;
}
public String toString()
{
return "hand = " + Arrays.toString(hand) + " \n- # wins " + winCount;
}
}