From 26002d06c36d6dae0f8f8abaf5cddaf779ce7c3e Mon Sep 17 00:00:00 2001 From: jim-clark Date: Fri, 26 Jul 2019 13:58:18 -0700 Subject: [PATCH] Add render and stub up event listener --- css/main.css | 21 +++++++++++++++++++-- index.html | 11 ++++++++++- js/main.js | 22 +++++++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/css/main.css b/css/main.css index 3811df1..f6573f8 100644 --- a/css/main.css +++ b/css/main.css @@ -11,14 +11,31 @@ body { align-items: center; } -section { +section.markers { + display: grid; + grid-template-columns: repeat(7, 10vmin); + grid-gap: 1vmin; + margin-bottom: 1vmin; +} + +section.markers div { + border-top: 5vmin solid lightgrey; + border-left: 5vmin solid transparent; + border-right: 5vmin solid transparent; +} + +section.markers div:hover { + border-top-color: grey; +} + +section.board { display: grid; grid-template-columns: repeat(7, 10vmin); grid-template-rows: repeat(6, 10vmin); grid-gap: 1vmin; } -section div { +section.board div { border-radius: 50%; border: 1px solid grey; } \ No newline at end of file diff --git a/index.html b/index.html index 7511d45..2d29b4c 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,16 @@

CONNECT FOUR

-
+
+
+
+
+
+
+
+
+
+
diff --git a/js/main.js b/js/main.js index 52db426..0b45cd3 100644 --- a/js/main.js +++ b/js/main.js @@ -12,9 +12,11 @@ let board, turn, winner; /*----- event listeners -----*/ - +document.querySelector('section.markers') + .addEventListener('click', handleClick); /*----- functions -----*/ +init(); function init() { board = [ @@ -28,4 +30,22 @@ function init() { ]; turn = 1; winner = null; // 1, -1, null (no winner), 'T' (tie) + render(); +} + +function render() { + // Render the board + board.forEach(function(colArr, colIdx) { + colArr.forEach(function(cell, rowIdx) { + let div = document.getElementById(`c${colIdx}r${rowIdx}`); + div.style.backgroundColor = COLORS[cell]; + }); + }); +} + +function handleClick(evt) { + let idx = parseInt(evt.target.id.replace('col', '')); + if (isNaN(idx) || winner) return; + + } \ No newline at end of file