Skip to content

Commit

Permalink
Update minesweeper.js
Browse files Browse the repository at this point in the history
  • Loading branch information
leomcelroy committed Nov 7, 2022
1 parent 8491d5f commit 5c8f099
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions games/minesweeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ function drawBoard() {

};
};

selectX = Math.min(width()-1, selectX);
selectX = Math.max(0, selectX);
selectY = Math.min(height()-1, selectY);
selectY = Math.max(0, selectY);
addSprite(selectX, selectY, select);
player = getFirst(select);

Expand Down Expand Up @@ -543,7 +546,14 @@ onInput("d", () => {selectX++});
// Open tile
onInput("j", () => {
// Exclude flagged tiles
if (board[selectY][selectX] == -2 ) { return };
if (
board === undefined ||
board[selectY] === undefined ||
board[selectY][selectX] === undefined ||
numbers === undefined ||
numbers[selectY] === undefined ||
numbers[selectY][selectX] === undefined ||
board[selectY][selectX] == -2 ) { return };

if (board[selectY][selectX] == -1) {
lost(); // You opened a mine
Expand All @@ -565,6 +575,12 @@ onInput("j", () => {

// Flag a tile
onInput("l", () => {
if (
board === undefined ||
board[selectY] === undefined ||
board[selectY][selectX] === undefined
) { return };

// Exclude opened tiles
if (board[selectY][selectX] != 0 && board[selectY][selectX] != -1 && board[selectY][selectX] != -2 ) { return };

Expand Down

0 comments on commit 5c8f099

Please sign in to comment.