From 52c39c0347967d3e5d971f97d7a75d86135e9926 Mon Sep 17 00:00:00 2001 From: synth-ruiner Date: Mon, 9 Mar 2015 23:44:35 +0000 Subject: [PATCH] Performance enhancements --- index.html | 56 +++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/index.html b/index.html index 9cee94f..e1e3459 100644 --- a/index.html +++ b/index.html @@ -272,6 +272,18 @@ } } + function newRow() { + var row = ''; + + return row; + } + $.fn.checkRow = function() { //unclicked tiles @@ -316,30 +328,22 @@ return $(this).checkRow(); }); - var numRowsToRemove = rowsToRemove.length; - - if (numRowsToRemove == 0) return; - - rowsToRemove.addClass("removing"); - rowsToRemove.each(function() { score += $(this).children('.mine').length; - }); - rowsToRemove.slideUp("slow", function() { - $(this).remove(); - //add new row on bottom + $(this).addClass("removing"); - $('#game').append(''); + $(this).slideUp("slow", function() { + $(this).remove(); - for (var i = 0; i < gameBoardWidth; i++) { - $('#game ul').last().append(newTile()); - } + //add new row on bottom + $('#game').append(newRow()); - refreshMineCounts(); + refreshMineCounts(); - //click blank tiles - $('li.revealed:not(.mine):empty').mouseup(); + //click blank tiles + $('li.revealed:not(.mine):empty').mouseup(); + }); }); } @@ -348,15 +352,11 @@ return $(this).checkColumn(); }); - if (columnsToRemove.length == 0) return; - - columnsToRemove.addClass("removing"); - columnsToRemove.each(function() { score += $(this).column().filter('.mine').length; - }); - columnsToRemove.each(function() { + $(this).addClass("removing"); + $(this).column().animate({width: 0, borderRadius: 0, padding: 0}, "slow", function() { $(this).parent().append(newTile()); $(this).remove(); @@ -446,15 +446,7 @@ } $.fn.countMinesAdjacent = function() { - var count = 0; - - $.each($(this).getAdjacentTiles(), function() { - if ($(this).isMine()) { - count++; - } - }); - - return count; + return $(this).getAdjacentTiles().filter('.mine').length; } $.fn.getAdjacentTiles = function() {