| 138 | |
| 139 | //check neighboring squares once square is clicked |
| 140 | function checkSquare(square, currentId) { |
| 141 | const isLeftEdge = currentId % width === 0; |
| 142 | const isRightEdge = currentId % width === width - 1; |
| 143 | |
| 144 | setTimeout(() => { |
| 145 | if (currentId > 0 && !isLeftEdge) { |
| 146 | const newId = squares[parseInt(currentId) - 1].id; |
| 147 | const newSquare = document.getElementById(newId); |
| 148 | click(newSquare); |
| 149 | } |
| 150 | if (currentId > 9 && !isRightEdge) { |
| 151 | const newId = squares[parseInt(currentId) + 1 - width].id; |
| 152 | const newSquare = document.getElementById(newId); |
| 153 | click(newSquare); |
| 154 | } |
| 155 | if (currentId > 10) { |
| 156 | const newId = squares[parseInt(currentId - width)].id; |
| 157 | const newSquare = document.getElementById(newId); |
| 158 | click(newSquare); |
| 159 | } |
| 160 | if (currentId > 11 && !isLeftEdge) { |
| 161 | const newId = squares[parseInt(currentId) - 1 - width].id; |
| 162 | const newSquare = document.getElementById(newId); |
| 163 | click(newSquare); |
| 164 | } |
| 165 | if (currentId < 98 && !isRightEdge) { |
| 166 | const newId = squares[parseInt(currentId) + 1].id; |
| 167 | const newSquare = document.getElementById(newId); |
| 168 | click(newSquare); |
| 169 | } |
| 170 | if (currentId < 90 && !isLeftEdge) { |
| 171 | const newId = squares[parseInt(currentId) - 1 + width].id; |
| 172 | const newSquare = document.getElementById(newId); |
| 173 | click(newSquare); |
| 174 | } |
| 175 | if (currentId < 88 && !isRightEdge) { |
| 176 | const newId = squares[parseInt(currentId) + 1 + width].id; |
| 177 | const newSquare = document.getElementById(newId); |
| 178 | click(newSquare); |
| 179 | } |
| 180 | if (currentId < 89) { |
| 181 | const newId = squares[parseInt(currentId) + width].id; |
| 182 | const newSquare = document.getElementById(newId); |
| 183 | click(newSquare); |
| 184 | } |
| 185 | }, 10); |
| 186 | } |
| 187 | |
| 188 | //game over |
| 189 | function gameOver(square) { |