-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoom.java
149 lines (136 loc) · 2.87 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
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
public class Room {
private int[] Coordinates;
private String room = "";
private boolean[] contents;
private String contentstring;
public Room(boolean pit, boolean monster, boolean entrance, boolean exit, boolean visionpotion, boolean healingpotion, int pillar, int size, int x, int y){
Coordinates = new int[] {x,y};
String content = "";
boolean haspillar = false;
if (pillar != -1) {
haspillar = true;
content = Integer.toString(pillar);
}
contents = new boolean[] {pit, monster, entrance, exit, visionpotion, healingpotion, haspillar};
if ((pit || monster || entrance || exit || visionpotion || healingpotion || haspillar) == false) {
content = "E";
}
else {
if(pit) {
content = "P";
}
if(monster) {
if(content == "") {
content = "X";
}
else {
content = "M";
}
}
if(entrance) {
if(content == "") {
content = "I";
}
}
if(exit) {
if(content == "") {
content = "O";
}
}
if(visionpotion) {
if(content == "") {
content = "V";
}
else {
content = "M";
}
}
if(healingpotion) {
if(content == "") {
content = "H";
}
else {
content = "M";
}
}
}
//top wall
if (x == 0) {
room += "***\n";
}else {
room += "*-*\n";
}
//middle section
if (y == 0){
room += "*" + content + "|\n";
}
else if (y == size-1){
room += "|" + content + "*\n";
}
else {
room += "|" + content + "|\n";
}
//bottom wall
if (x == size-1) {
room += "***\n";
}else {
room += "*-*\n";
}
contentstring = content;
}
public int[] getCoordinates() {
return Coordinates;
}
public String getContentString() {
return contentstring;
}
public String getRoom() {
return room;
}
public String getItemContents(){
String itemstring = "This room contains ";
if (contents[2]) {
return itemstring + "the enterance";
}
if (contents[3]) {
return itemstring + "the exit";
}
if (contents[6]) {
return itemstring + "a pillar of OO";
}
String items = "";
if (contents[0]) {
items += "a pit";
}
//can specify monster later
if (contents[1]) {
if (items != "") {
items += ",";
}
items += "a monster";
}
if (contents[4]) {
if (items != "") {
items += ",";
}
items += "a vision potion";
}
if (contents[5]) {
if (items != "") {
items += ",";
}
items += "a healing potion";
}
if (items == "") {
items = "nothing";
}
if (items.contains(",")){
int lastcomma = items.lastIndexOf(',');
items = items.substring(0, lastcomma) + " and " + items.substring(lastcomma + 1);
}
return itemstring + items + "\n";
}
public String toString(){
return room + "\n" + getItemContents();
}
}