Merge remote-tracking branch 'origin/master' into gh-pages

This commit is contained in:
synth-ruiner 2015-03-10 20:01:47 +00:00
commit ccf1f8e7c2
1 changed files with 168 additions and 147 deletions

View File

@ -47,6 +47,20 @@
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#768087', endColorstr='#53595e',GradientType=0 ); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#768087', endColorstr='#53595e',GradientType=0 );
} }
#stats button {
margin: 1vmin;
float: right;
font-family: Helsinki;
font-size: 3vmin;
border-radius: 2vmin;
padding: 1.75vmin;
box-shadow: 0.5vmin 0.5vmin 0 #000;
border: 0.4vmin solid #454e52;
position: relative;
top: auto;
left: auto;
}
#stats div { #stats div {
float: left; float: left;
font-size: 5.4vmin; font-size: 5.4vmin;
@ -57,19 +71,10 @@
#gameOver, #setup { #gameOver, #setup {
position: absolute; position: absolute;
width: 100vmin; width: 100vmin;
height: 90vmin; height: 100vh;
background-color: rgba(0,0,0,0.3); background-color: rgba(0,0,0,0.3);
} }
#setup {
height: 100vmin;
}
#setup h1 {
margin-top: 6vmin;
margin-bottom: 6vmin;
}
#setup h2 { #setup h2 {
margin-top: 0; margin-top: 0;
} }
@ -121,6 +126,11 @@
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#768087', endColorstr='#53595e',GradientType=0 ); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#768087', endColorstr='#53595e',GradientType=0 );
} }
button.cancel {
right: 20vmin;
left: auto;
}
h1, h2 { h1, h2 {
text-align: center; text-align: center;
} }
@ -128,7 +138,8 @@
h1 { h1 {
color: #a4f4b4; color: #a4f4b4;
font-size: 12vmin; font-size: 12vmin;
margin: 16vmin 0; margin-top: 6vmin;
margin-bottom: 6vmin;
text-shadow: 1vmin 1vmin 0 #fe7ac6; /* x y blur-radius colour */ text-shadow: 1vmin 1vmin 0 #fe7ac6; /* x y blur-radius colour */
} }
@ -174,6 +185,7 @@
li.mine.revealed { li.mine.revealed {
background-color: #d23000; background-color: #d23000;
color: #000;
} }
li.mines1 { li.mines1 {
@ -234,15 +246,16 @@
function drawGameBoard() { function drawGameBoard() {
$('#game').html(""); $('#game').html("");
for (var i = 0; i < gameBoardHeight; i++) { //determine aspect ratio so as to fit the screen
$('#game').append("<ul></ul>"); gameBoardHeight = Math.floor((1 / getAspectRatio()) * 10) - 1;
if (gameBoardHeight <= 9) {
gameBoardHeight = 9;
} }
$('#game ul').each(function() { for (var i = 0; i < gameBoardHeight; i++) {
for (var i = 0; i < gameBoardWidth; i++) { $('#game').append(newRow());
$(this).append(newTile());
} }
});
} }
function newTile() { function newTile() {
@ -253,43 +266,43 @@
} }
} }
function newRow() {
var row = '<ul>';
$.fn.checkRow = function() { for (var i = 0; i < gameBoardWidth; i++) {
row += newTile();
};
row += '</ul>';
return row;
}
$.fn.check = function() {
//unclicked tiles //unclicked tiles
if ($(this).children('li:not(.revealed):not(.flagged)').length > 0) { if ($(this).filter('li:not(.revealed):not(.flagged)').length > 0) {
return false; return false;
} }
//incorrectly flagged tiles //incorrectly flagged tiles
if ($(this).children('li.flagged:not(.mine)').length > 0) { if ($(this).filter('li.flagged:not(.mine)').length > 0) {
return false; return false;
} }
//clicked mines //clicked mines
if ($(this).children('li.revealed.mine').length > 0) { if ($(this).filter('li.revealed.mine').length > 0) {
return false; return false;
} }
return true; return true;
} }
$.fn.checkRow = function() {
return $(this).children().check();
}
$.fn.checkColumn = function() { $.fn.checkColumn = function() {
//unclicked tiles return $(this).column().check();
if ($(this).column().filter(':not(.revealed):not(.flagged)').length > 0) {
return false;
}
//incorrectly flagged tiles
if ($(this).column().filter('.flagged:not(.mine)').length > 0) {
return false;
}
//clicked mines
if ($(this).column().filter('.revealed.mine').length > 0) {
return false;
}
return true;
} }
window.removeClearedRows = function() { window.removeClearedRows = function() {
@ -297,31 +310,23 @@
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).slideUp("slow", function() {
$(this).remove(); $(this).remove();
//add new row on bottom //add new row on bottom
$('#game').append(newRow());
$('#game').append('<ul></ul>');
for (var i = 0; i < gameBoardWidth; i++) {
$('#game ul').last().append(newTile());
}
refreshMineCounts(); refreshMineCounts();
//click blank tiles //click blank tiles
$('li.revealed:not(.mine):empty').mouseup(); $('li.revealed:not(.mine):empty').mouseup();
}); });
});
} }
window.removeClearedColumns = function() { window.removeClearedColumns = function() {
@ -329,48 +334,44 @@
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).column().addClass("removing");
$(this).column().animate({width: 0, borderRadius: 0, padding: 0}, "slow", function() {
$(this).parent().append(newTile()); //animation for top row + deletion
$(this).remove(); // then animation for others?
//...
$(this).animate({width: 0, borderRadius: 0, padding: 0}, "slow", function() {
$(this).column().remove();
$('ul').each(function() {
$(this).append(newTile());
});
refreshMineCounts(); refreshMineCounts();
//click blank tiles //click blank tiles
$('li.revealed:not(.mine):empty').mouseup(); $('li.revealed:not(.mine, .removing):empty').mouseup();
}); });
$(this).column().animate({width: 0, borderRadius: 0, padding: 0}, "slow");
}); });
} }
function refreshMineCounts() { function refreshMineCounts() {
$('li.revealed:not(.mine)').each(function() { $('ul:not(.removing) li.revealed:not(.mine, .removing)').each(function() {
$(this).text( var mineCount = $(this).countMinesText();
$(this).countMinesText()
); $(this).text(mineCount);
//remove "mines1" etc //remove "mines1" etc
$(this).attr(
var mine = $(this).hasClass("mine"); 'class',
$(this).attr('class').replace(
$(this).removeAttr("class"); /mines[0-9]/, "mines" + mineCount
)
if (mine) {
$(this).addClass("mine");
} else {
$(this).addClass(
"mines" + $(this).countMinesText()
); );
}
$(this).addClass("revealed");
}); });
} }
@ -398,6 +399,20 @@
); );
} }
function getAspectRatio() {
return $(window).width() / $(window).height();
}
function isPortrait() {
return getAspectRatio() > 1;
}
$.fn.updateMineCount = function() {
$(this).text(
$(this).countMinesText
);
}
$.fn.rowScore = function() { $.fn.rowScore = function() {
return $(this).children('.mine').length; return $(this).children('.mine').length;
} }
@ -435,53 +450,31 @@
} }
$.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() {
var adjacentTiles = $(''); var adjacentTiles = $('');
var x = $(this).getX();
var y = $(this).getY();
//row above if (y > 0) {
if ($(this).getY() > 0) { var tileAbove = $(this).rowAbove().children().eq(x);
if ($(this).getX() > 0) {
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());
} }
adjacentTiles = adjacentTiles.add($(this).rowAbove().children().eq($(this).getX()).toArray()); adjacentTiles = adjacentTiles.add($(this).prev());
adjacentTiles = adjacentTiles.add($(this).next());
if ($(this).getX() < (gameBoardWidth - 1)) { if (y < (gameBoardHeight - 1)) {
adjacentTiles = adjacentTiles.add($(this).rowAbove().children().eq($(this).getX() + 1).toArray()); var tileBelow = $(this).rowBelow().children().eq(x);
}
}
//this row adjacentTiles = adjacentTiles.add(tileBelow.prev());
if ($(this).getX() > 0) { adjacentTiles = adjacentTiles.add(tileBelow );
adjacentTiles = adjacentTiles.add($(this).prev().toArray()); adjacentTiles = adjacentTiles.add(tileBelow.next());
}
if ($(this).getX() < (gameBoardWidth - 1)) {
adjacentTiles = adjacentTiles.add($(this).next().toArray());
}
//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());
}
} }
return adjacentTiles; return adjacentTiles;
@ -506,14 +499,31 @@
}); });
$('#gameOver button').on("click", function() { $('#gameOver button').on("click", function() {
//reset game board
drawGameBoard(); drawGameBoard();
$('#gameOver').hide(); $('#gameOver').hide();
$('button.cancel').hide();
$('button.start').removeAttr('style');
$('#setup').show(); $('#setup').show();
}); });
$('#setup button').on("click", function() { $('button.reset').on("click", function() {
//prompt user with setup screen
$('#setup').show();
$('button.cancel').show();
$('button.start').css('left', '20vmin');
});
$('button.cancel').on("click", function() {
//prompt user with setup screen
$('#setup').hide();
$('button.cancel').hide();
$('button.start').removeAttr('style');
});
$('button.start').on("click", function() {
drawGameBoard();
//reset stats //reset stats
firstClick = true; firstClick = true;
@ -552,6 +562,7 @@
if ($(this).isMine()) { if ($(this).isMine()) {
$(this).addClass("revealed"); $(this).addClass("revealed");
$(this).html("&#9760;"); //skull & crossbones
//game over, or lose a life, or whatever //game over, or lose a life, or whatever
//... //...
@ -559,15 +570,11 @@
//already clicked; use middle click reveal functionality //already clicked; use middle click reveal functionality
//number of flags matches number of adjacent mines //number of flags matches number of adjacent mines
$(this).getAdjacentTiles().filter(':not(.flagged, .revealed)').each(function() { $(this).getAdjacentTiles().filter(':not(.flagged, .revealed)').mouseup();
$(this).mouseup();
});
} else { } else {
$(this).addClass("revealed"); $(this).addClass("revealed");
$(this).text( $(this).updateMineCount();
$(this).countMinesText()
);
$(this).addClass("mines" + $(this).countMinesAdjacent()); $(this).addClass("mines" + $(this).countMinesAdjacent());
@ -583,9 +590,7 @@
$.fn.middleClick = function() { $.fn.middleClick = function() {
//number of flags matches number of adjacent mines //number of flags matches number of adjacent mines
if (parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged, .revealed.mine').length) { if (parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged, .revealed.mine').length) {
$(this).getAdjacentTiles().filter(':not(.flagged)').each(function() { $(this).getAdjacentTiles().filter(':not(.flagged, .revealed)').mouseup();
$(this).mouseup();
});
} }
} }
@ -597,7 +602,7 @@
clearTimeout(timeout); clearTimeout(timeout);
} }
$(document).on("contextmenu", "li", function(event) { $(document).on("contextmenu", "body", function(event) {
event.preventDefault(); event.preventDefault();
}); });
@ -643,7 +648,7 @@
} }
removeClearedRows(); removeClearedRows();
//removeClearedColumns(); removeClearedColumns();
checkGameOver(); checkGameOver();
updateScore(); updateScore();
@ -654,17 +659,32 @@
drawGameBoard(); drawGameBoard();
$('#gameOver').hide(); $('#gameOver').hide();
$('button.cancel').hide();
}); });
</script> </script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-60523398-1', 'auto');
ga('send', 'pageview');
</script>
</head> </head>
<body> <body>
<div id="game"></div>
<div id="stats"> <div id="stats">
<div id="score">Score: 0</div> <div id="score">Score: 0</div>
<div id="mines">Mines left: 0</div> <div id="mines">Mines left: 0</div>
<button class="reset">reset</button>
</div> </div>
<div id="game"></div>
<div id="gameOver"> <div id="gameOver">
<h1>game over</h1> <h1>game over</h1>
<p>a game by max bradbury</p>
<p>inspirations include minesweeper, tetris and 2048</p>
<p>tell your friends</p>
<p>stay in school</p>
<button>reset</button> <button>reset</button>
</div> </div>
<div id="setup"> <div id="setup">
@ -687,7 +707,8 @@
<label for="difficultyHard">Hard</label> <label for="difficultyHard">Hard</label>
</div> </div>
<button>start</button> <button class="start">start</button>
<button class="cancel">cancel</button>
</div> </div>
</body> </body>
</html> </html>