From cebae1734160889f5c21d8dda1e41574bf48e5d4 Mon Sep 17 00:00:00 2001 From: synth-ruiner Date: Fri, 6 Mar 2015 09:40:32 +0000 Subject: [PATCH 1/4] Add middle-click functionality to left click --- index.html | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index f9707a5..427877d 100644 --- a/index.html +++ b/index.html @@ -468,7 +468,9 @@ $('#setup').hide(); }); - $.fn.leftClick = function() { + $.fn.leftClick = function(automated) { + if (!automated) automated = false; + //don't want first click to be a mine if (firstClick) { var x = $(this).getX(); @@ -500,9 +502,11 @@ //$(this).middleClick(); //number of flags matches number of adjacent mines - $(this).getAdjacentTiles().filter(':not(.flagged)').each(function() { - //$(this).mousedown(); - }); + if (!automated && parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged, .revealed.mine').length) { + $(this).getAdjacentTiles().filter(':not(.flagged)').each(function() { + $(this).mousedown(); + }); + } } else { $(this).addClass("revealed"); @@ -522,8 +526,6 @@ } $.fn.middleClick = function() { - //move this functionality to left click - //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() { @@ -558,9 +560,11 @@ $(this).middleClick(); break; case 1: - default: $(this).leftClick(); break; + default: + $(this).leftClick(true); //automated + break; } removeClearedRows(); From 0272c62f6c5e3d752a99627f36c408eb16780d5c Mon Sep 17 00:00:00 2001 From: synth-ruiner Date: Fri, 6 Mar 2015 09:41:55 +0000 Subject: [PATCH 2/4] Update readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 3f7d639..ad09561 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ Rows with exploded mines cannot be cleared. See how far you can get! Left-click to clear a tile. Right-click to flag a mine. Middle-click a number to clear any non-flagged adjacent tiles. ## stuff to add -move middle-click functionality to left-click instead - add support for mobile devices/1-button mice (probably hold down to flag a mine) save game using html5 local storage so player can come back later From b4a037c0cb94ee9634353310f632e921f8a804b7 Mon Sep 17 00:00:00 2001 From: synth-ruiner Date: Fri, 6 Mar 2015 10:41:53 +0000 Subject: [PATCH 3/4] Mouse hold functionality --- index.html | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index 427877d..c961122 100644 --- a/index.html +++ b/index.html @@ -217,6 +217,9 @@ var currentlyIterating = false; var mineChance = 0.2; var inputEnabled = true; + var clickholdMs = 200; + var timeout; //hold timer + var mouseHeld = false; $(document).ready(function() { function drawGameBoard() { @@ -309,10 +312,10 @@ }); //refresh last row to reflect new rows beneath - $('li.revealed').last().parent().children('li.revealed').mousedown(); + $('li.revealed').last().parent().children('li.revealed').mouseup(); //click blank tiles - $('li.revealed:not(.mine):empty').mousedown(); + $('li.revealed:not(.mine):empty').mouseup(); //this is a bit of a hack :( oh well $('ul:gt(' + gameBoardHeight + ')').remove(); @@ -497,16 +500,13 @@ //game over, or lose a life, or whatever //... - } else if (parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged').length) { + } else if (!automated && parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged, .revealed.mine').length) { //already clicked; use middle click reveal functionality - //$(this).middleClick(); - + //number of flags matches number of adjacent mines - if (!automated && parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged, .revealed.mine').length) { - $(this).getAdjacentTiles().filter(':not(.flagged)').each(function() { - $(this).mousedown(); - }); - } + $(this).getAdjacentTiles().filter(':not(.flagged, .revealed)').each(function() { + $(this).mouseup(); + }); } else { $(this).addClass("revealed"); @@ -518,7 +518,7 @@ //if no mines adjacent, cascade! if ($(this).countMinesAdjacent() == 0) { - $(this).getAdjacentTiles().filter(':not(.revealed)').mousedown(); + $(this).getAdjacentTiles().filter(':not(.revealed)').mouseup(); } } @@ -529,7 +529,7 @@ //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).mousedown(); + $(this).mouseup(); }); } } @@ -541,17 +541,41 @@ } else { $(this).toggleClass("flagged"); } + + clearTimeout(timeout); } $(document).on("contextmenu", "li", function(event) { event.preventDefault(); }); + $(document).on("mousedown", "li", function(event) { + var x = $(this).getX(); + var y = $(this).getY(); + + timeout = setTimeout(function() { + $('ul:eq(' + y + ') li:eq(' + x + ')').rightClick(); + mouseHeld = true; + }, clickholdMs); + }); + + $(document).on("mouseleave", "li", function(event) { + clearTimeout(timeout); + }); + + $(document).on("mouseup", "li", function(event) { event.preventDefault(); + clearTimeout(timeout); + if (!inputEnabled) return; + if (mouseHeld) { + mouseHeld = false; + return; + } + switch (event.which) { case 3: $(this).rightClick(); From c75ff197f8b33cd02e7b7948aa2b9472a809f158 Mon Sep 17 00:00:00 2001 From: synth-ruiner Date: Fri, 6 Mar 2015 10:52:29 +0000 Subject: [PATCH 4/4] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index ad09561..17667ba 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ Rows with exploded mines cannot be cleared. See how far you can get! Left-click to clear a tile. Right-click to flag a mine. Middle-click a number to clear any non-flagged adjacent tiles. ## stuff to add -add support for mobile devices/1-button mice (probably hold down to flag a mine) - save game using html5 local storage so player can come back later make cleared columns slide left?