-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevelB.html
More file actions
463 lines (371 loc) · 16 KB
/
levelB.html
File metadata and controls
463 lines (371 loc) · 16 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fun Thinker Game</title>
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center; /* Pusatkan secara vertikal */
align-items: center; /* Pusatkan secara horizontal */
background: url('spacebackground.png') no-repeat center center;
background-size: cover;
overflow: hidden;
}
.game-container {
display: flex;
width: 500px;
height: 300px;
gap:53px;
background-repeat: no-repeat;
background-size: cover; /* Atau gunakan contain */
background-size: 100% 100%;
background-position: center;
}
.grid {
display: grid;
grid-template-columns: repeat(4, 42px);
grid-template-rows: repeat(4, 42px);
gap: 2px;
position: relative;
transform: translateY(100px)translateX(55px); /* Geser gambar ke atas */
}
.grid div {
width: 40px;
height: 40px;
border: 1px solid black;
display: flex;
justify-content: center;
align-items: center;
font-size: 16px;
font-weight: bold;
cursor: pointer;
position: relative;
}
.red {
width: 100px;
height: 100px;
border: 1px solid black;
display: inline-block;
background-size: cover;
background-position: center;
}
#neutral1, #neutral2, #neutral5, #neutral6 {
background-color: rgba(255, 0, 0, 0.5); /* merah transparan */
}
/* Neutral 5–8 biru */
#neutral11, #neutral12, #neutral15, #neutral16 {
background-color: rgba(0, 0, 255, 0.5); /* biru transparan */
}
/* Neutral 9–12 kuning */
#neutral9, #neutral10, #neutral13, #neutral14 {
background-color: rgba(255, 255, 0, 0.5); /* kuning transparan */
}
/* Neutral 13–16 hijau */
#neutral3, #neutral4, #neutral7, #neutral8 {
background-color: rgba(0, 128, 0, 0.5); /* hijau transparan */
}
.dragging {
opacity: 0.5;
}
#show-score-btn {
background-image: url('score button.png');
background-size: cover;
background-repeat: no-repeat;
width: 80px;
height: 22px;
border: none;
cursor: pointer;
background-size: 100% 100%;
background-color: transparent;
transition: transform 0.3s ease;
transform: translateX(7px);
position: absolute;
top: 20px;
left: 18px;
}
#show-score-btn:hover {
transform: translateX(7px) scale(0.9); /* Zoom out dengan scale */
}
#toggleAudioImg {
position: fixed; /* Tetap di tempat saat scroll */
top: 10px;
left: -10px;
width: 30px; /* Ukuran gambar */
cursor: pointer;
transition: transform 0.3s ease;
transform: translate(55px, 70px); /* Perbaikan sintaks */
max-width: 100%;
}
#toggleAudioImg:hover {
transform: translate(55px, 70px) scale(0.9); /* Efek hover tetap mempertahankan posisi */
}
/* Styling tambahan untuk body */
body {
margin: 0;
height: 100vh;
overflow: hidden; /* Mencegah scroll jika tidak diperlukan */
}
.toggleNextImg2 {
position: fixed; /* Tetap di tempat saat scroll */
top: 50px;
left: 25px;
width: 70px;
cursor: pointer;
transition: transform 0.3s ease;
max-width: 100%;
}
.toggleNextImg2:hover {
transform: scale(0.9);
}
/* Styling tambahan untuk body */
body {
margin: 0;
height: 100vh;
overflow: hidden; /* Mencegah scroll jika tidak diperlukan */
}
.toggleNextImg3 {
position: fixed; /* Tetap di tempat saat scroll */
top: 120px;
left: 45px;
width: 28px;
cursor: pointer;
transition: transform 0.3s ease;
max-width: 100%;
}
.toggleNextImg3:hover {
transform: scale(0.9);
}
/* Styling tambahan untuk body */
body {
margin: 0;
height: 100vh;
overflow: hidden; /* Mencegah scroll jika tidak diperlukan */
}
/* Popup image styling */
#popup_2 {
position: fixed; /* Tetap di posisi layar */
top: 50%; /* Posisi vertikal tengah */
left: 50%; /* Posisi horizontal tengah */
transform: translate(-50%, -50%); /* Pusatkan */
max-width: 300px; /* Ukuran maksimal */
max-height: 300px;
display: none; /* Awalnya disembunyikan */
z-index: 9999; /* Paling depan */
}
</style>
</head>
<body>
<img id="popup_2" src="popup/popup2.png">
<a href="tugasB/contohB.html">
<img id="toggleNextImg3" src="contoh.png" class="toggleNextImg3">
<a href="levelC.html">
<img id="toggleNextImg2" src="next button.png" class="toggleNextImg2">
</a>
<img id="toggleAudioImg" src="sound button.png" alt="Play Audio">
<audio id="audio" loop>
<source src="sound/backsound01.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
<button id="show-score-btn"></button>
<div class="game-container" style="background-image: url('level 1/papan2D.png'); background-repeat: no-repeat; padding: 10px;">
<div class="grid" id="leftGrid">
<div class="red" id="red1" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral1" ondragstart="drag(event)">1</div>
</div>
<div class="red" id="red2" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral2" ondragstart="drag(event)">2</div>
</div>
<div class="red" id="red3" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral3" ondragstart="drag(event)">3</div>
</div>
<div class="red" id="red4" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral4" ondragstart="drag(event)">4</div>
</div>
<div class="red" id="red5" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral5" ondragstart="drag(event)">5</div>
</div>
<div class="red" id="red6" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral6" ondragstart="drag(event)">6</div>
</div>
<div class="red" id="red7" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral7" ondragstart="drag(event)">7</div>
</div>
<div class="red" id="red8" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral8" ondragstart="drag(event)">8</div>
</div>
<div class="red" id="red9" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral9" ondragstart="drag(event)">9</div>
</div>
<div class="red" id="red10" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral10" ondragstart="drag(event)">10</div>
</div>
<div class="red" id="red11" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral11" ondragstart="drag(event)">11</div>
</div>
<div class="red" id="red12" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral12" ondragstart="drag(event)">12</div>
</div>
<div class="red" id="red13" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral13" ondragstart="drag(event)">13</div>
</div>
<div class="red" id="red14" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral14" ondragstart="drag(event)">14</div>
</div>
<div class="red" id="red15" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral15" ondragstart="drag(event)">15</div>
</div>
<div class="red" id="red16" ondrop="drop(event)" ondragover="allowDrop(event)">
<div class="neutral" draggable="true" id="neutral16" ondragstart="drag(event)">16</div>
</div>
</div>
<div class="game-container">
<!-- Left Grid -->
<div class="grid" id="rightGrid">
<div class="red" id="red17" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red18" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red19" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red20" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red21" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red22" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red23" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red24" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red25" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red26" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red27" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red28" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red29" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red30" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red31" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<div class="red" id="red32" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
</div>
<script>
// Audio Toggle
const audio = document.getElementById('audio');
const buttonImg = document.getElementById('toggleAudioImg');
function toggleAudio() {
if (audio.paused) {
audio.play().then(() => {
buttonImg.src = "sound button.png"; // Ganti gambar saat audio diputar
}).catch((error) => {
console.error("Audio playback failed:", error);
});
} else {
audio.pause();
buttonImg.src = "sound button.png"; // Ganti gambar saat audio dihentikan
}
}
buttonImg.addEventListener('click', toggleAudio);
let score = 0; // Variabel untuk menyimpan skor
function updateScore(points) {
score += points; // Tambahkan poin ke skor
}
function allowDrop(event) {
event.preventDefault();
}
let draggedElement = null;
function drag(event) {
draggedElement = event.target;
}
let popupShown = false; // biar popup cuma sekali muncul
function drop(event) {
event.preventDefault();
const target = event.target;
if (target.classList.contains("red") && target.childElementCount === 0) {
target.appendChild(draggedElement);
// Cek apakah semua red 17–32 terisi
if (!popupShown && checkAllFilled()) {
showPopup("popup/popup2.png");
popupShown = true; // supaya popup nggak muncul lagi
}
}
draggedElement = null;
}
// Fungsi untuk cek semua kotak red 17–32 terisi
function checkAllFilled() {
for (let i = 17; i <= 32; i++) {
const redBox = document.getElementById(`red${i}`);
if (!redBox || redBox.childElementCount === 0) {
return false; // ada yang kosong
}
}
return true; // semua terisi
}
function showPopup(imageSrc) {
const popup = document.getElementById("popup_2");
popup.src = imageSrc;
popup.style.display = "block";
setTimeout(() => {
popup.style.display = "none";
}, 5000); // 5 detik
}
function returnToOriginalPosition(element) {
const originalParentId = element.getAttribute("data-original-parent"); // Ambil ID parent asal
const originalParent = document.getElementById(originalParentId); // Dapatkan elemen parent asal
if (originalParent) {
originalParent.appendChild(element); // Pindahkan kembali ke parent asal
}
}
function showFinalScore() {
alert(`Skor Akhir Anda: ${score}`);
}
document.addEventListener("DOMContentLoaded", () => {
// Simpan posisi awal (parent) setiap elemen neutral
document.querySelectorAll(".neutral").forEach(neutralBox => {
neutralBox.setAttribute("data-original-parent", neutralBox.parentElement.id); // Simpan ID parent asal
// Tevent listener untuk double click agar kembali ke tempat asalnya
neutralBox.addEventListener("dblclick", () => {
returnToOriginalPosition(neutralBox);
});
});
// atribut data-correct, poin, dan validPlacement untuk setiap slot merah
document.querySelectorAll(".red").forEach((redBox, index) => {
// Menentukan data-correct satu per satu berdasarkan ID atau urutan kotak merah
if (redBox.id === "red17") {
redBox.setAttribute("data-correct", "neutral8");
} else if (redBox.id === "red18") {
redBox.setAttribute("data-correct", "neutral5");
} else if (redBox.id === "red19") {
redBox.setAttribute("data-correct", "neutral13");
} else if (redBox.id === "red20") {
redBox.setAttribute("data-correct", "neutral10");
} else if (redBox.id === "red21") {
redBox.setAttribute("data-correct", "neutral2");
} else if (redBox.id === "red22") {
redBox.setAttribute("data-correct", "neutral11");
} else if (redBox.id === "red23") {
redBox.setAttribute("data-correct", "neutral7");
} else if (redBox.id === "red24") {
redBox.setAttribute("data-correct", "neutral3");
} else if (redBox.id === "red25") {
redBox.setAttribute("data-correct", "neutral16");
} else if (redBox.id === "red26") {
redBox.setAttribute("data-correct", "neutral6");
} else if (redBox.id === "red27") {
redBox.setAttribute("data-correct", "neutral14");
} else if (redBox.id === "red28") {
redBox.setAttribute("data-correct", "neutral11");
} else if (redBox.id === "red29") {
redBox.setAttribute("data-correct", "neutral15");
} else if (redBox.id === "red30") {
redBox.setAttribute("data-correct", "neutral9");
} else if (redBox.id === "red31") {
redBox.setAttribute("data-correct", "neutral4");
} else if (redBox.id === "red32") {
redBox.setAttribute("data-correct", "neutral12");
}
// data-wrong sesuai kebutuhan
redBox.setAttribute("data-wrong", "neutral4"); // Contoh untuk data-wrong
// Tentukan poin
redBox.setAttribute("data-correct-points", "10"); // Poin untuk penempatan yang benar
redBox.setAttribute("data-wrong-points", "10"); // Poin untuk penempatan yang salah
});
// Tambahkan event listener untuk tombol tampilkan skor
document.getElementById("show-score-btn").addEventListener("click", showFinalScore);
});
</script>