Ho realizzato un gioco minesweeper in javascript, che alla fine si è svolto senza intoppi, fino a quando non ho aggiunto la funzione "expand()" (vedi sotto). Ho 3 problemi:javascript minesweeper expand messing counter
- Quando si espande aggiunge troppi per "flippedCount" (vedi codice qui sotto) - nell'immagine qui sotto il div a destra viene visualizzato "flippedCount", e il suo 39 invece di 35.
- Di conseguenza, se un giocatore supera i 90 quadrati (importo da vincere) durante un "espandi()", la schermata vincente non viene visualizzata.
- Inoltre non si espande correttamente (vedere le immagini di seguito).
Il codice in questione e un link è qui sotto queste 2 immagini
var flippedCount = 0;
var alreadySetAsZero = [];
var columnAmount = 10;
function processClick(clicked) { //i use a "(this)" to pass as "(clicked)"
nextToBombCheck(parseInt(clicked.id));
checkWin();
}
nextToBombCheck(boxNum) {
flippedCount++;
document.getElementById("flipped").innerHTML = flippedCount;
//long function setting "bombCount" to # bombs around clicked square goes here
if (bombCount !== 0) {
//blah blah blah
} else {
alreadySetAsZero[ boxNum ] = "yes";
expand(boxNum);
}
}
function expand(emptyBoxId) {
checkRightOfEmpty(emptyBoxId + 1);
checkLeftOfEmpty(emptyBoxId - 1);
checkAboveEmpty(emptyBoxId - columnAmount);
checkBelowEmpty(emptyBoxId + columnAmount);
}
function checkRightOfEmpty(boxToTheRightId) {
//check if already marked as zero
if (alreadySetAsZero[ boxToTheRightId ] === "yes")
return;
//if box is at the edge
if (boxToTheRightId % columnAmount === (0)) {
//do nothing
} else {
nextToBombCheck(boxToTheRightId);
}
}
//and the rest are 3 similar functions
non ero in grado di trovare un modello con la mancanza di espansione o aggiunti dei numeri conteggio capovolto.
P.S. scusate per il titolo non so cos'altro chiamarlo
Se posso dare un suggerimento: formattare il codice correttamente (indentazione corretta) e prestare attenzione alla grammatica delle frasi (una frase inizia con una maiuscola per esempio e di solito finisce in un punto). È più probabile che le persone rispondano a una domanda se è facile da leggere. – Sumurai8