-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.mjs
179 lines (104 loc) · 3.46 KB
/
main.mjs
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
document.addEventListener("DOMContentLoaded", function() {
const firstContainer = document.querySelector('.firstContainer');
firstSubmit.addEventListener("click", moveNext);
document.addEventListener('keydown', handleKeyPress);
function handleKeyPress(event) {
if (event.key === 'Enter') {
moveNext();
}
}
});
//containers etc
const magnifier = document.querySelector('.magnifier')
magnifier.addEventListener('click', timeOutText);
const area = document.querySelector('.area');
const textContainer = document.querySelector('.textContainer');
//textContainer.classList.add("textContainer");
const text = document.querySelector('.text');
const bell = document.querySelector('.bell');
const compass = document.querySelector('.compass')
compass.addEventListener('click', showCompassText);
let compassText = document.querySelector('.compassText')
const quill = document.querySelector('.quill');
quill.addEventListener('click', inputQuill);
const firstInput = document.querySelector("#firstInput");
//firstInput.type = "text";
//const value = firstInput.value;
firstInput.className = "firstInput"; // set the CSS class//same as classList.add? it works
const firstSubmit = document.createElement("button");
firstSubmit.type = "submit";
firstSubmit.textContent = "Enter"
firstSubmit.className="firstSubmit";
//Audios
const windAudio = new Audio('./resurssit/sound/wind.mp3');
windAudio.loop = true;
const bellAudio = new Audio('./resurssit/sound/belltolls.wav');
bellAudio.loop = false;
bell.addEventListener('click', playBell);
//Buttons
//const soundButton = document.createElement('button');
//soundButton.classList.add("soundButton");
//firstContainer.appendChild(soundButton);
//soundButton.innerHTML ="Sound";
const soundButton = document.querySelector('.soundButton');
soundButton.addEventListener('click', soundOn );
//counters
let puzzleCount = 2;
const puzzleCounter = document.querySelector('.puzzleCounter');
puzzleCounter.innerHTML = puzzleCount;
//simple funcs
function soundOn() {
windAudio.play();
}
function timeOutText() {
setTimeout(() => {
area.style.display = 'flex';
}, 1000);
setTimeout(() => {
text.innerHTML= "Once there was a great mystery." ;
}, 3500);
setTimeout(() => {
text.innerHTML="..." ;
}, 6000);
}
function playBell() {
bellAudio.play();
}
function showCompassText() {
compassText.innerHTML="Up, up to the cold place my way goes... "
setTimeout(() => {
compassText.innerHTML="";
}, 3000);
}
function inputQuill(){
firstInput.style.display= "block";
//textContainer.appendChild(firstInput);
textContainer.appendChild(firstSubmit);
checkPuzzles();
text.innerHTML= "Give me two words." ;
}
function moveNext() {
const value = document.querySelector('#firstInput').value;
const lowercasedValue = value.toLowerCase();
if(lowercasedValue.includes("three north") || lowercasedValue.includes("north three")){ //works also the three norths
text.innerHTML="Correct." ;
bellAudio.play();
checkPuzzles();
firstInput.value = "";
setTimeout(() => {
window.location.href = 'second.html';
return false;
}, 2000);
}
else{
text.innerHTML="...no." ;
firstInput.value = "";
setTimeout(() => {
text.innerHTML="..." ;
}, 1000)
}
}
function checkPuzzles() {
puzzleCount --;
puzzleCounter.innerHTML = puzzleCount;
}