Add an event handler for the click event
This commit is contained in:
parent
e6cea57d65
commit
cd88607ad3
1 changed files with 25 additions and 0 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue