-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
282 lines (232 loc) · 12.1 KB
/
script.js
File metadata and controls
282 lines (232 loc) · 12.1 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
const blockFloors = {
"Main Guardhouse": [],
"Arts Block": ["Ground Floor (Main Office)", "First Floor (Primary music)", "Second Floor (Secondary art)", "Third Floor (Secondary music)", "Fourth Floor (Secondary drama)", "Fifth Floor (Secondary DT)", "Sixth Floor (Finance office)"],
"Sports Field": [],
"Primary Block": ["Ground Floor (Y1 and Y2)", "First Floor (Primary hall + library)", "Second Floor (Y3 and Y4)", "Third Floor (Y5 and Y6)"],
"Adventure Playground": [],
"Under Cover Basketball Court": [],
"Centre Block": ["Ground Floor (Languages + Pool + Canteen + Courts)", "First Floor (Grand Hall + Sports Hall)", "Second Floor (Business + Computing)"],
"Swimming Pool": [],
"Secondary Block": ["Basement Floor (B)", "Lower Floor (L)","Ground Floor (G)", "First Floor (F)", "Second Floor (S)"],
"Drop-off & Pick-up Zone": [],
};
let startPointBlock = '';
let destinationPointBlock = '';
function generateFloorButtons(block, containerId) {
const floorButtonsContainer = document.getElementById(containerId);
floorButtonsContainer.innerHTML = '';
const floors = blockFloors[block];
if (floors && floors.length > 0) {
for (const floor of floors) {
const button = document.createElement('button');
button.textContent = floor;
button.addEventListener('click', () => {
changeFloor(floor)
});
floorButtonsContainer.appendChild(button);
}
} else {
const noFloorMessage = document.createElement('p');
noFloorMessage.textContent = "No floors available for this block.";
floorButtonsContainer.appendChild(noFloorMessage);
}
}
function generateBlockDropdown(blocks, containerId) {
const container = document.getElementById(containerId);
container.innerHTML = '';
const select = document.createElement('select');
select.id = containerId + '-dropdown';
if (containerId === 'start-point-container') {
select.innerHTML = '<option value="">Choose your starting block...</option>';
} else{
select.innerHTML = '<option value="">Choose your destination block...</option>';
}
blocks.forEach(block => {
const option = document.createElement('option');
option.textContent = block;
option.value = block;
select.appendChild(option);
});
select.addEventListener('change', () => {
const selectedBlock = select.value;
if (containerId === 'start-point-container') {
startPointBlock = selectedBlock;
generateFloorButtons(selectedBlock, 'start-floor-buttons');
} else if (containerId === 'destination-container') {
destinationPointBlock = selectedBlock;
generateFloorButtons(selectedBlock, 'destination-floor-buttons');
}
});
container.appendChild(select);
}
function generateBlockButtons() {
const blockButtonsContainer = document.getElementById('block-buttons');
blockButtonsContainer.innerHTML = '';
for (const block in blockFloors) {
const button = document.createElement('button');
button.textContent = block;
button.addEventListener('click', () => {
generateFloorButtons(block, 'floor-buttons');
});
blockButtonsContainer.appendChild(button);
}
}
function changeFloor(floor) {
const currentMap = document.getElementById('current-map');
currentMap.style.width = "1000px";
currentMap.style.height = "500px";
currentMap.src = `${floor}_map.png`;
function displayInstructions(start, destination, floor) {
alert(instructions);
console.log(destination);
console.log(instructions);
}
}
function findBlock() {
const roomNumberInput = document.getElementById('room-number').value;
let block = "";
let floor = "";
if (roomNumberInput.startsWith('G')) {
block = "Secondary Block";
floor = "Ground Floor (G)";
alert("This is on the Ground Floor (Secondary Maths) in the Secondary Block. Press ok to be directed to the map of the floor");
changeFloor(floor);
} else if (roomNumberInput.startsWith('F')) {
block = "Secondary Block";
floor = "First Floor (F)";
alert("This is on the F Floor (Secondary English) in the Secondary Block. Press ok to be directed to the map of the floor");
changeFloor(floor);
} else if (roomNumberInput.startsWith('S')) {
block = "Secondary Block";
floor = "Second Floor (S)";
alert("This is on the S Floor (Secondary Humanities) in the Secondary Block. Press ok to be directed to the map of the floor");
changeFloor(floor);
} else if (roomNumberInput.startsWith('L')) {
block = "Secondary Block";
floor = "Lower Floor (L)";
alert("This is on the L Floor (Secondary Science) in the Secondary Block. Press ok to be directed to the map of the floor")
changeFloor(floor);
} else if (roomNumberInput.startsWith('B')) {
block = "Secondary Block";
floor = "Basement Floor (B)";
alert("This is on the B Floor (Sixth Form Center) in the Secondary Block. Press ok to be directed to the map of the floor")
changeFloor(floor);
} else if (roomNumberInput.startsWith('M')) {
block = "Centre Block";
floor = "Ground Floor (Languages + Pool + Canteen + Courts)";
alert("This is on the Ground Floor in the the Centre Block. Press ok to be directed to the map of the floor")
changeFloor(floor);
} else if (roomNumberInput.startsWith('C')) {
block = "Centre Block";
floor = "Second Floor";
alert("This is on the Second Floor in the the Centre Block. Press ok to be directed to the map of the floor")
changeFloor(floor);
} else if (roomNumberInput.startsWith('2')) {
block = "Arts Block";
floor = "Second Floor (Secondary art)";
alert("This is on the Second Floor (Secondary art) in the the Arts Block. Press ok to be directed to the map of the floor.")
changeFloor(floor);
}
else if (roomNumberInput.startsWith('AS')) {
block = "Arts Block";
floor = "Second Floor (Secondary art)";
alert("This is on the Second Floor (Secondary art) in the the Arts Block. Press ok to be directed to the map of the floor.")
changeFloor(floor);
}
else if (roomNumberInput.startsWith('DT')) {
block = "Arts Block";
floor = "Fifth Floor (Secondary DT)";
alert("This is on the Fifth Floor (Secondary DT) in the the Arts Block. Press ok to be directed to the map of the floor")
changeFloor(floor);
}
else if (roomNumberInput.startsWith('3')) {
block = "Arts Block";
floor = "Third Floor (Secondary music)";
alert("This is on the Third Floor (Secondary music) in the the Arts Block. Press ok to be directed to the map of the floor")
changeFloor(floor);
}
else if (roomNumberInput.startsWith('4')) {
block = "Arts Block";
floor = "Fourth Floor (Secondary drama)";
alert("This is on the Fourth Floor (Secondary drama) in the the Arts Block. Press ok to be directed to the map of the floor")
changeFloor(floor);
}
else {
alert("Invalid room number or room not found.");
}
}
function navigate() {
const instructionsContainer = document.getElementById('instructions-container');
instructionsContainer.innerHTML = '';
if (!startPointBlock || !destinationPointBlock) {
alert("Please select both starting point and destination.");
return;
}
let instructions = [];
instructions.push(`Navigating from ${startPointBlock} to ${destinationPointBlock}.`);
if (destinationPointBlock === startPointBlock) {
instructions.push(`Your destination and starting block are the same. Click the ${startPointBlock} button above to view the maps of ${startPointBlock}.`);
}else{
instructions.push("Go to the lowest floor of the block.");
if (destinationPointBlock === "Sports Field") {
instructions.push("You should be able to see the football field.");
} else {
instructions.push("Go to the main football field. Face and stand in front of the construction site.");
}
if (destinationPointBlock === "Main Guardhouse") {
instructions.push("Turn left and walk up the small set of stairs on the walkway in front of you.");
instructions.push("Walk forward and turn to your right. You should see the main guardhouse in front of you, slightly to your left");
}
if (destinationPointBlock === "Arts Block") {
instructions.push("Turn left and walk up the small set of stairs on the walkway in front of you.");
instructions.push("Turn to your left. You should see a set of stairs leading up. Take these stairs. 1st Floor: Primary Music, 2nd Floor: Secondary Art, 3rd Floor: Secondary Music, 4th Floor: Secondary Drama, 5th Floor: Secondary DT, 6th Floor: Finance Office.");
}
if (destinationPointBlock === "Under Cover Basketball Court") {
instructions.push("Turn around completely and walk towards the right side of the field.");
instructions.push("The basketball court should be in front of you.");
}
if (destinationPointBlock === "Secondary Block") {
instructions.push("Walk towards your right.");
instructions.push("Enter the covering. The sixth form center is in front of you. If you want to go to another floor in the block, take the staircase on your right. 1st Floor: Secondary Science, 2nd Floor: Secondary Maths, 3rd Floor: Secondary English, 4th Floor: Secondary Humanities (history + computer science).");
}
if (destinationPointBlock === "Swimming Pool") {
instructions.push("Turn around completely and walk towards the left side of the field.");
instructions.push("The swimming pool should be in front of you. Entrance is through the changing room. You must ask a teacher's permission to enter the changing rooms.");
}
if (destinationPointBlock === "Centre Block") {
instructions.push("Turn around completely and walk towards the opening on the right side of the pool and the left side of the basketball court.");
instructions.push("Enter the covering. Walk up the stairs directly in front of you. The Grand Hall is to your right and the Sports Hall is to your left. If you want to go to business floors, turn left and go up the narrow set of stairs on your right.");
}
if (destinationPointBlock === "Adventure Playground") {
instructions.push("Turn around and walk towards the basketball court. ");
instructions.push("Walk on the pavement on the right side of the basketball court.")
instructions.push("Walk straight ahead, through the canteen, until you reach the road.")
instructions.push("Then, turn right, walk along the pavement parallel to road. In front of you, you should see the Adventure Playground. ")
}
if (destinationPointBlock === "Drop-off & Pick-up Zone") {
instructions.push("Turn around and walk towards the opening on the right side of the pool and the left side of the basketball court.");
instructions.push("Enter the covering. Walk up the stairs in front of you. Turn right and walk across the corridor until you reach a set of stairs. ");
instructions.push("Walk up these stairs. Turn right immediatelu, you should see a road in front of you, where cars can drive through. Turn left and walk up the stairs to exit the school. This will lead you to Jaya Grocer.")
}
if (destinationPointBlock === "Primary Block") {
instructions.push("Turn around and walk towards the right side of the field (basketball court). Walk on the pavement on the right side of the field. There should be a small set of stairs that leads to a smaller field on the right of the big football field. ");
instructions.push('You are now in the primary block. Take the staircase on your left up. Ground Floor: Y1 and Y2. First Floor: Primary Hall and Library. Second Floor: Y3 and Y4. Third Floor: Y5 and Y6.')
}
}
let formattedInstructions = '';
instructions.forEach((instruction, index) => {
formattedInstructions += `${index + 1}. ${instruction}\n\n`;
});
const instructionsParagraph = document.createElement('p');
instructionsParagraph.textContent = formattedInstructions;
instructionsContainer.appendChild(instructionsParagraph);
console.log(formattedInstructions);
}
window.onload = () => {
generateBlockButtons();
generateBlockDropdown(Object.keys(blockFloors), 'start-point-container');
generateBlockDropdown(Object.keys(blockFloors), 'destination-container');
const navigateButton = document.createElement('button');
navigateButton.textContent = '';
navigateButton.addEventListener('click', navigate);
};