More fixes

More styling for numbers

First click can no longer be a mine
This commit is contained in:
synth-ruiner 2015-02-28 19:20:27 +00:00
parent 37e98ea1f5
commit 551499749d
1 changed files with 91 additions and 29 deletions

View File

@ -84,14 +84,36 @@
li.mines3 { li.mines3 {
color: #fe7ac6; color: #fe7ac6;
} }
li.mines4 {
color: #b17afe;
}
li.mines5 {
color: #feb27a;
}
li.mines6 {
color: #7afeb2;
}
li.mines7 {
color: #d74600;
}
li.mines8 {
color: #8c4600;
}
</style> </style>
<script src="jquery-2.1.3.min.js"></script> <script src="jquery-2.1.3.min.js"></script>
<script> <script>
var gameBoard = []; var gameBoardWidth = 10;
var score = 0; var gameBoardHeight = 10;
var firstClick = true; var gameBoard = [];
var score = 0;
var firstClick = true;
$( document ).ready(function() { $(document).ready(function() {
function newTile() { function newTile() {
var tile = {}; var tile = {};
@ -101,15 +123,19 @@
return tile; return tile;
} }
function newRow() {
var newRow = [];
for (var i = 0; i < gameBoardWidth; i++) {
newRow.push(newTile());
};
return newRow;
}
function initGameBoard() { function initGameBoard() {
for (var i = 0; i < 10; i++) { for (var i = 0; i < gameBoardHeight; i++) {
var row = []; gameBoard.push(newRow());
for (var j = 0; j < 10; j++) {
row.push(newTile());
}
gameBoard.push(row);
} }
} }
@ -132,16 +158,20 @@
} }
$.fn.checkRow = function() { $.fn.checkRow = function() {
$(this).children('li').each(function() { //unclicked tiles
if ($(this).hasClass("mine")) { if ($(this).parent('ul').children('li:not(.revealed):not(.flagged)').length > 0) {
return false; return false;
} }
//unclicked //incorrectly flagged tiles
if (!$(this).hasClass("flagged") && !$(this).hasClass("mine") && !$(this).hasClass("revealed")) { if ($(this).parent('ul').children('li.flagged:not(.mine)').length > 0) {
return false; return false;
} }
});
//clicked mines
if ($(this).parent('ul').children('li.revealed.mine').length > 0) {
return false;
}
return true; return true;
} }
@ -232,19 +262,20 @@
} }
$.fn.leftClick = function() { $.fn.leftClick = function() {
if ($(this).hasClass("flagged")) {
return;
}
//don't want first click to be a mine //don't want first click to be a mine
if (firstClick && $(this).getGameboardPos().mine) { if (firstClick && $(this).getGameboardPos().mine) {
$(this).getGameboardPos().mine = false; $(this).getGameboardPos().mine = false;
$(this).removeClass("mine");
}
if ($(this).hasClass("flagged")) {
return;
} }
$(this).getGameboardPos().revealed = true; $(this).getGameboardPos().revealed = true;
$(this).addClass("revealed"); $(this).addClass("revealed");
if ($(this).getGameboardPos().mine && !firstClick) { if ($(this).getGameboardPos().mine == true) {
//game over, or lose a life, or whatever //game over, or lose a life, or whatever
$(this).addClass("mine"); $(this).addClass("mine");
} else { } else {
@ -253,12 +284,43 @@
); );
$(this).addClass("mines" + $(this).countMinesAdjacent()); $(this).addClass("mines" + $(this).countMinesAdjacent());
//if no mines adjacent, cascade!
if ($(this).countMinesAdjacent() == 0) {
$(this).getAdjacentTiles().filter(':not(.revealed)').mousedown();
}
} }
//if no mines adjacent, cascade! if (false && $(this).checkRow()) {
if ($(this).countMinesAdjacent() == 0) { //hide this row and add a new one at the bottom
$(this).getAdjacentTiles().filter(':not(.revealed)').mousedown();
var x = $(this).getX();
var y = $(this).getY();
//remove row from game board
//gameBoard.splice(y, 1);
console.debug(gameBoard);
//add new row at bottom
gameBoard.push(newRow());
$(this).parent('ul').slideUp("slow", function() {$(this).remove();});
//redo the numbers on the rows above and below
//add new row on bottom
$('#game').append('<ul></ul>');
for (var i = 0; i < gameBoard[0].length; i++) {
if (gameBoard[gameBoardHeight][i].mine) {
$('#game ul:last-child').append('<li class="mine"></li>');
} else {
$('#game ul:last-child').append('<li></li>');
}
}
} }
firstClick = false;
} }
$.fn.middleClick = function() { $.fn.middleClick = function() {