diff --git a/index.html b/index.html
index dcff2fa..591c432 100644
--- a/index.html
+++ b/index.html
@@ -467,40 +467,26 @@
$.fn.getAdjacentTiles = function() {
var adjacentTiles = $('');
+ var x = $(this).getX();
+ var y = $(this).getY();
- //row above
- if ($(this).getY() > 0) {
- if ($(this).getX() > 0) {
- adjacentTiles = adjacentTiles.add($(this).rowAbove().children().eq($(this).getX() - 1).toArray());
- }
+ if (y > 0) {
+ var tileAbove = $(this).rowAbove().children().eq(x);
- adjacentTiles = adjacentTiles.add($(this).rowAbove().children().eq($(this).getX()).toArray());
-
- if ($(this).getX() < (gameBoardWidth - 1)) {
- adjacentTiles = adjacentTiles.add($(this).rowAbove().children().eq($(this).getX() + 1).toArray());
- }
+ adjacentTiles = adjacentTiles.add(tileAbove.prev());
+ adjacentTiles = adjacentTiles.add(tileAbove );
+ adjacentTiles = adjacentTiles.add(tileAbove.next());
}
- //this row
- if ($(this).getX() > 0) {
- adjacentTiles = adjacentTiles.add($(this).prev().toArray());
- }
+ adjacentTiles = adjacentTiles.add($(this).prev());
+ adjacentTiles = adjacentTiles.add($(this).next());
- if ($(this).getX() < (gameBoardWidth - 1)) {
- adjacentTiles = adjacentTiles.add($(this).next().toArray());
- }
+ if (y < (gameBoardHeight - 1)) {
+ var tileBelow = $(this).rowBelow().children().eq(x);
- //row below
- if ($(this).getY() < (gameBoardHeight - 1)) {
- if ($(this).getX() > 0) {
- adjacentTiles = adjacentTiles.add($(this).rowBelow().children().eq($(this).getX() - 1).toArray());
- }
-
- adjacentTiles = adjacentTiles.add($(this).rowBelow().children().eq($(this).getX()).toArray());
-
- if ($(this).getX() < (gameBoardWidth - 1)) {
- adjacentTiles = adjacentTiles.add($(this).rowBelow().children().eq($(this).getX() + 1).toArray());
- }
+ adjacentTiles = adjacentTiles.add(tileBelow.prev());
+ adjacentTiles = adjacentTiles.add(tileBelow );
+ adjacentTiles = adjacentTiles.add(tileBelow.next());
}
return adjacentTiles;
@@ -596,9 +582,7 @@
//already clicked; use middle click reveal functionality
//number of flags matches number of adjacent mines
- $(this).getAdjacentTiles().filter(':not(.flagged, .revealed)').each(function() {
- $(this).mouseup();
- });
+ $(this).getAdjacentTiles().filter(':not(.flagged, .revealed)').mouseup();
} else {
$(this).addClass("revealed");
@@ -620,9 +604,7 @@
$.fn.middleClick = function() {
//number of flags matches number of adjacent mines
if (parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged, .revealed.mine').length) {
- $(this).getAdjacentTiles().filter(':not(.flagged)').each(function() {
- $(this).mouseup();
- });
+ $(this).getAdjacentTiles().filter(':not(.flagged, .revealed)').mouseup();
}
}
@@ -680,7 +662,7 @@
}
removeClearedRows();
- //removeClearedColumns();
+ removeClearedColumns();
checkGameOver();
updateScore();
@@ -696,7 +678,7 @@