MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / checkStatusOfGame

Function checkStatusOfGame

assets/js/ConnectFour.js:234–388  ·  view source on GitHub ↗
(cell)

Source from the content-addressed store, hash-verified

232};
233
234const checkStatusOfGame = (cell) => {
235 const color = getColorOfCell(cell);
236
237 if (!color) return;
238 const [rowIndex, colIndex] = getCellLocation(cell);
239
240 /* Check Horizontally */
241
242 let winningCells = [cell];
243 let rowToCheck = rowIndex;
244 let colToCheck = colIndex - 1;
245
246 while (colToCheck >= 0) {
247 const cellToCheck = rows[rowToCheck][colToCheck];
248
249 if (getColorOfCell(cellToCheck) === color) {
250 winningCells.push(cellToCheck);
251 colToCheck--;
252 } else {
253 break;
254 }
255 }
256
257 colToCheck = colIndex + 1;
258
259 while (colToCheck <= 6) {
260 const cellToCheck = rows[rowToCheck][colToCheck];
261
262 if (getColorOfCell(cellToCheck) === color) {
263 winningCells.push(cellToCheck);
264 colToCheck++;
265 } else {
266 break;
267 }
268 }
269
270 let isWinningCombo = checkWinningCells(winningCells);
271 if (isWinningCombo) return;
272
273 /* Check Vertically */
274
275 winningCells = [cell];
276 rowToCheck = rowIndex - 1;
277 colToCheck = colIndex;
278
279 while (rowToCheck >= 0) {
280 const cellToCheck = rows[rowToCheck][colToCheck];
281
282 if (getColorOfCell(cellToCheck) === color) {
283 winningCells.push(cellToCheck);
284 rowToCheck--;
285 } else {
286 break;
287 }
288 }
289
290 rowToCheck = rowIndex + 1;
291

Callers 1

handleCellClickFunction · 0.85

Calls 4

getColorOfCellFunction · 0.85
getCellLocationFunction · 0.85
checkWinningCellsFunction · 0.85
getClassListArrayFunction · 0.85

Tested by

no test coverage detected