diff --git a/package.json b/package.json index af37d53..0d05bce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minesweeper", - "version": "0.0.9", + "version": "0.0.10", "description": "Just Minesweeper!", "author": "Felix W. Dekker", "browser": "dist/bundle.js", diff --git a/src/main/js/index.js b/src/main/js/index.js index 7c66233..e3aaab0 100644 --- a/src/main/js/index.js +++ b/src/main/js/index.js @@ -30,6 +30,9 @@ class Game { this.display = new Display(this.canvas, this.field); this.display.startDrawLoop(); + this.leftDown = false; + this.rightDown = false; + this.solverForm.addEventListener( "submit", @@ -57,7 +60,18 @@ class Game { ); this.canvas.addEventListener( "mousedown", - event => event.preventDefault() + event => { + event.preventDefault() + + switch (event.button) { + case 0: + this.leftDown = true; + break; + case 2: + this.rightDown = true; + break; + } + } ); this.canvas.addEventListener( "mouseup", @@ -67,13 +81,23 @@ class Game { const square = this.display.posToSquare({x: event.clientX, y: event.clientY}); switch (event.button) { case 0: - square.uncover(); + if (this.leftDown && this.rightDown) + square.chord(); + else + square.uncover(); + + this.leftDown = false; break; case 1: square.chord(); break; case 2: - square.flag(); + if (this.leftDown && this.rightDown) + square.chord(); + else + square.flag(); + + this.rightDown = false; break; }