-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
23 lines (22 loc) · 818 Bytes
/
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
import boardContainer from './boardView.js';
import knightMoves from './knightTravails.js';
document.addEventListener('DOMContentLoaded', () => {
let board = new boardContainer();
let gameContainer = document.getElementById('game-container');
gameContainer.prepend(board);
gameContainer.addEventListener('click', (ev) => {
if (
ev.target.id === 'go-btn' &&
board.querySelector('.start') &&
board.querySelector('.end')
) {
let start = board.querySelector('.start').getAttribute('coords');
let end = board.querySelector('.end').getAttribute('coords');
let path = knightMoves(JSON.parse(start), JSON.parse(end));
board.highlightPath(path);
}
if (ev.target.id === 'reset-btn') {
board.reset();
}
});
});