Remove mines from starter neighbours as well

Fixes #9.
This commit is contained in:
Florine W. Dekker 2020-07-30 21:26:16 +02:00
parent a167922c00
commit 793da19c00
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
2 changed files with 12 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "minesweeper", "name": "minesweeper",
"version": "0.0.27", "version": "0.0.28",
"description": "Just Minesweeper!", "description": "Just Minesweeper!",
"author": "Felix W. Dekker", "author": "Felix W. Dekker",
"browser": "dist/bundle.js", "browser": "dist/bundle.js",

View File

@ -698,14 +698,18 @@ class Field {
* @param square {Square} the square that was clicked on * @param square {Square} the square that was clicked on
*/ */
onUncover(square) { onUncover(square) {
if (!this.started) this.startTime = Date.now(); if (!this.started) {
if (!this.started && square.hasMine) { this.started = true;
square.hasMine = false; this.startTime = Date.now();
const target = this.squareList
.filter(it => !it.hasMine && it !== square)[0]; const squareAndNeighs = [square].concat(square.getNeighbors());
target.hasMine = true; squareAndNeighs
.filter(it => it.hasMine)
.forEach(it => {
it.hasMine = false;
this.squareList.filter(it => !it.hasMine && squareAndNeighs.indexOf(it) < 0)[0].hasMine = true;
});
} }
this.started = true;
if (!square.hasMine) { if (!square.hasMine) {
this.coveredRemaining = this.squareList.filter(it => !it.hasMine && it.isCovered).length; this.coveredRemaining = this.squareList.filter(it => !it.hasMine && it.isCovered).length;