-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
62 lines (45 loc) · 1.69 KB
/
main.js
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
import GameLogic from "./src/GameLogic.js";
import GameSound from './src/GameSound.js'
import { OutputMsg, HandleInput } from "./src/GameUI.js";
const gameSound = new GameSound()
const outputMsg = new OutputMsg()
const handleInput = new HandleInput(outputMsg, gameSound);
const gameLogic = new GameLogic(handleInput, outputMsg, gameSound);
document.addEventListener("DOMContentLoaded", () => {
const submitBtn = document.querySelector("#submitBtn");
const resultContainer = document.querySelector(".result-container");
const muteBtn = document.querySelector("#muteBtn");
const soundImg = document.querySelector(".sound-img");
const cells = document.querySelectorAll(".cells");
const cellsArray = Array.from(cells);
muteBtn.addEventListener("click", () => {
if (muteBtn.classList.contains("sound-on")) {
gameSound.muteSounds()
soundImg.src = "./src/assets/music-note-off.svg"
soundImg.alt = "sound off"
muteBtn.classList.remove("sound-on")
muteBtn.classList.add("sound-off")
} else {
gameSound.unMuteSounds()
soundImg.src = "./src/assets/music-note.svg"
soundImg.alt = "sound on"
muteBtn.classList.remove("sound-off")
muteBtn.classList.add("sound-on")
}
})
submitBtn.addEventListener("click", (e) => {
e.preventDefault();
handleInput.submitHandler()
});
cells.forEach((cell) => {
cell.addEventListener("click", (e) => {
gameLogic.turnGame(e, cellsArray);
});
});
document.querySelector("#resetGameBtn").addEventListener("click", () => {
gameLogic.resetLogin();
});
document.querySelector("#playAgainGameBtn").addEventListener("click", () => {
gameLogic.playAgainLogic();
});
});