From cd88607ad311ed88bb524b5e3e02eec00044296e Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Thu, 15 Dec 2022 11:52:17 +0100
Subject: [PATCH] Add an event handler for the click event

---
 src/js/Components.js | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/js/Components.js b/src/js/Components.js
index e9dd6a8..f4162d1 100644
--- a/src/js/Components.js
+++ b/src/js/Components.js
@@ -13,6 +13,31 @@ export function App(game)
 {
     return [
         "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,
             game.board