Allow chording with LMB+RMB

Fixes #5.
This commit is contained in:
Florine W. Dekker 2020-07-28 21:25:49 +02:00
parent 18d17cbe3b
commit e9b4f7749e
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
2 changed files with 28 additions and 4 deletions

View File

@ -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",

View File

@ -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;
}