Adding support to reveal the adjacents cells
This commit is contained in:
20
src/App.js
20
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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user