-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoom.java
103 lines (75 loc) · 2.46 KB
/
Room.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
91
92
93
94
95
96
97
98
99
100
101
102
103
class Room {
static String[] directions = {"[n]orth","[e]ast","[s]outh","[w]est"};
String name;
String description;
Room[] doors = new Room[4];
Item[] items;
Monster[] monsters;
boolean locked = false;
Room(String name, String description){
this.name = name;
this.description = description;
}
public void setDoors(Room north, Room east, Room south, Room west){
this.doors[0] = north;
this.doors[1] = east;
this.doors[2] = south;
this.doors[3] = west;
}
void setMonsters(Monster[] monsters){
this.monsters = new Monster[monsters.length];
for ( int i =0; i<monsters.length; i++ ){
this.monsters[i] = monsters[i];
}
}
void setItems(Item[] items){
this.items = new Item[items.length];
for ( int i = 0; i<items.length; i++ ){
this.items[i] = items[i];
}
}
void unlock(){
this.locked = false;
}
void describe(){
System.out.print("You are in ");
System.out.println(this.description);
// monsters in the room
if(this.monsters.length > 0){
if(this.monsters.length == 1){
System.out.println("\nIn the room there is one monster: \n");
}else{
System.out.print("In the room there are ");
System.out.println(this.monsters.length + " monsters \n");
}
}
if(this.monsters.length > 0){
for (int i = 0; i<this.monsters.length; i++){
System.out.println(ConsoleColors.RED + this.monsters[i].describe() + ConsoleColors.RESET);
}
System.out.println();
}
this.getExits();
} //end of describe method
// exits
void getExits(){
System.out.print("\nThere are exit doors to the ");
for (int i=0; i<4; i++){
if (this.doors[i] != null){
System.out.print(directions[i] + " ");
}
}
System.out.println("\n");
}
void getItems(){
if (this.items.length > 0
) {
System.out.println("\nIn the room, there is:\n");
for (int i = 0; i < this.items.length; i++){
System.out.print(ConsoleColors.YELLOW + "("+ (i+1) + ") " );
this.items[i].about();
System.out.println(ConsoleColors.RESET);
}
}
}
}