-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
55 lines (41 loc) · 1.33 KB
/
Player.java
File metadata and controls
55 lines (41 loc) · 1.33 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
import java.util.ArrayList;
public class Player{
private ArrayList<Card> hand = new ArrayList<>();
private ArrayList<Card> palette = new ArrayList<>();
public Player clonePlayer() {
Player copy = new Player();
for (Card card : this.hand) {
copy.hand.add(new Card(card.getColor(), card.getNumber()));
}
for (Card card : this.palette) {
copy.palette.add(new Card(card.getColor(), card.getNumber()));
}
return copy;
}
public static <T> void replaceContentsWithAnother(ArrayList<T> toReplace, ArrayList<T> newContents) {
toReplace.clear();
toReplace.addAll(newContents);
}
public void copyFrom(Player other) {
replaceContentsWithAnother(this.hand, other.hand);
replaceContentsWithAnother(this.palette, other.palette);
}
public ArrayList<Card> getHand() {
return hand;
}
public ArrayList<Card> getPalette() {
return palette;
}
public void setHand(ArrayList<Card> hand) {
this.hand = new ArrayList<>(hand);
}
public void setPalette(ArrayList<Card> palette) {
this.palette = new ArrayList<>(palette);
}
public Card removeCardFromHand(int index) {
return hand.remove(index);
}
public void addCardToPalette(Card card) {
palette.add(card);
}
}