-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
52 lines (44 loc) · 1.27 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
public class Player {
private String name;
private Deck gameDeck;
private Deck winningDeck;
public Player(String name) {
this.name = name;
this.gameDeck = new Deck(false);
this.winningDeck = new Deck(false);
}
public String getName() {
return name;
}
public void addToWinningDeck(Card card) {
this.winningDeck.addCard(card);
}
public void addToGameDeck(Card card) {
this.gameDeck.addCard(card);
}
private void switchDeck() {
/**
* when the game deck is empty, the winning deck is shuffled and
* becomes the new game deck.
*/
if (this.gameDeck.isEmpty()) {
winningDeck.shuffle();
while (!this.winningDeck.isEmpty()) {
addToGameDeck(this.winningDeck.removeTopCard());
}
gameDeck.reverse();
}
}
public Card drawCard() {
switchDeck();
return this.gameDeck.removeTopCard();
}
public boolean outOfCards() {
return this.gameDeck.isEmpty() && this.winningDeck.isEmpty();
}
@Override
public String toString() {
/** prints out the player's name. */
return this.name;
}
}