-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (21 loc) · 795 Bytes
/
index.js
File metadata and controls
25 lines (21 loc) · 795 Bytes
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
import Board from './module/Board.js';
import checkDraw from './module/checkDraw.js';
import checkWin from './module/checkWin.js';
import gameEnd from './module/gameEnd.js';
export const board = new Board();
board.setOnClickHook(shape => {
if (checkWin(shape)) {
gameEnd(`${shape == 'cross' ? 'X' : 'O'} wins!`);
} else if (checkDraw()) {
gameEnd("It's a Draw!");
}
});
document.querySelector('button').addEventListener('click', () => {
document.querySelectorAll('.cell').forEach(cell => {
cell.classList.remove('fixed', 'circle', 'cross', 'highlight');
cell.innerHTML = ``;
});
document.querySelector('.play-again').classList.remove('reveal');
document.querySelector('.result').classList.remove('reveal');
board.enable();
});