-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.html
874 lines (843 loc) · 48.5 KB
/
game.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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
<!DOCTYPE html>
<html lang="de">
<head>
<title>Michi's Escape Room</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://d3js.org/d3.v6.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.1/css/all.min.css">
<link rel="stylesheet" type="text/css" href="game.css">
<script language="javascript" type="text/javascript" src="game.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap" rel="stylesheet">
</head>
<body onload="window.setInterval('timecounter()',1000)" oncontextmenu="return false;">
<div id="loading-screen">
<div id="loader">
<img src="graphics/rooms/kitchen/teddy1.png">
</div>
</div>
<div id="game">
<div id="rooms">
<div id="room1" class="room">
<h1>Arbeitszimmer/Büro</h1>
<img id="item-desk1" src="graphics/rooms/office/desk.svg" draggable="false" style="position:absolute; top: 39vh; left: -5%; width:66.4%;">
<img id="item-apple1" src="graphics/rooms/office/apple.svg" draggable="false" onclick="toggleBackpack()" style="position:absolute; top: 80%; left: 45%; width:6.8%;">
<img id="item-officechair1" src="graphics/rooms/office/officechair.png" draggable="false" onclick="createNewWindow('Der Bürostuhl', 'zoom', 'graphics/rooms/office/officechair.png')" style="position:absolute; top: 50vh; left: 40%; width:16.426%;">
<img id="item-pocketligher1" src="graphics/rooms/office/pocketlighter.svg" draggable="false" onclick="toggleBackpack()" style="position:absolute; top: 51vh; left: 32%; width:4.5%; transform: rotate(-80deg);">
<img id="item-fruitbowlpicture1" src="graphics/rooms/office/fruitbowl-picture.png" draggable="false" style="position:absolute; top: 8vh; left: 30%; width: 18.2%;">
<img id="item-flower1" src="graphics/rooms/office/flower3.png" draggable="false" onclick="useItemfromBackpack('item-wateringcan1')" style="position:absolute; top: 62%; left: 80%; width: 13.63%;">
<img id="item-lightbulb1" src="graphics/rooms/office/lightbulb2.png" draggable="false" onclick="toggleBackpack()" style="position:absolute; top: 79%; left: 66%; width: 6.81%;">
<img id="item-map1" src="graphics/rooms/office/map2.svg" draggable="false" onclick="createNewWindow('Europa Karte', 'image', 'graphics/rooms/office/europe-map2.png')" style="position:absolute; top: 50%; left: 25%; width: 7.38%; transform: rotate(-6deg);">
<img id="item-letter1" src="graphics/rooms/office/letter.png" draggable="false" onclick="createNewWindow('Der Brief', 'image', 'graphics/rooms/office/letter-paper.png')" style="position:absolute; top: 56%; left: 18%; width: 7.38%; transform: rotate(0deg);">
</div>
<div id="room2" class="room">
<h1>Schlafzimmer</h1>
<img id="item-bed1" src="graphics/rooms/bedroom/bed.png" draggable="false" onclick="useItemfromBackpack('item-teddy1')" style="position:absolute; top: 55vh; left: 52%; width:38%;">
<img id="item-cabinet1" src="graphics/rooms/bedroom/cabinet2.svg" draggable="false" onclick="createNewWindow('Der alte Schrank', 'cabinet', 'graphics/rooms/bedroom/wateringcan.svg')" style="position:absolute; top: 32vh; left: -2%; width:18.18%;">
<img id="item-chair4" src="graphics/rooms/bedroom/chair.png" draggable="false" style="position:absolute; top: 40vh; left: 20%; width:19.8%; z-index: 80;">
<img id="item-tshirt1" src="graphics/rooms/bedroom/tshirt.png" draggable="false" onclick="removeItem()" style="position:absolute; top: 40vh; left: 20%; width:19.8%; z-index: 82;">
<img id="item-key1" src="graphics/rooms/bedroom/key.svg" draggable="false" onclick="toggleBackpack()" style="position:absolute; top: 53.5vh; left: 27%; width:8.522%; z-index: 81; transform: rotate(25deg);">
<img id="item-candle1" src="graphics/rooms/bedroom/candle2-off.svg" draggable="false" onclick="useItemfromBackpack('item-pocketligher1'); createNewWindow('Die rote Kerze', 'zoom')" style="position:absolute; top: 72vh; left: 76%; width:3.4%;">
<img id="item-lamp1" src="graphics/rooms/bedroom/lamp.png" draggable="false" style="position:absolute; top: 0vh; left: 30%; width:14.77%;">
<img id="item-fire1" src="graphics/rooms/bedroom/fire-extinguisher.svg" draggable="false" onclick="toggleBackpack(); useItemfromBackpack('item-fire1');" style="position:absolute; top: 59vh; left: 10%; width:9.09%;">
<img id="item-window1" src="graphics/rooms/bedroom/window1.png" draggable="false" style="position:absolute; top: 10%; left: 62%; width:15.9%; filter: opacity(95%) brightness(110%);">
</div>
<div id="room3" class="room">
<h1>Küche</h1>
<img id="item-oven1" src="graphics/rooms/kitchen/oven3.png" draggable="false" style="position:absolute; top: 41vh; left: 14%; width:20.45%;">
<img id="item-table1" src="graphics/rooms/kitchen/table.svg" draggable="false" style="position:absolute; top: 60vh; left: 55%; width:45.45%; z-index: 71;">
<img id="item-chair1" src="graphics/rooms/kitchen/chair.png" draggable="false" style="position:absolute; top: 68vh; left: 54%; width:12.5%; z-index: 69;">
<img id="item-chair2" src="graphics/rooms/kitchen/chair-qrcode.png" draggable="false" onclick="createNewWindow('Ein mysteriöser QR-Code', 'image', 'graphics/rooms/kitchen/Juneau-QRCode2.png')" style="position:absolute; top: 77vh; left: 64%; width:12.5%; z-index: 73;">
<img id="item-chair3" src="graphics/rooms/kitchen/chair.png" draggable="false" style="position:absolute; top: 77vh; left: 79%; width:12.5%; z-index: 72;">
<img id="item-teddy1" src="graphics/rooms/kitchen/teddy3.png" draggable="false" onclick="toggleBackpack(); document.getElementById('item-officechair1').src = 'graphics/rooms/office/officechair-teddy.png'; document.getElementById('item-teddy1').src = 'graphics/rooms/kitchen/teddy1.png';" style="position:absolute; top: 53vh; left: 56%; width:10.795%; z-index: 70;">
<img id="item-calendar1" src="graphics/rooms/kitchen/calendar.png" onclick="createNewWindow('Der Rätselkalender', 'calendarquiz', 'graphics/rooms/kitchen/calendar2.png')" draggable="false" style="position:absolute; top: 24vh; left: 72%; width:11.36%;">
<img id="item-fruitbowl1" src="graphics/rooms/kitchen/fruitbowl1.png" draggable="false" onclick="createNewWindow('Komische Buchstaben auf der Schüssel', 'zoom')" style="position:absolute; top: 59vh; left: 67%; width:9.09%; z-index: 75;">
<img id="item-radio1" src="graphics/rooms/kitchen/radio.png" draggable="false" onclick="playAudio('sounds/radio-quiz.mp3')" style="position:absolute; top: 52vh; left: 80%; width:7.95%; z-index: 74;">
<img id="item-window2" src="graphics/rooms/kitchen/window.svg" draggable="false" style="position:absolute; top: 6%; left: 35%; width:15.909%;">
<img id="item-pan1" src="graphics/rooms/kitchen/pan.png" draggable="false" onclick="createNewWindow('Die verbrannte Pfanne', 'image', 'graphics/rooms/kitchen/pan.png')" style="position:absolute; top: 35vh; left: 25%; width:9.659%; z-index: 76;">
<img id="item-fire2" src="graphics/rooms/kitchen/fire.svg" draggable="false" onclick="useItemfromBackpack('item-fire1')" style="position:absolute; top: 27%; left: 24.5%; width:9.09%; z-index: 77;">
</div>
<div id="room4" class="room">
<h1>Ausgang</h1>
<img id="item-door1" src="graphics/rooms/exit/door2-lock.png" draggable="false" onclick="useItemfromBackpack('item-key1')" style="position:absolute; top: 14.4vh; left: 26%; width:23.86%; z-index: 90;">
<img id="item-keypad1" src="graphics/rooms/exit/keypad.svg" draggable="false" onclick="createNewWindow('Der Code zur Freiheit!', 'keypad', 'graphics/rooms/exit/keypad.svg')" style="position:absolute; top: 43vh; left: 36%; width:4.545%; z-index: 91; display:none;">
<img id="item-lock1" src="graphics/rooms/exit/lock.svg" draggable="false" onclick="useItemfromBackpack('item-key1')" style="position:absolute; top: 47%; left: 43%; width:2.5%; z-index: 92; display:none;">
<img id="item-shoe1" src="graphics/rooms/exit/shoe1.svg" draggable="false" style="position:absolute; top: 62vh; left: 65%; width:6.81%; transform: scaleX(-1);">
<img id="item-shoe2" src="graphics/rooms/exit/shoe2.svg" draggable="false" onclick="toggleBackpack()" style="position:absolute; top: 63vh; left: 15%; width:9.09%;">
<img id="item-jacket1" src="graphics/rooms/exit/jacket.png" draggable="false" style="position:absolute; top: 25vh; left: 55%; width:13.636%;">
</div>
<div id="congrats" class="room">
<h1>Herzlich Gratulation, sie haben es geschafft meinen Escape Room zu lösen.</h1>
<p id="yourtime">Zeit: error</p>
<p id="highscore">Highscore: error</p>
<p id="hintcounter">Hinweise: error</p>
<img src="graphics/rooms/congrats/balloons.svg" draggable="false" style="position:absolute; top: 60vh; left: 75%; width:120px;">
<p>Wenn sie es nochmal versuchen wollen, um eine bessere Zeit aufzustellen, klicken sie unten auf den Reload Knopf. Bis nachher</p>
<button onclick="location.reload();">Nochmals spielen</button>
<h3>Michi</h3>
</div>
<div id="startscreen" class="room" style="display: block;">
<h1>Michi′s Escape Room</h1>
<img src="graphics/media/1.png" draggable="false">
<button onclick="playgame()" id="start-btn">Start</button>
<button onclick="createNewWindow('Anleitung', 'tutorial')">Anleitung</button>
<button onclick="createNewWindow('Quellen', 'sources')">Quellen</button>
<p style="font-size: 12px; position: absolute; bottom: 0; margin-left: 10px;">Version 1.2.4</p>
</div>
</div>
<div id="backpack">
<div id="lastRoom" class="backpack-btn" style="float:left;" onclick="lastRoom()">
<i class="fas fa-arrow-circle-left"></i>
</div>
<div id="backpack-content">
</div>
<div id="nextRoom" class="backpack-btn" style="float:right;" onclick="nextRoom()">
<i class="fas fa-arrow-circle-right"></i>
</div>
</div>
<div id="puzzleWindowContainer">
</div>
<div id="audioContainer" style="display:none;">
<audio id="audio-player"></audio>
<audio id="bg-music-player" src="sounds/background-music3.mp3" loop muted></audio>
</div>
<div id="controlButtons">
<button id="mute-btn" class="controlbutton" onclick="toggleMusic()"><i class="fas fa-volume-mute" id="mute-btn-i"></i></button>
<button id="help-btn" class="controlbutton" onclick="getHint()"><i class="fas fa-eye"></i></button>
</div>
</div>
<script>
// Loading
$(window).on("load", function(){
$("#loading-screen").fadeOut(750);
console.log("Page loaded.");
});
// keyboard
// next room key 39
// last room key 37
// hint key 40
// music key 38
// close window key 32
// add to backpack/add to room from backpack
function toggleBackpack(){ // funktioniert nur mit Bildern
var backpack = document.getElementById('backpack');
var item = event.target.id;
if(event.target.parentNode.id != "backpack"){
playAudio('sounds/click-sound2.mp3');
document.getElementById(item).style.position = "static";
backpack.appendChild(document.getElementById(item));
}
/*
else{
if(document.getElementById('room1').style.display == "block"){
var roomId = document.getElementById('room1');
}
else if(document.getElementById('room2').style.display == "block"){
var roomId = document.getElementById('room2');
}
else if(document.getElementById('room3').style.display == "block"){
var roomId = document.getElementById('room3');
}
document.getElementById(item).style.position = "absolute";
roomId.appendChild(document.getElementById(item));
}
*/
else{
// detect room
if(document.getElementById('room1').style.display == "block"){
var roomName = "room1";
}
else if(document.getElementById('room2').style.display == "block"){
var roomName = "room2";
}
else if(document.getElementById('room3').style.display == "block"){
var roomName = "room3";
}
else if(document.getElementById('room4').style.display == "block"){
var roomName = "room4";
}
else{
console.log("Error");
}
// use item
console.log("You are the item in backpack.")
if(item == "item-fire1"){
if(document.getElementById('item-fire2').parentNode.id == roomName){
playAudio('sounds/click-sound2.mp3');
document.getElementById(item).style.position = "absolute";
document.getElementById("room3").appendChild(document.getElementById(item));
document.getElementById('item-fire1').style.animation = "item-fire1 1s linear";
setTimeout(function(){
document.getElementById('item-fire1').remove();
document.getElementById('item-fire2').remove();
}, 1000);
//document.getElementById('room3').childNodes.includes('item-fire2')
}
}
else if(item == "item-pocketligher1"){
if(document.getElementById('item-candle1').parentNode.id == roomName){
playAudio('sounds/candle-sound1.mp3');
document.getElementById('item-candle1').src = "graphics/rooms/bedroom/candle2.png";
document.getElementById('item-pocketligher1').remove();
}
}
else if(item == "item-key1"){
if(roomName == "room4"){
playAudio('sounds/click-sound2.mp3');
document.getElementById('item-key1').remove(); //+ad event listener
document.getElementById('item-door1').src = "graphics/rooms/exit/door2.png";
document.getElementById('item-door1').addEventListener("click", function(){
createNewWindow('Der Code zur Freiheit!', 'keypad', 'graphics/rooms/exit/keypad.svg');
});
}
}
else if(item == "item-lightbulb1"){
if(roomName == "room2"){
playAudio('sounds/click-sound2.mp3');
document.getElementById('room2').style.filter = "brightness(100%)";
document.getElementById('item-lightbulb1').remove();
}
}
else if(item == "item-teddy1"){
if(document.getElementById('item-bed1').parentNode.id == roomName){
playAudio('sounds/click-sound2.mp3');
document.getElementById('item-bed1').src = "graphics/rooms/bedroom/bed-teddy.png";
document.getElementById('item-teddy1').remove();
document.getElementById('item-bed1').addEventListener("click", function(){
createNewWindow('das bezogene Bett', 'image', 'graphics/rooms/bedroom/bed-teddy-zoom.png');
});
}
}
else if(item == "item-wateringcan1"){
if(document.getElementById('item-flower1').parentNode.id == roomName){
playAudio('sounds/water-sound.mp3');
document.getElementById('item-flower1').src = "graphics/rooms/office/flower2.png";
document.getElementById('item-wateringcan1').remove();
}
}
else if(item == "item-apple1"){
if(roomName == "room3"){
playAudio('sounds/click-sound2.mp3');
document.getElementById('item-apple1').remove();
// get the correct fruitbowl image
if(sessionStorage.getItem('fruitbowlNumber') == "1"){
createNewWindow('Komische Buchstaben auf der Schüssel', 'image', 'graphics/rooms/kitchen/fruitbowl1.png');
}
else if(sessionStorage.getItem('fruitbowlNumber') == "2"){
createNewWindow('Komische Buchstaben auf der Schüssel', 'image', 'graphics/rooms/kitchen/fruitbowl2.png');
}
else if(sessionStorage.getItem('fruitbowlNumber') == "3"){
createNewWindow('Komische Buchstaben auf der Schüssel', 'image', 'graphics/rooms/kitchen/fruitbowl3.png');
}
else if(sessionStorage.getItem('fruitbowlNumber') == "4"){
createNewWindow('Komische Buchstaben auf der Schüssel', 'image', 'graphics/rooms/kitchen/fruitbowl4.png');
}
}
}
}
console.log(item + " added to " + event.target.parentNode.id);
}
// change room
function nextRoom(){ // go to the next room
var numberOfRooms = 4;
if(document.getElementById('room1').style.display == "block"){
var room = 1;
}
else if(document.getElementById('room2').style.display == "block"){
var room = 2;
}
else if(document.getElementById('room3').style.display == "block"){
var room = 3;
}
else if(document.getElementById('room4').style.display == "block"){
var room = 4;
}
else{
console.log("Error");
}
if(room == numberOfRooms){ // wenn Room gleich wie Anzahl Räume
var room = 1;
}
else{
room++
}
var roomName = "room" + room;
document.getElementById("room1").style.display = "none";
document.getElementById("room2").style.display = "none";
document.getElementById("room3").style.display = "none";
document.getElementById("room4").style.display = "none";
document.getElementById(roomName).style.display = "block";
playAudio('sounds/click-sound2.mp3');
console.log(roomName + " opened.");
document.getElementById('puzzleWindowContainer').innerHTML = '';
}
function lastRoom(){ // go to the last room
var numberOfRooms = 4;
if(document.getElementById('room1').style.display == "block"){
var room = 1;
}
else if(document.getElementById('room2').style.display == "block"){
var room = 2;
}
else if(document.getElementById('room3').style.display == "block"){
var room = 3;
}
else if(document.getElementById('room4').style.display == "block"){
var room = 4;
}
else{
console.log("Error");
}
if(room == 1){ // wenn Room gleich wie Anzahl Räume
var room = numberOfRooms;
}
else{
room--
}
var roomName = "room" + room;
document.getElementById("room1").style.display = "none";
document.getElementById("room2").style.display = "none";
document.getElementById("room3").style.display = "none";
document.getElementById("room4").style.display = "none";
document.getElementById(roomName).style.display = "block";
playAudio('sounds/click-sound2.mp3');
console.log(roomName + " opened.");
document.getElementById('puzzleWindowContainer').innerHTML = '';
}
function createNewWindow(title, windowtype, content){
if(document.getElementsByClassName('closeWindowBtn')[0] == null){
playAudio('sounds/click-sound2.mp3');
var newWindow = document.createElement('div');
newWindow.className = "puzzleWindow";
var newtitle = document.createElement('h1');
newtitle.textContent = title;
var newCloseBtn = document.createElement('i');
newCloseBtn.className = "fas fa-times-circle closeWindowBtn";
newWindow.appendChild(newtitle);
newWindow.appendChild(newCloseBtn);
if(windowtype == "image"){
if(event.target.id == "item-pan1"){
var newImage = document.createElement('img');
newImage.src = content;
newImage.draggable = false;
newWindow.appendChild(newImage);
}
else{
var newImage = document.createElement('img');
newImage.src = content;
newImage.draggable = false;
newWindow.appendChild(newImage);
}
}
else if(windowtype == "zoom"){
var clickedItem = document.getElementById(event.target.id);
var newImage = document.createElement('img');
newImage.src = clickedItem.src;
newImage.draggable = false;
newWindow.appendChild(newImage);
}
else if(windowtype == "hint"){
var newText = document.createElement('p');
newText.textContent = content;
newText.style.fontSize = "24px";
newWindow.appendChild(newText);
}
else if(windowtype == "calendarquiz"){
var newImage = document.createElement('img');
var newInput = document.createElement('input');
var newButton = document.createElement('button');
if(sessionStorage.getItem('calendar1') == 1){
newImage.src = "graphics/rooms/kitchen/calendar-correct.png";
}
else{
newImage.src = content;
}
newImage.draggable = false;
newImage.style.height = "40vw";
newInput.type = "text";
newInput.placeholder = "Was ist die Hauptstadt von Alaska?";
newInput.id = "calendarInput";
newInput.addEventListener("keyup", function(){
$(newInput).on("keyup", function(e){
if(e.keyCode == 13){
//playAudio('sounds/click-sound2.mp3');
if(newInput.value.toUpperCase().includes('JUNEAU')){
console.log('Answer ' + newInput.value + ' is correct!')
newInput.value = "";
newImage.src = "graphics/rooms/kitchen/calendar-correct.png";
sessionStorage.setItem('calendar1', 1);
}
else{
console.log('Answer ' + newInput.value + ' is incorrect!')
newInput.value = "";
}
}
});
});
newButton.textContent = "✔️";
newButton.addEventListener("click", function(){
playAudio('sounds/click-sound2.mp3');
if(newInput.value.toUpperCase().includes('JUNEAU')){
console.log('Answer ' + newInput.value + ' is correct!')
newInput.value = "";
newImage.src = "graphics/rooms/kitchen/calendar-correct.png";
sessionStorage.setItem('calendar1', 1);
}
else{
console.log('Answer ' + newInput.value + ' is incorrect!')
newInput.value = "";
}
});
newWindow.appendChild(newImage);
newWindow.appendChild(newInput);
newWindow.appendChild(newButton);
}
else if(windowtype == "keypad"){
var newImage = document.createElement('img');
newImage.src = content;
newImage.style.height = "40vw";
var newInput1 = document.createElement('input');
newInput1.type = "numbers";
newInput1.required = true;
newInput1.maxLength = "1";
newInput1.placeholder = "0";
newInput1.id = "newInput1";
newInput1.value = sessionStorage.getItem('yourInput1');
newInput1.addEventListener("keyup", function(){
if(newInput1.value.length == '1'){
newInput2.focus();
}
console.log("Go to next input field.");
});
var newInput2 = document.createElement('input');
newInput2.type = "numbers";
newInput2.required = true;
newInput2.maxLength = "1";
newInput2.placeholder = "0";
newInput2.id = "newInput2";
newInput2.value = sessionStorage.getItem('yourInput2');
newInput2.addEventListener("keyup", function(){
if(newInput2.value.length == '1'){
newInput3.focus();
}
console.log("Go to next input field.");
});
var newInput3 = document.createElement('input');
newInput3.type = "numbers";
newInput3.required = true;
newInput3.maxLength = "1";
newInput3.placeholder = "0";
newInput3.id = "newInput3";
newInput3.value = sessionStorage.getItem('yourInput3');
newInput3.addEventListener("keyup", function(){
if(newInput3.value.length == '1'){
newInput4.focus();
}
console.log("Go to next input field.");
});
var newInput4 = document.createElement('input');
newInput4.type = "numbers";
newInput4.required = true;
newInput4.maxLength = "1";
newInput4.placeholder = "0";
newInput4.id = "newInput4";
newInput4.value = sessionStorage.getItem('yourInput4');
newInput4.addEventListener("keyup", function(){
if(newInput4.value.length == '1'){
newInput5.focus();
}
console.log("Go to next input field.");
});
var newInput5 = document.createElement('input');
newInput5.type = "numbers";
newInput5.required = true;
newInput5.maxLength = "1";
newInput5.placeholder = "0";
newInput5.id = "newInput5";
newInput5.value = sessionStorage.getItem('yourInput5');
newInput5.addEventListener("keyup", function(){
if(newInput5.value.length == '1'){
newInput6.focus();
}
console.log("Go to next input field.");
});
var newInput6 = document.createElement('input');
newInput6.type = "numbers";
newInput6.required = true;
newInput6.maxLength = "1";
newInput6.placeholder = "0";
newInput6.id = "newInput6";
newInput6.value = sessionStorage.getItem('yourInput6');
newInput6.addEventListener("keyup", function(){
if(newInput6.value.length == '1'){
newInput7.focus();
}
console.log("Go to next input field.");
});
var newInput7 = document.createElement('input');
newInput7.type = "numbers";
newInput7.required = true;
newInput7.maxLength = "1";
newInput7.placeholder = "0";
newInput7.id = "newInput7";
newInput7.value = sessionStorage.getItem('yourInput7');
newInput7.addEventListener("keyup", function(){
if(newInput7.value.length == '1'){
newButton.focus();
}
console.log("Go to next input field.");
});
var newButton = document.createElement('button');
newButton.textContent = "✔️";
newButton.addEventListener("click", function(){
playAudio('sounds/click-sound2.mp3');
// get correct code
if(sessionStorage.getItem('fruitbowlNumber') == "1"){
var code1 = "1596742";
var code2 = "1597642";
}
else if(sessionStorage.getItem('fruitbowlNumber') == "2"){
var code1 = "2467951";
var code2 = "2476951";
}
else if(sessionStorage.getItem('fruitbowlNumber') == "3"){
var code1 = "1267549";
var code2 = "1276549";
}
else if(sessionStorage.getItem('fruitbowlNumber') == "4"){
var code1 = "6751249";
var code2 = "7651249";
}
// check with your code
var yourCode = newInput1.value.toString() + newInput2.value.toString() + newInput3.value.toString() + newInput4.value.toString() + newInput5.value.toString() + newInput6.value.toString() + newInput7.value.toString();
if(yourCode.toUpperCase().includes(code1) || yourCode.toUpperCase().includes(code2)){
console.log('Answer ' + newInput1.value + ' is correct!')
newInput1.value = "";
newInput2.value = "";
newInput3.value = "";
newInput4.value = "";
newInput5.value = "";
newInput6.value = "";
newInput7.value = "";
//newImage.src = "graphics/rooms/kitchen/calendar-correct.png";
// get score
sessionStorage.setItem('yourTime', sessionStorage.getItem('time'));
if(localStorage.getItem('highscore') == null){
localStorage.setItem('highscore', sessionStorage.getItem('yourTime'));
console.log('Saved new highscore.')
}
if(localStorage.getItem('highscore') >= sessionStorage.getItem('yourTime')){
localStorage.setItem('highscore', sessionStorage.getItem('yourTime'));
console.log('New highscore set to ' + localStorage.getItem('highscore'));
}
else{
console.log('You not reached a new highscore.')
}
// show your score
var showTime1 = sessionStorage.getItem('yourTime') / 60;
var showTimeMin = Math.floor(showTime1);
var showTimeSec1 = showTime1.toFixed(2) - showTimeMin;
var showTimeSec = showTimeSec1 * 60;
// show your highscore
var showHighscore1 = localStorage.getItem('highscore') / 60;
var showHighscoreMin = Math.floor(showHighscore1);
var showHighscoreSec1 = showHighscore1.toFixed(2) - showHighscoreMin;
var showHighscoreSec = showHighscoreSec1 * 60;
document.getElementById('yourtime').textContent = 'Zeit: ' + showTimeMin + ':' + showTimeSec.toFixed(0) + 'Min';
document.getElementById('highscore').textContent = 'Highscore: ' + showHighscoreMin + ':' + showHighscoreSec.toFixed(0) + 'Min';
document.getElementById('hintcounter').textContent = 'benutze Hinweise: ' + sessionStorage.getItem('hints');
// end game
document.getElementById('room4').style.display = "none";
document.getElementById('backpack').style.display = "none";
document.getElementById('controlButtons').style.display = "none";
document.getElementsByClassName('puzzleWindow')[0].remove();
document.getElementById('bg-music-player').src = "sounds/background-music1.mp3";
document.getElementById('bg-music-player').muted = false;
document.getElementById('bg-music-player').play();
document.getElementById('congrats').style.display = "block";
// THE END
}
else{
console.log('Answer ' + yourCode + ' is incorrect!')
newInput1.value = "";
newInput2.value = "";
newInput3.value = "";
newInput4.value = "";
newInput5.value = "";
newInput6.value = "";
newInput7.value = "";
}
});
//newWindow.appendChild(newImage);
var newTextarea = document.createElement('textarea');
newTextarea.placeholder = "Hier haben sie Platz für Notizen...";
newTextarea.textContent = sessionStorage.getItem('yourTextarea');
newTextarea.id = "yourTextarea";
newWindow.appendChild(newInput1);
newWindow.appendChild(newInput2);
newWindow.appendChild(newInput3);
newWindow.appendChild(newInput4);
newWindow.appendChild(newInput5);
newWindow.appendChild(newInput6);
newWindow.appendChild(newInput7);
newWindow.appendChild(newButton);
newWindow.appendChild(newTextarea);
}
else if(windowtype == "cabinet"){
playAudio('sounds/door-sound2.mp3');
var newImage = document.createElement('img');
newImage.src = "graphics/rooms/bedroom/cabinet-open2.png";
newWindow.appendChild(newImage);
if(sessionStorage.getItem('wateringcan') == 0){
var newItem = document.createElement('img');
newItem.src = "graphics/rooms/bedroom/wateringcan.svg";
newItem.id = "item-wateringcan1";
newItem.draggable = false;
newItem.style.position = "absolute";
newItem.style.top = "55%";
newItem.style.left = "32%";
newItem.style.width = "17%";
newItem.addEventListener("click", function(){
toggleBackpack();
sessionStorage.setItem('wateringcan', 1);
});
newWindow.appendChild(newItem);
}
// <img id="item-teddy1" src="graphics/rooms/kitchen/teddy3.png" draggable="false" onclick="toggleBackpack()" style="position:absolute; top: 53vh; left: 56%; width:95px; z-index: 70;">
}
else if(windowtype == "sources"){
var newText = document.createElement('p');
newText.style.textAlign = "justify";
newText.style.margin = "5px";
newText.textContent = "Alle Grafiken der Gegenstände sind von Pixabay. Einige der Grafiken habe ich vor der Verwendung in meinem Projekt bearbeitet, damit sie zum Inhalt passen. Die Räume im Hintergrund und alle Sounds habe ich selbst gemacht. Die Hintergrundmusik ist auch von Pixabay. Das Logo wurde mit Canva erstellt.";
newWindow.appendChild(newText);
var newImage = document.createElement('img');
newImage.src = "https://pixabay.com/static/img/public/medium_rectangle_b.png";
newImage.style.width = "200px";
newImage.style.borderRadius = "8px";
newImage.draggable = false;
newWindow.appendChild(newImage);
newWindow.style.padding = "5px";
newWindow.style.paddingRight = "0";
newWindow.style.background = "#e67e22";
newWindow.style.color = "#fff";
newWindow.style.border = "8px solid #fff";
}
else if(windowtype == "tutorial"){
var newText = document.createElement('p');
newText.textContent = "Sie müssen das Gebäude möglichst schnell verlassen. Mit den Pfeilen unten links und rechts können sie zwischen den Räumen hin und her wechseln. Durch anklicken einiger Gegenständen, können sie mit ihnen interagieren oder sie einsammeln. Sie müssen den siebenstelligen geheimen Zahlencode herausfinden und am Schluss bei der Tür eingeben. Die Zahlen sind versteckt halten sie also Ihre Augen gut offen. Geschafft? Sie sehen am Schluss wie lange sie hatten und können es erneut versuchen um Ihre Zeit zu verbessern.";
newWindow.appendChild(newText);
newWindow.style.background = "#e67e22";
newWindow.style.color = "#fff";
newWindow.style.border = "8px solid #fff";
}
document.getElementById("puzzleWindowContainer").appendChild(newWindow);
// add event listener
if(windowtype == "keypad"){
newCloseBtn.addEventListener("click", function(){
playAudio('sounds/click-sound2.mp3');
sessionStorage.setItem('yourInput1', document.getElementById('newInput1').value);
sessionStorage.setItem('yourInput2', document.getElementById('newInput2').value);
sessionStorage.setItem('yourInput3', document.getElementById('newInput3').value);
sessionStorage.setItem('yourInput4', document.getElementById('newInput4').value);
sessionStorage.setItem('yourInput5', document.getElementById('newInput5').value);
sessionStorage.setItem('yourInput6', document.getElementById('newInput6').value);
sessionStorage.setItem('yourInput7', document.getElementById('newInput7').value);
sessionStorage.setItem('yourTextarea', document.getElementById('yourTextarea').value);
document.getElementsByClassName('puzzleWindow')[0].style.display = "none";
document.getElementsByClassName('puzzleWindow')[0].remove();
console.log("Window removed.");
});
}
else{
newCloseBtn.addEventListener("click", function(){
playAudio('sounds/click-sound2.mp3');
document.getElementsByClassName('puzzleWindow')[0].style.display = "none";
document.getElementsByClassName('puzzleWindow')[0].remove();
console.log("Window removed.");
});
}
console.log("New window with title " + title + " created.");
}
console.log("Close the open window, before you can open another.")
}
function removeItem(){
playAudio('sounds/click-sound2.mp3');
var item = event.target.id;
document.getElementById(item).remove();
console.log(item + " removed.");
}
function playAudio(source){
var bgPlayer = document.getElementById('bg-music-player');
var audioplayer = document.getElementById('audio-player');
var item = event.target.id;
//document.getElementById(item).remove();
audioplayer.src = source;
audioplayer.play();
console.log(item + " started to play the audio: " + source);
}
function useItemfromBackpack(backpackitem1){
var backpackitem2 = document.getElementById(backpackitem1);
var item = event.target.id;
if(backpackitem2.parentNode.id == "backpack"){
playAudio('sounds/click-sound2.mp3');
console.log("The item you need is in the backpack.")
if(item == "item-fire2"){
document.getElementById('item-fire1').remove();
document.getElementById('item-fire2').remove();
}
else if(item == "item-candle1"){
playAudio('sounds/candle-sound1.mp3');
document.getElementById('item-candle1').src = "graphics/rooms/bedroom/candle2.png";
document.getElementById('item-pocketligher1').remove();
}
else if(item == "item-door1"){
//document.getElementById('item-lock1').remove();
document.getElementById('item-key1').remove(); //+ad event listener
document.getElementById('item-door1').src = "graphics/rooms/exit/door2.png";
document.getElementById('item-door1').addEventListener("click", function(){
createNewWindow('Der Code zur Freiheit!', 'keypad', 'graphics/rooms/exit/keypad.svg');
});
}
else if(item == "item-lamp1"){
document.getElementById("room2").style.filter = "brightness(100%)";
document.getElementById('item-lightbulb1').remove();
}
else if(item == "item-bed1"){
document.getElementById('item-bed1').src = "graphics/rooms/bedroom/bed-teddy.png";
document.getElementById('item-teddy1').remove();
document.getElementById('item-bed1').addEventListener("click", function(){
createNewWindow('das bezogene Bett', 'image', 'graphics/rooms/bedroom/bed-teddy-zoom.png')
});
}
else if(item == "item-flower1"){
playAudio('sounds/water-sound.mp3');
document.getElementById('item-flower1').src = "graphics/rooms/office/flower2.png";
document.getElementById('item-wateringcan1').remove();
}
}
else{
console.log('You need to have ' + backpackitem1 + ' in your backpack to operate with ' + item + '.');
}
}
function toggleMusic(type){
// types: toggle, on, off
var bgMusicPlayer = document.getElementById('bg-music-player');
if(bgMusicPlayer.muted == true){
document.getElementById('bg-music-player').play();
bgMusicPlayer.muted = false;
document.getElementById('mute-btn-i').className = "fas fa-volume-up";
}
else{
bgMusicPlayer.muted = true;
document.getElementById('mute-btn-i').className = "fas fa-volume-mute";
}
if(type == 'on'){
document.getElementById('bg-music-player').play();
bgMusicPlayer.muted = false;
document.getElementById('mute-btn-i').className = "fas fa-volume-up";
}
else if(type == 'off'){
bgMusicPlayer.muted = true;
document.getElementById('mute-btn-i').className = "fas fa-volume-mute";
}
}
function playgame(){
document.getElementById("room1").style.display = "block";
document.getElementById("room2").style.display = "none";
document.getElementById("room3").style.display = "none";
document.getElementById("room4").style.display = "none";
document.getElementById("startscreen").style.display = "none";
document.getElementById("congrats").style.display = "none";
document.getElementById("backpack").style.display = "block";
document.getElementById('controlButtons').style.display = "block";
document.getElementById('help-btn').style.display = "block";
document.getElementById('bg-music-player').src = "sounds/background-music3.mp3";
document.getElementById('bg-music-player').play();
toggleMusic('on');
sessionStorage.setItem('time', 0);
sessionStorage.setItem('hints', 0);
sessionStorage.setItem('wateringcan', 0);
sessionStorage.setItem('calendar1', 0);
sessionStorage.removeItem('yourInput1');
sessionStorage.removeItem('yourInput2');
sessionStorage.removeItem('yourInput3');
sessionStorage.removeItem('yourInput4');
sessionStorage.removeItem('yourInput5');
sessionStorage.removeItem('yourInput6');
sessionStorage.removeItem('yourInput7');
sessionStorage.removeItem('yourTextarea');
var fruitbowl = document.getElementById('item-fruitbowl1');
var fruitbowlNumber = Math.round(Math.random() * (4 - 1)) + 1;
sessionStorage.setItem('fruitbowlNumber', fruitbowlNumber);
fruitbowl.src = "graphics/rooms/kitchen/fruitbowl" + fruitbowlNumber + ".png";
}
function timecounter(){
var time = sessionStorage.getItem('time');
time++;
sessionStorage.setItem('time', time);
}
function getHint(){
var hintCounter = sessionStorage.getItem('hints');
hintCounter++;
sessionStorage.setItem('hints', hintCounter);
//var randomNumber = Math.round(Math.random() * (10 - 1)) + 1;
var randomNumber = hintCounter;
if(sessionStorage.getItem('hints') >= 14){
var randomNumber = randomNumber - 13;
}
if(sessionStorage.getItem('hints') >= 27){
var randomNumber = 0;
sessionStorage.setItem('hints', 27);
}
var hintName = 'Hinweis ' + randomNumber + '/13';
if(randomNumber == "0"){
createNewWindow('Hinweise aufgebraucht!', 'hint', 'Sie haben alle Hinweise aufgebraucht und können ab jetzt keine mehr ansehen.');
}
else if(randomNumber == "1"){
createNewWindow(hintName, 'hint', 'Schau dich gut um!');
}
else if(randomNumber == "2"){
createNewWindow(hintName, 'hint', 'Kannst du Licht ins Dunkle bringen?');
}
else if(randomNumber == "3"){
createNewWindow(hintName, 'hint', 'Wo ist der geheime Schlüssel versteckt?');
}
else if(randomNumber == "4"){
createNewWindow(hintName, 'hint', 'Hast du das Feuer bereits gelöscht? Geht es der Pfanne noch gut?');
}
else if(randomNumber == "5"){
createNewWindow(hintName, 'hint', 'Auf der Europa Karte wurden Orte mit Zahlen markiert.');
}
else if(randomNumber == "6"){
createNewWindow(hintName, 'hint', 'Gehört der Teddy wirklich auf den Stuhl? Sollte er nicht woanders hin?');
}
else if(randomNumber == "7"){
createNewWindow(hintName, 'hint', 'Welche Bedeutung haben die Wörter im Radio? Möglicherweise etwas mit den Anfangsbuchstaben?');
}
else if(randomNumber == "8"){
createNewWindow(hintName, 'hint', 'Für was brauchst du denn eine Giesskanne im Haus? Auf dem Boden wachsen doch keine Blumen.');
}
else if(randomNumber == "9"){
createNewWindow(hintName, 'hint', 'Die Schuhe dienen nur zur Dekoration.');
}
else if(randomNumber == "10"){
createNewWindow(hintName, 'hint', 'Im QR-Code findest du die Lösung für das Rätsel beim Kalender.');
}
else if(randomNumber == "11"){
createNewWindow(hintName, 'hint', 'Was haben die Buchstaben an der Wand zu bedeuten? Vielleicht eine Zahl?');
}
else if(randomNumber == "12"){
createNewWindow(hintName, 'hint', 'Das Wort an der Wand (SHRAS) kann mit der Geheimschrift auf dem Pult entschlüsselt werden. Dadurch erhalten Sie eine der sieben Zahlen.');
}
else if(randomNumber == "13"){
createNewWindow(hintName, 'hint', 'Haben die Buchstaben auf der Schüssel etwas mit der Reihenfolge des Codes zu tun?');
}
}
</script>
</body>
</html>