-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle3.html
474 lines (369 loc) · 16 KB
/
puzzle3.html
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<!DOCTYPE html>
<html>
<head>
<title>Level 3</title>
<style>
.container {
width: 100%;
height: 100%;
position: relative;
}
body, html {
overflow: hidden;
margin: 0;
padding: 0;
height: 100%;
}
.button:hover {
opacity: 0.7;
}
.button-container {
position: fixed;
top: 10px;
left: 10px;
z-index: 10;
}
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 1);
z-index: 9;
display: none;
}
.toast-message {
color: white;
font-size: 24px;
margin-bottom: 20px;
}
.toast-buttons {
display: flex;
flex-wrap: wrap; /* Enable wrapping */
max-width: 480px;
}
.toast-button {
margin-right: 10px;
margin-bottom: 10px; /* Add margin between rows */
padding: 10px 20px;
background-color: #87ffbf;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.toast-button:last-child {
margin-right: 0;
}
#decisionTree {
padding: 1vw;
height: 5vh;
width: 5vw;
}
.level-container {
height: 20vh;
width: 45vw;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-around;
}
.textbox {
margin: 1vw;
border: 1px solid darkgreen;
width: 9vw;
height: 9vw;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Bradley Hand', cursive;
font-size: 2vw;
color: white;
min-width: 9vw;
}
.yesBranch {
margin: 2vw;
width: 0.1vw;
height: 5vw;
display: flex;
justify-content: center;
align-items: center;
transform: rotate(45deg);
font-family: 'Bradley Hand', cursive;
}
.noBranch {
margin: 2vw;
width: 0.1vw;
height: 5vh;
display: flex;
justify-content: center;
align-items: center;
transform: rotate(45deg);
font-family: 'Bradley Hand', cursive;
}
.glowing-textbox {
transition: box-shadow 0.5s ease-in-out;
}
.text-inside {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
transform-origin: center;
font-family: 'Bradley Hand', cursive;
font-size: 50px;
color: white;
-webkit-text-stroke: 2px darkgreen;
}
.toast-panel {
position: fixed;
bottom: 16%;
left: 5%;
width: 33%; /* Adjust as needed */
height: 62%; /* Adjust as needed */
background-color: rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
padding: 2%;
z-index: 3;
}
.toast-draggable {
width: 30vw;
height: 1.6vw;
border: 0.25vw solid #ccc;
border-radius: 0.25vw;
padding: 0.25vw;
cursor: pointer;
margin: 1vw;
display: flex;
justify-content: center;
align-items: center;
background-color: #87ffbf;
font-family: 'Bradley Hand', cursive;
font-size: 1.3vw;
color: darkgreen;
margin-bottom: 1vw;
}
.toast-message {
font-family: 'Bradley Hand', cursive;
font-size: 1.1vw;
color:white;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
</style>
</head>
<body>
<script src="static/jsFiles/treeBuilder.js">//script to hold tree data</script>
<script src="static/jsFiles/testAccuracy.js"></script>
<script src="static/jsFiles/loadAnimals.js">//load animals</script>
<script src="static/jsFiles/defineSplitUI.js">//defining splits</script>
<!-- Images Background-->
<div style="width: 100vw; height: 100vh; position: relative; background-color: #87ffbf"> </div>
<img id="BackgroundImage" style="width: 100%; height: 100%; left: 0%; top: 0%;opacity: 30%; z-index:0;position: absolute" src="static/bgexample4.png" />
<div style="width: 100vw; height: 1vh; left: 0%; top: 5%; position: absolute; display: flex; justify-content: center; align-items: center; font-size: 5vw; text-align: center; color: white; text-shadow: -0.25vw -0.25vw 0 #006400, -0.25vw -0.25px 0 #006400, -0.25px 0.25px 0 #006400, -0.25vw -0.25vw 0 #006400, 0 0 5px #006400; font-family: 'Bradley Hand', cursive;">
Fauna Forest --- Level 3
</div>
<img id="treeBuilderOutline" style="width: 100%; height: 105%; left: 10%; top: -8%; position: absolute" src="static/boxcolor.png" />
<a href="#">
<img id="testAccuracy" class="button" style="width: 26.5%; height: 12%; left: 50%; top: 87%; position: absolute; transform: translateX(-50%);" src="static/next.png" onclick="showNextPuzzle();" />
</a>
<img id="tutorialcursor" style="width: 10%; height: 20%; pointer-events: none; top: 50%; left: 28%;opacity:0; transform: rotate(150deg); z-index: -500; position: absolute; animation: slide 1.2s linear infinite;" src="static/mousecursor1.png" />
<img id="tutorialcursorstart" style="width: 10%; height: 20%; pointer-events: none; top: 24%; left: 35%;opacity:1; transform: rotate(150deg); z-index: -500; position: absolute;animation: pointRotation 1s linear infinite; " src="static/mousecursor1.png" />
<!-- Decesion Trees
The drop containers are held in the nodes, the drag objects are in defineSplitUI.js script under the createToastPanel
-->
<div id="output" style="position: absolute; top: 10%; left: 75%; transform: translate(-50%, -50%); font-size: 1.3vw;"></div>
<!-- </div> -->
<div id="defineSplitMenu" class="popup-menu" style="top: -8%; left: 10%; transform: translate(-50%, -50%);">
<a href="#">Option 1</a>
<a href="#">Option 2</a>
<a href="#">Option 3</a>
</div>
<div id="decisionTree" style="position: absolute; top: 21%; left: 51%; transform: translate(-50%, -50%); z-index: 3;">
<div id="level-1" class="level-container">
<div class="textbox" id="node1" style="background-color: #006400; transform: rotate(45deg);" ondrop="drop(event, 'node1')" ondragover="allowDrop(event)"></div>
</div>
<div id="level-2" class="level-container">
<div class="textbox" id="node2" style="background-color: #006400; transform: rotate(45deg);" ondrop="drop(event, 'node2')" ondragover="allowDrop(event)"></div>
<div class="textbox" id="node3" style="background-color: #006400; transform: rotate(45deg);" ondrop="drop(event, 'node3')" ondragover="allowDrop(event)"></div>
</div>
<div id="level-3" class="level-container" style="margin-top: 5vh;">
<div class="textbox" id="node4" ondrop="drop(event, 'node4')" ondragover="allowDrop(event)"></div>
<div class="textbox" id="node5" ondrop="drop(event, 'node5')" ondragover="allowDrop(event)"></div>
<div class="textbox" id="node6" ondrop="drop(event, 'node6')" ondragover="allowDrop(event)"></div>
<div class="textbox" id="node7" ondrop="drop(event, 'node7')" ondragover="allowDrop(event)"></div>
</div>
</div>
<div id="branches" style="position: absolute; top: 49%; left: 71%; transform: translate(-50%, -50%); z-index: 2;" >
<div id="branches1" class="level-container">
<div class="noBranch" id="branch1" style="background-color: darkgreen; height: 50%; transform: rotate(45deg); margin-left: 30%; z-index:5;">
<span style="color: lightgreen; font-family: 'Bradley Hand', cursive; font-size:2.5vw; transform: rotate(-45deg); display: inline-block; text-shadow: -0.1vw -0.1vw 0 black, 0.1vw -0.1vw 0 black, -0.1vw 0.1vw 0 black, 0.1vw 0.1vw 0 black;">No</span> <!-- Text for the "Yes" branch -->
</div>
<div class="yesBranch" id="branch2" style="background-color: darkgreen; height: 50%; transform: rotate(-45deg); margin-right: 30%; z-index:5;">
<span style="color: lightgreen; font-family: 'Bradley Hand', cursive; font-size:2.5vw; transform: rotate(45deg); display: inline-block; text-shadow: -0.1vw -0.1vw 0 black, 0.1vw -0.1vw 0 black, -0.1vw 0.1vw 0 black, 0.1vw 0.1vw 0 black;">Yes</span> <!-- Text for the "No" branch -->
</div>
</div>
<div id="branches2" class="level-container">
<div class="noBranch" id="branch3" style="background-color: darkgreen; height: 52%; transform: rotate(40deg); margin-left: 10%; margin-top: 9%;; z-index:5;">
<span style="color: lightgreen; font-family: 'Bradley Hand', cursive; font-size:2.5vw; transform: rotate(-40deg); display: inline-block; text-shadow: -0.1vw -0.1vw 0 black, 0.1vw -0.1vw 0 black, -0.1vw 0.1vw 0 black, 0.1vw 0.1vw 0 black;">No</span> <!-- Text for the "Yes" branch -->
</div>
<div class="yesBranch" id="branch4" style="background-color: darkgreen; height: 52%; transform: rotate(-40deg); margin-right: 10%; margin-top: 9%; z-index:5;">
<span style="color: lightgreen; font-family: 'Bradley Hand', cursive; font-size:2.5vw; transform: rotate(40deg); display: inline-block; text-shadow: -0.1vw -0.1vw 0 black, 0.1vw -0.1vw 0 black, -0.1vw 0.1vw 0 black, 0.1vw 0.1vw 0 black;">Yes</span> <!-- Text for the "No" branch -->
</div>
<div class="noBranch" id="branch5" style="background-color: darkgreen; height: 52%; transform: rotate(40deg); margin-left: 10%; margin-top: 9%; z-index:5;">
<span style="color: lightgreen; font-family: 'Bradley Hand', cursive; font-size:2.5vw; transform: rotate(-40deg); display: inline-block; text-shadow: -0.1vw -0.1vw 0 black, 0.1vw -0.1vw 0 black, -0.1vw 0.1vw 0 black, 0.1vw 0.1vw 0 black;">No</span> <!-- Text for the "Yes" branch -->
</div>
<div class="yesBranch" id="branch6" style="background-color: darkgreen; height: 52%; transform: rotate(-40deg); margin-right: 10%; margin-top: 9%;; z-index:5;">
<span style="color: lightgreen; font-family: 'Bradley Hand', cursive; font-size:2.5vw; transform: rotate(40deg); display: inline-block; text-shadow: -0.1vw -0.1vw 0 black, 0.1vw -0.1vw 0 black, -0.1vw 0.1vw 0 black, 0.1vw 0.1vw 0 black;">Yes</span> <!-- Text for the "No" branch -->
</div>
</div>
</div>
<div class="overlay" id="overlay"></div>
<!-- things to do on startup -->
<script>
const initialContent = document.documentElement.outerHTML;
var popupMenu = document.createElement('div');
popupMenu.classList.add('popup-menu');
// Create the accuracy message
var startMessage = document.createElement('p');
startMessage.textContent = "In this level, you will have 90 seconds to solve as many decision tree puzzles as you can, while still maintaining a high accuracy! Press start to begin!";
startMessage.style.fontSize = '2.5vw';
startMessage.style.textAlign = 'center';
startMessage.style.color = 'white';
startMessage.style.textShadow = "-2px -2px 0 #006400, 2px -2px 0 #006400, -2px 2px 0 #006400, 2px 2px 0 #006400";
startMessage.style.fontFamily = 'Bradley Hand';
popupMenu.appendChild(startMessage);
// Create the buttons container
var buttonsContainer = document.createElement('div');
// Create the first button
var button = document.createElement('button');
buttonsContainer.appendChild(button);
popupMenu.appendChild(buttonsContainer);
// Add styles to the popup menu
popupMenu.style.position = 'absolute';
popupMenu.style.top = '50%';
popupMenu.style.left = '50%';
popupMenu.style.transform = 'translate(-50%, -50%)';
popupMenu.style.minWidth = '50vw';
popupMenu.style.width = '60vw';
popupMenu.style.height = '25vw';
popupMenu.style.boxShadow = '0 8px 16px 0 rgba(0,0,0,0.2)';
popupMenu.style.padding = '2vw';
popupMenu.style.backgroundColor = "#87ffbf";
popupMenu.style.zIndex = '10';
popupMenu.id = 'level3StartingMenu';
// Add styles to the buttons container
buttonsContainer.style.display = 'flex';
buttonsContainer.style.justifyContent = 'space-around';
buttonsContainer.style.marginTop = '2vw';
popupMenu.style.justifyContent = 'center'; // Center horizontally
popupMenu.style.alignItems = 'center'; // Center vertically
button.style.padding = '1vw 2vw';
button.style.backgroundColor = '#007bff';
button.style.color = 'white';
button.style.border = 'none';
button.style.borderRadius = '0.5vw';
button.style.cursor = 'pointer';
button.style.width = '26vw';
button.style.height = '6vw';
button.style.marginTop = '2.5vw';
button.style.backgroundImage = "url('static/start.png')";
button.style.backgroundSize = "contain"; // Adjust how the background image is sized
button.onclick = startLevel3;
document.body.appendChild(popupMenu);
var overlay = document.getElementById("overlay");
overlay.style.display = "block";
</script>
<!-- Dragging Background-->
<script src="static/jsFiles/testDragNDrop/ContainerFunctions.js"></script>
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.target.style.opacity = "0"; // Make the dragged image translucent
ev.dataTransfer.setData("text", ev.target.id);
}
function dragEnd(ev) {
ev.target.style.opacity = "1"; // Make the original image opaque again
}
const dropCount = { count: 0 };
function drop(ev, nodeId) {
// Increment the drop count
dropCount.count++;
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
var targetNode = document.getElementById(nodeId);
if (!targetNode) {
console.error("Target node not found:", nodeId);
return;
}
for (let i = 0; i < randPuzzle.leaves.length; i++) {
if (targetNode.textContent == randPuzzle.leaves[i]) {
return; // cannot drag/drop into leaf node
}
}
for (let i = 0; i < randPuzzle.decisionNodesList.length; i++) {
if (targetNode.textContent == randPuzzle.decisionNodesList[i]) {
return; // cannot drag into predefined node
}
}
// add draggable block if user is replacing a selection they already made
var draggableItems = document.getElementById('draggableItems');
if (targetNode.textContent.trim() !== '') {
var draggableItem = document.createElement('div');
draggableItem.textContent = targetNode.textContent.trim();
draggableItem.className = 'toast-draggable';
draggableItem.draggable = true;
for (let i = 0; i < randPuzzle.options.length; i++) {
if (targetNode.textContent.trim() == randPuzzle.options[i].trim()) {
draggableItem.id = `draggable-${i}`;
}
}
// Add drag start event listener
draggableItem.addEventListener('dragstart', (event) => {
event.dataTransfer.setData("text", event.target.id);
});
draggableItems.appendChild(draggableItem);
}
// clear the node before appending new content to prevent stacking
while (targetNode.firstChild) {
targetNode.removeChild(targetNode.firstChild);
}
var dragBlock = document.getElementById(data);
// Rotate the element by 45 degrees
var elementToAppend = document.createElement('div');
elementToAppend.style.transform = "rotate(-45deg)";
elementToAppend.style.fontSize = '2vw';
elementToAppend.style.textAlign = 'center'; // Center-align the text
elementToAppend.textContent = dragBlock.textContent;
targetNode.appendChild(elementToAppend);
// get the index of the node in the treeNodes array
var index = parseInt(nodeId.replace("node", "")) - 1;
// put user's choice into userSelections array for later use
userSelections[index] = document.getElementById(data).textContent;
console.log(userSelections);
// log the name of the draggable item
console.log("Item dropped:", document.getElementById(data).textContent);
// log the current state of the userSelections array
console.log("userSelections:", userSelections);
// remove draggable block from draggables panel
dragBlock.parentNode.removeChild(dragBlock);
switch (nodeId) {
case 'node1':
console.log("Item dropped in node1");
// custom logic for node1
break;
// add cases for other nodes as needed
default:
console.log("Item dropped in", nodeId);
break;
}
}
</script>
</body>
</html>