-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
37 lines (30 loc) · 1.34 KB
/
Copy pathmain.js
File metadata and controls
37 lines (30 loc) · 1.34 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
let activeGameCleanUp = null; // Variabel global untuk menyimpan fungsi cleanup game aktif
function openGame(gameName) {
// Sembunyikan menu utama
document.getElementById("menu").classList.add("hidden");
// Periksa nama game dan tampilkan kanvas yang sesuai
if (gameName === "snake") {
document.getElementById("snakeGame").classList.remove("hidden");
} else if (gameName === "tictactoe") {
document.getElementById("tictactoeGame").classList.remove("hidden");
}
// Import file script game tertentu secara dinamis
const script = document.createElement('script');
script.src = `./games/${gameName}/index.js`; // Memuat file game berdasarkan nama
document.body.appendChild(script)
}
function returnToMenu() {
// Hentikan game aktif jika ada
if (activeGameCleanUp) {
activeGameCleanUp(); // Bersihkan game aktif
activeGameCleanUp = null; // Reset fungsi cleanup
}
// Sembunyikan semua game canvas
document.getElementById("snakeGame").classList.add("hidden");
document.getElementById("tictactoeGame").classList.add("hidden");
// Hapus elemen popup Game Over jika ada
const popup = document.getElementById("gameOverPopup");
if (popup) document.body.removeChild(popup);
// Tampilkan menu utama
document.getElementById("menu").classList.remove("hidden");
}