-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRoom.java
More file actions
195 lines (137 loc) · 3.62 KB
/
Room.java
File metadata and controls
195 lines (137 loc) · 3.62 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package RoomGame;
/**
*
* @author kleesans
*/
public class Room {
private Room north;
private Room south;
private Room east;
private Room west;
String description;
private int state;
String name;
Creature[] RoomOccupants;
private int LastCreatureIndex;
public Room(String name, String description, String state) {
setName(name);
setDescription(description);
if (state.equals("dirty")) {
this.state = 0;
}
if (state.equals("half-dirty")) {
this.state = 1;
}
if (state.equals("clean")) {
this.state = 2;
}
this.RoomOccupants = new Creature[10];
this.LastCreatureIndex = -1;
}
public Room findNeighbor(String command) {
if (command.equalsIgnoreCase("north"))
return findNorth();
if (command.equalsIgnoreCase("east"))
return FindEast();
if (command.equalsIgnoreCase("south"))
return FindSouth();
if (command.equalsIgnoreCase("west")) {
return FindWest();
}
return null;
}
public Room findNorth() {
return this.north;
}
public void setNorthRoom(Room north) {
this.north = north;
}
public Room FindSouth(){
return this.south;
}
public void setDescription(String description) {
this.description = description;
}
public void setName(String name) {
this.name = name;
}
public void setSouthRoom(Room south)
{
this.south = south;
}
public Room FindEast()
{
return this.east;
}
public void setEastRoom(Room east)
{
this.east = east;
}
public Room FindWest()
{
return this.west;
}
public void setWestRoom(Room west)
{
this.west = west;
}
public String toString() {
for (int i = 0; i < 10; i++){
if (RoomOccupants[i] != null) {
System.out.println(RoomOccupants[i].toString());
}
}
return null;
}
public void reactCreaturesChangedRoom(Creature thisone, String command, PC player) {
Creature temp = null;
for (int i = 0; i <= getLastCreature(); i++) {
if (!(getOccupants()[i] instanceof PC)) {
temp = getOccupants()[i];
getOccupants()[i].reactChangedRoomState(command, player);
if (!temp.equals(getOccupants()[i])) {
i--;
}
}
}
}
public void addCreature(Creature thisone, int i)
{
this.RoomOccupants[i] = thisone;
}
public void removeCreature(Creature thisone) {
for (int i = 0; i <= this.LastCreatureIndex; i++) {
if (this.RoomOccupants[i].getName().equalsIgnoreCase(thisone.getName())) {
this.RoomOccupants[i] = null;
for (int j = i; j < this.LastCreatureIndex; j++) {
this.RoomOccupants[j] = this.RoomOccupants[j + 1];
}
this.LastCreatureIndex--;
}
}
}
public Creature[] getOccupants() {
return this.RoomOccupants;
}
public void setOccupants(Creature[] RoomOccupants) {
this.RoomOccupants = RoomOccupants;
}
public int getState() {
return this.state;
}
public String getName() {
return name;
}
public void setState(int state) {
this.state = state;
}
public int getLastCreature() {
return this.LastCreatureIndex; }
public void setLastCreatureIndex(int lastCreatureIndex) {
this.LastCreatureIndex = lastCreatureIndex; }
}