Add an event handler for the click event

This commit is contained in:
Manuel Thalmann 2022-12-15 11:52:17 +01:00
parent e6cea57d65
commit cd88607ad3
No known key found for this signature in database
GPG key ID: 5FD9AD3CCDDBD27B

View file

@ -13,6 +13,31 @@ export function App(game)
{ {
return [ return [
"div", "div",
{
onclick: (event) =>
{
let target = /** @type {HTMLElement} */ (event.target);
for (let y = 0; y < game.board.length; y++)
{
let rowLength = game.board[y].length;
for (let x = 0; x < rowLength; x++)
{
let node = document.querySelector(".board").children.item(y * rowLength + x);
if (node === target || node.contains(target))
{
if (game.addChip(x, y))
{
game.state.turnCount++;
game.draw();
}
}
}
}
}
},
[ [
Board, Board,
game.board game.board