Performance enhancements

This commit is contained in:
synth-ruiner 2015-03-09 23:44:35 +00:00
parent e1c50da7b4
commit 52c39c0347
1 changed files with 24 additions and 32 deletions

View File

@ -272,6 +272,18 @@
} }
} }
function newRow() {
var row = '<ul>';
for (var i = 0; i < gameBoardWidth; i++) {
row += newTile();
};
row += '</ul>';
return row;
}
$.fn.checkRow = function() { $.fn.checkRow = function() {
//unclicked tiles //unclicked tiles
@ -316,30 +328,22 @@
return $(this).checkRow(); return $(this).checkRow();
}); });
var numRowsToRemove = rowsToRemove.length;
if (numRowsToRemove == 0) return;
rowsToRemove.addClass("removing");
rowsToRemove.each(function() { rowsToRemove.each(function() {
score += $(this).children('.mine').length; score += $(this).children('.mine').length;
});
rowsToRemove.slideUp("slow", function() { $(this).addClass("removing");
$(this).remove();
//add new row on bottom
$('#game').append('<ul></ul>'); $(this).slideUp("slow", function() {
$(this).remove();
for (var i = 0; i < gameBoardWidth; i++) { //add new row on bottom
$('#game ul').last().append(newTile()); $('#game').append(newRow());
}
refreshMineCounts(); refreshMineCounts();
//click blank tiles //click blank tiles
$('li.revealed:not(.mine):empty').mouseup(); $('li.revealed:not(.mine):empty').mouseup();
});
}); });
} }
@ -348,15 +352,11 @@
return $(this).checkColumn(); return $(this).checkColumn();
}); });
if (columnsToRemove.length == 0) return;
columnsToRemove.addClass("removing");
columnsToRemove.each(function() { columnsToRemove.each(function() {
score += $(this).column().filter('.mine').length; score += $(this).column().filter('.mine').length;
});
columnsToRemove.each(function() { $(this).addClass("removing");
$(this).column().animate({width: 0, borderRadius: 0, padding: 0}, "slow", function() { $(this).column().animate({width: 0, borderRadius: 0, padding: 0}, "slow", function() {
$(this).parent().append(newTile()); $(this).parent().append(newTile());
$(this).remove(); $(this).remove();
@ -446,15 +446,7 @@
} }
$.fn.countMinesAdjacent = function() { $.fn.countMinesAdjacent = function() {
var count = 0; return $(this).getAdjacentTiles().filter('.mine').length;
$.each($(this).getAdjacentTiles(), function() {
if ($(this).isMine()) {
count++;
}
});
return count;
} }
$.fn.getAdjacentTiles = function() { $.fn.getAdjacentTiles = function() {