-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroom.js
More file actions
67 lines (53 loc) · 1.36 KB
/
room.js
File metadata and controls
67 lines (53 loc) · 1.36 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
// room.js
class Room {
#name;
#description;
#items;
#exits;
constructor(name, description) {
this.#name = name;
this.#description = description;
this.#items = [];
this.#exits = {};
}
get name() {
return this.#name;
}
get description() {
return this.#description;
}
get items() {
return this.#items;
}
get exits() {
return this.#exits;
}
setExit(direction, room) {
this.#exits[direction] = room;
}
addItem(item) {
this.#items.push(item);
}
removeItem(itemName) {
this.#items = this.#items.filter(i => i.name !== itemName);
}
describe() {
console.log(`\n${this.#name}`);
console.log(this.#description);
if (this.#items.length > 0) {
console.log("Itens nesta sala:");
this.#items.forEach(i => console.log(`- ${i.name}`));
} else {
console.log("Não há itens aqui.");
}
const directions = Object.keys(this.#exits);
console.log("Saídas disponíveis: " + (directions.length > 0 ? directions.join(", ") : "nenhuma"));
}
getItemByName(name) {
return this.#items.find(i => i.name === name) || null;
}
getExit(direction) {
return this.#exits[direction] || null;
}
}
module.exports = Room;