diff --git a/package.json b/package.json index 5058a6f..052225f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minesweeper", - "version": "0.0.15", + "version": "0.0.16", "description": "Just Minesweeper!", "author": "Felix W. Dekker", "browser": "dist/bundle.js", diff --git a/src/main/index.html b/src/main/index.html index f853c21..3eb6e3f 100644 --- a/src/main/index.html +++ b/src/main/index.html @@ -29,7 +29,7 @@
- +
@@ -40,7 +40,7 @@
- +
diff --git a/src/main/js/index.js b/src/main/js/index.js index da91ab5..8117be7 100644 --- a/src/main/js/index.js +++ b/src/main/js/index.js @@ -14,6 +14,7 @@ class Game { this.canvas = $("#canvas"); this.solveForm = $("#solveForm"); + this.controlForm = $("#controlForm"); this.displayScale = $("#displayScale"); this.settingsForm = $("#settingsForm"); @@ -24,7 +25,7 @@ class Game { this.reset(); this.display = new Display(this.canvas, this.field); - this.display.scale = this.displayScale.value; + this.display.setScale(+this.displayScale.value); this.display.startDrawLoop(); this.leftDown = false; @@ -38,13 +39,15 @@ class Game { new Solver().solve(this.field); } ); + this.controlForm.addEventListener( + "submit", + event => event.preventDefault() + ); this.displayScale.addEventListener( "change", event => { event.preventDefault(); - this.canvas.width = this.field.width * this.displayScale.value; - this.canvas.height = this.field.height * this.displayScale.value; - this.display.scale = this.displayScale.value; + this.display.setScale(+this.displayScale.value); } ); @@ -378,6 +381,17 @@ class Display { ); } + /** + * Rescales the display appropriately. + * + * @param scale {number} the size of a square in pixels + */ + setScale(scale) { + this.scale = scale; + this.canvas.width = this.field.width * this.scale; + this.canvas.height = this.field.height * this.scale + this.scale; + } + /** * Invokes `#draw` in every animation frame of this window. @@ -466,6 +480,15 @@ class Display { ctx.restore(); } + // Draw counter + ctx.save(); + ctx.fillStyle = "#000"; + ctx.font = scale + "px serif"; + ctx.textBaseline = "top"; + ctx.textAlign = "left"; + ctx.fillText(`${this.field.squareList.filter(it => it.hasFlag).length}/${this.field.mineCount}`, 0, (this.field.height) * scale); + ctx.restore(); + // Done } }