Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions board.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,19 @@ Board.prototype.mineCount = function(x, y) {
* @param {number} x x-coordinate of the square to reveal
* @param {number} y y-coordinate of the square to reveal
* @param {string} [username] username of the person that revealed the square
* @param {boolean} true if this reveal was initiated by a user clicking the square
* as opposed to a recursive call to reveal more 0s
* if this is true and the square is flagged, no changes are made
* @return {Array<Object>} Array of squares that have been changed
*/
Board.prototype.reveal = function(x, y, username) {
Board.prototype.reveal = function(x, y, username, firstClick) {
if (!this.generated) {
this.generate(x, y);
username = 'default';
}

if (this.squares[x][y].revealed)
// Prevent users from erroneously clicking a flagged mine
if (this.squares[x][y].revealed || (firstClick && this.squares[x][y].flagged))
return [];

this.squares[x][y].revealed = true;
Expand Down Expand Up @@ -232,7 +236,7 @@ Board.prototype.reveal = function(x, y, username) {
if (this.squares[x][y].count === 0 && !this.squares[x][y].mine) {
var adjacentSquares = this.getAdjacentSquares(x, y);
for (let i in adjacentSquares)
changedSquares = changedSquares.concat(this.reveal(adjacentSquares[i].x, adjacentSquares[i].y, username));
changedSquares = changedSquares.concat(this.reveal(adjacentSquares[i].x, adjacentSquares[i].y, username, false));
}

return changedSquares;
Expand Down
4 changes: 2 additions & 2 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ Game.prototype.getBoard = function() {
return this.board;
};

Game.prototype.reveal = function(x, y, username) {
Game.prototype.reveal = function(x, y, username, firstClick) {
if (this.resetting)
return [];

var revealedSquares = this.board.reveal(x, y, username);
var revealedSquares = this.board.reveal(x, y, username, firstClick);

if (!this.board.lost)
for (let i in revealedSquares)
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ io.on('connection', (socket) => {
});


socket.on('reveal', (coord) => {
socket.on('reveal', (args) => {
if (game.resetting)
return;

io.to(game.gameId).emit('squares', game.reveal(coord.x, coord.y, username));
io.to(game.gameId).emit('squares', game.reveal(args.x, args.y, username, args.firstClick));
io.to(game.gameId).emit('flag count', game.getBoard().flagCount);
io.to(game.gameId).emit('players', game.getPlayers());

Expand Down
3 changes: 2 additions & 1 deletion js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ socket.on('board', function (board_data) {
if (isCurrentlyRevealMode())
socket.emit('reveal', {
x: parseInt($(this).prop('id').split('-')[0]),
y: parseInt($(this).prop('id').split('-')[1])
y: parseInt($(this).prop('id').split('-')[1]),
firstClick: true
});
else
socket.emit('flag', {
Expand Down
2 changes: 1 addition & 1 deletion js/uglified.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading