-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
65 lines (54 loc) · 1.83 KB
/
Player.java
File metadata and controls
65 lines (54 loc) · 1.83 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
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
class Player extends Characters {
private ArrayList<Artifact> Inventory = new ArrayList<>();
private Location location;
private int health = 3;
Player(String name, String description) {
super(name, description);
}
//update player health
void modHealth(boolean isUp) {
if(!isUp) {
health--;
} else {
health++;
}
}
ArrayList<Artifact> returnInventory() {
return Inventory;
}
void getInventory(BufferedWriter out) throws IOException {
System.out.println("Your Inventory contains:");
for(Artifact a : Inventory) {
out.write(a.getName() + " -- " + a.getDescription() + "\n");
}
}
void checkHealth(BufferedWriter out, Location loc) throws IOException {
if(health == 0) {
location.getArtifacts().addAll(Inventory);
Inventory.removeAll(Inventory);
location.getCharactersHere().remove(this);
location = loc;
health = 3;
out.write("You died! You have been returned to where you started.\n");
}
}
void addToInventory(Artifact artifact, BufferedWriter out) throws IOException {
Inventory.add(artifact);
location.getArtifacts().remove(artifact);
out.write(artifact.getName() + " has been added to your inventory.\n");
}
void removeFromInventory(Artifact artifact, BufferedWriter out) throws IOException {
location.getArtifacts().add(artifact);
Inventory.remove(artifact);
out.write(artifact.getName() + " has been removed from your inventory.\n");
}
void setLocation(Location l) {
this.location = l;
}
Location getLocation() {
return location;
}
}