Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
Buscando entender cómo contar y revelar fichas adyacentes en el buscaminas

Escribí un algoritmo para contar y revelar todas las fichas adyacentes en el buscaminas. Sin embargo, cuando se revela una ficha y no contiene una mina, muestra cero. Las minas adyacentes no se revelan. Estoy seguro de que el problema está en mi código, pero no puedo resolverlo. Estoy buscando alguna orientación.

captura de pantalla que ilustra lo que describí anteriormente.

 My code:
 // Left Click if (event.which === 1) { startTimer(); if(tile.classList.contains("mine")) { tile.classList.toggle("mine_hit"); smiley.classList.toggle("face_lose"); window.alert("Game Over. You lose!"); revealMines(); } else { tile.classList.contains("hidden"); tile.classList.remove("hidden"); // Count and display the number of adjacent mines var mineCount = 0; var tileRow = tile.parentNode.rowIndex; var tileCol = tile.cellIndex; //alert (tileRow + "" + tileCol); for (var i = Math.max(tileRow-1,0); i <= Math.min(tileRow+1,9); i++) { for (var j = Math.max(tileCol-1,0); j <=Math.min(tileCol+1,9); j++) { if(minefield.rows[i].tile[j].classList.contains("mine")) { mineCount++; } } } tile.innerHTML=mineCount; if (mineCount==0) { //Reveal all adjacent tiles as they do not have a mine for (var i = Math.max(tileRow -1, 0); i <= Math.min(tileRow +1, 9); i++) { for (var j=Math.max(tileCol -1, 0); j <=Math.min(tileCol+1,9); j++) { //recursive call if (minefield.rows[i].tiles[j].innerHTML=="") handleTileClick(minefield.rows[i].tile[j]); } } } //checkCompletionLevel(); } }

Intenté modificar la función de revelar minas pero no tuve éxito. Cambié esta línea tile.innerHTML=mineCount a tile.classList.containst("Hidden")=tile.ClassList.toggle("tile_1"). Pero el tablero de juego muestra 1 en azul donde se hizo clic en el mosaico. He buscado otros juegos de buscaminas para tratar de entender, pero no tuve éxito.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!