-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathLocation.java
90 lines (71 loc) · 2.03 KB
/
Location.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
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
import java.util.*;
public class Location extends GameObject {
private ArrayList<Character> people;
private ArrayList<Item> items;
private HashMap<String, Location> neighbors;
public Location (String name, String description) {
super(name, description);
people = new ArrayList<>();
items = new ArrayList<>();
neighbors = new HashMap<>();
}
public String getLocation () {
return this.getName();
}
public void addPerson (Character person) {
people.add(person);
}
public void removePerson (Character person) {
people.remove(person);
}
public void addItem (Item item) {
items.add(item);
}
public void removeItem (Item item) {
items.remove(item);
}
public Item containItem (String name) {
for (Item i : this.items) {
if (i.getName().equals(name)) {
return i;
}
}
return null;
}
public Character containCharacter (String name) {
for (Character c : this.people) {
if (c.getName().equals(name)) {
return c;
}
}
return null;
}
public void addNeighbor (String direction, Location neighbor) {
neighbors.put(direction, neighbor);
}
public Location getNeighbor (String direction) {
return neighbors.get(direction);
}
// Unless this game suddenly becomes a survival horror,
// we won't need to remove doors between places
public void removeNeighbor (String direction) {
throw new UnsupportedOperationException("removeNeighbor not written");
}
public void printItemsHere () {
System.out.println("Items Here: ");
for (Item curr : items) {
System.out.println("- " + curr.getName());
}
}
public void printInfo () {
System.out.println(getName());
System.out.println(getDescription());
System.out.println("Nearby:");
for (Map.Entry<String, Location> kv : neighbors.entrySet()) {
System.out.println(String.format(" - %s (go %s)", kv.getValue().getName(), kv.getKey()));
}
}
public String toString () {
return getName() + " - " + getDescription();
}
}