-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.java
More file actions
121 lines (98 loc) · 2.93 KB
/
Room.java
File metadata and controls
121 lines (98 loc) · 2.93 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package APCSA.APCSA_Code_Your_Own;
import java.io.Serializable;
import java.util.*;
public class Room implements Serializable{
private ArrayList<Item> items = new ArrayList<Item>();
private HashMap<String, Door> doors;
private boolean connected;
private int row;
private int column;
private ArrayList<NonPlayerCharacter> npcs = new ArrayList<NonPlayerCharacter>();
public Room(int row, int column, HashMap<String, Door> doors) {
this.row = row;
this.column = column;
this.doors = doors;
}
public int getRow() {
return row;
}
public int getColumn() {
return column;
}
public HashMap<String, Door> getDoors() {
return doors;
}
public ArrayList<NonPlayerCharacter> getNpcs() {
return npcs;
}
public boolean isConnected() {
return connected;
}
public void removeDoor(String direction) {
doors.remove(direction);
}
public void setDoors(HashMap<String, Door> doors) {
this.doors = doors;
}
public void addDoor(Door door) {
if (!doors.containsKey(door.getDirection())) {
doors.put(door.getDirection(), new Door(door.getDirection()));
}
}
public void setConnection(boolean connected) {
this.connected = connected;
}
public void addItem(Item item) {
this.items.add(item);
}
public void addNpc(NonPlayerCharacter npc) {
this.npcs.add(npc);
}
public boolean hasNpcs(){
if(!npcs.isEmpty()){
for (NonPlayerCharacter npc : npcs){
if (!npc.isDead()){
return true;
}
}
}
return false;
}
public String toString() {
String returnString = "";
returnString += "The room contains the following doors:\n";
for (Door door : doors.values()) {
returnString += "\n\t" + door.toString();
}
returnString += "\n";
returnString += "\nThe room contains the following items:\n";
if (items.isEmpty()) {
returnString += "\n\tThe room contains no items.";
} else {
for (Item item : items) {
returnString += "\n\t" + item.toString();
}
}
returnString += "\n";
if (!npcs.isEmpty()) {
returnString += "\nThe room contains the following enemies:\n";
for (NonPlayerCharacter npc : npcs) {
returnString += "\n\t" + npc.toString();
}
returnString += "\n";
}
return returnString;
}
public boolean hasNorthDoor() {
return doors.containsKey("north");
}
public boolean hasEastDoor() {
return doors.containsKey("east");
}
public boolean hasSouthDoor() {
return doors.containsKey("south");
}
public boolean hasWestDoor() {
return doors.containsKey("west");
}
}