From 3d9317b6588e3889b5f484df7ae3a12b3696207a Mon Sep 17 00:00:00 2001 From: Michel Wilhelm Date: Sun, 8 Nov 2020 04:12:04 -0300 Subject: [PATCH] Adding support to reveal the adjacents cells --- src/App.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/App.js b/src/App.js index b2bf5a1..2bd82a2 100644 --- a/src/App.js +++ b/src/App.js @@ -121,6 +121,7 @@ function App() { gameClient.cellClick(row, col, activeGame.id).then(response => { cell.classList.add('revealed'); cell.classList.remove('busy'); + if (response.active_game.board_progress[row][col] === 0) { cell.classList.add('empty'); } else if (response.active_game.board_progress[row][col] > 0) { @@ -134,6 +135,25 @@ function App() { document.getElementsByClassName('reset')[0].innerHTML = '👻'; } + response.active_game.board_progress.map((row, rowId) => + row.map((col, colId) => { + const element = document.getElementById(`cell_${rowId}_${colId}`); + if (element.classList.length > 2) { + return; + } + + if (col == '-') { + return; + } + element.classList.add('revealed'); + element.classList.add('point'); + element.classList.add(`point-${col}`); + if (col > 0) { + element.innerHTML = col; + } + }) + ); + setActiveGame(response.active_game); }); }