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",
"version": "0.0.27",
"version": "0.0.28",
"description": "Just Minesweeper!",
"author": "Felix W. Dekker",
"browser": "dist/bundle.js",

View File

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