-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (38 loc) · 1.28 KB
/
index.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
import { grid, adjustLayout } from './layout/grid';
import popUpNumbers from './layout/popUp';
const gridContainer = document.getElementById('container');
const popUpElem = document.getElementById('popUp');
const startGame = document.querySelector('.start-button');
let sodukuBoard;
const popUp = popUpNumbers(popUpElem);
const restartBtn = document.getElementById('restart');
const checkBtn = document.getElementById('check');
const resetBtn = document.getElementById('reset');
const clearBtn = document.getElementById('clear');
function startPlay(e, restart = false) {
if (!e.isTrusted) {
alert("Don't cheat dude!");
return;
}
if (restart) gridContainer.innerHTML = null;
startGame.classList.add('hidden');
sodukuBoard = grid(gridContainer);
sodukuBoard.build();
adjustLayout();
sodukuBoard.bindPopUp(popUp);
popUp.bindClicks();
}
startGame.addEventListener('click', startPlay);
//bind events to the control btn
restartBtn.addEventListener('click', (e) => startPlay(e, true));
checkBtn.addEventListener('click', (e) => {
if (sodukuBoard.check()) {
alert('You are so great');
sodukuBoard.startPlay(e, true);
}
sodukuBoard.check();
});
resetBtn.addEventListener('click', () => {
sodukuBoard.reset();
});
clearBtn.addEventListener('click', () => sodukuBoard.clear());