-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
89 lines (75 loc) · 2.05 KB
/
Player.java
File metadata and controls
89 lines (75 loc) · 2.05 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
88
89
import java.util.ArrayList;
import java.util.List;
public class Player implements Theme {
private final String name;
private int moves = 0;
private int fails = 0;
private int points;
private IntPair position;
private List<Content> possession = new ArrayList<Content>();
public Player(String name) {
this.name = name;
}
public String getName() {
return name;
}
public int getMoves() {
return moves;
}
public void incrMove() {
this.moves += 1;
}
public int getFails() {
return fails;
}
public void incrFail() {
this.fails += 1;
setPoints(getPoints() - 1);
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
public IntPair getPosition() {
return position;
}
public void setPosition(IntPair position) {
this.position = position;
}
public void addPossession(Content content) {
possession.add(content);
}
public boolean hasPossession(Content content) {
if (possession.contains(content))
return true;
return false;
}
/* allows possession to be printed as corresponding unicode character */
private List<String> possessionTheme() {
List<String> list = new ArrayList<>();
for (int i = 0; i < possession.size(); i++) {
switch (possession.get(i)) {
case KEY:
list.add(" " + Key);
break;
case TROPHY:
list.add(" " + Trophy);
break;
case HAMMER:
list.add(" " + Hammer);
break;
default:
list.add(possession.get(i).toString());
break;
}
}
return list;
}
@Override
public String toString() {
return "NAME: " + name + ", POSSESSIONS: " + possessionTheme() + "\nMOVES: " + moves + ", FAILS: " + fails
+ ", POINTS: " + points;
}
}