-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
94 lines (77 loc) · 2.55 KB
/
Copy pathPlayer.java
File metadata and controls
94 lines (77 loc) · 2.55 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
90
91
92
93
import java.util.*;
public class Player {
private String currentLocation;
private String playerName;
private final ArrayList<String> inventory;
private int healthLevel;
public Player(){
inventory = new ArrayList<>();
}
public boolean setCurrentLocation(String location, GameModel model) {
if (!model.locationExist(location)) { // Check that it's actually a valid location
return false;
}
if (!model.getOneLocation(getCurrentLocation()).isItAPath(location)) {
return false; // The location is not on the path
}
currentLocation = location;
return true;
}
public void setStartLocation(String location){
currentLocation = location;
}
public String getCurrentLocation(){
return currentLocation;
}
public void setPlayerName(String playerName){
this.playerName = playerName;
}
public String getPlayerName(){
return playerName;
}
public boolean addToInventory(String object, GameModel model) {
// Check that the entity is in the location and the type is 'artefact' before adding
if (model.getOneLocation(getCurrentLocation()).isEntityInLocation(object)) {
if (model.getOneLocation(getCurrentLocation()).getEntity(object).getType().equals("artefacts")) {
inventory.add(object);
model.getOneLocation(getCurrentLocation()).removeEntity(object); // Removes from location
return true;
}
}
return false;
}
public boolean removeFromInventory(String object, GameModel model, String command) {
if (isInInventory(object)) {
inventory.remove(object);
if (command.equals("drop")) {
model.getOneLocation(getCurrentLocation()).addEntity(object, model); // Puts entity back in the location
}
return true;
}
return false;
}
public ArrayList<String> getInventory(){
return inventory;
}
public boolean isInInventory(String object){
return inventory.contains(object);
}
public void setHealthLevel(){
healthLevel = 3;
}
public int getHealthLevel(){
return healthLevel;
}
public void addToHealth(){
healthLevel = healthLevel + 1;
}
public void subtractHealth(){
healthLevel = healthLevel - 1;
}
public boolean isPlayerDead(){
if (healthLevel == 0){
return true;
}
return false;
}
}