From a3103caf417899b60519ffde44bc07a15c71b75a Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 30 Oct 2020 23:16:31 +0100 Subject: Added minesweeper start --- utils/minesweeper/index.html | 33 +++++++++++++++++++++++++++++++++ utils/minesweeper/script.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 utils/minesweeper/index.html create mode 100644 utils/minesweeper/script.js diff --git a/utils/minesweeper/index.html b/utils/minesweeper/index.html new file mode 100644 index 0000000..16ab664 --- /dev/null +++ b/utils/minesweeper/index.html @@ -0,0 +1,33 @@ + + + + + cacharle - minesweeper + + + + + +
+

minesweeper

+ +
+ before start + size: + + mine rate: + + +
+ +
+ during +
timer
+ +
+ + + +
+ + diff --git a/utils/minesweeper/script.js b/utils/minesweeper/script.js new file mode 100644 index 0000000..5679d75 --- /dev/null +++ b/utils/minesweeper/script.js @@ -0,0 +1,31 @@ +const height = 10 +const width = 10 +const mine_rate = 0.30 + +let mines = [] +let visited = [] + +for (i = 0; i < height; i++) { + mines.push(new Array(width)) + visited.push(new Array(width)) + for (j = 0; j < width; j++) { + mines[i][j] = Math.random() < mine_rate ? -1 : 0; + visited[i][j] = false; + } +} + +canvas = document.getElementById("minesweeper-canvas") +context = canvas.getContext("2d") +console.log(context) + +const cell_width = canvas.width / width +const cell_height = canvas.height / height +const cell_size = Math.min(cell_width, cell_height) + +for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + context.strokeRect(cell_size * j, cell_size * i, cell_size, cell_size); + } +} + +// canvas.addEventListener("click", () => {}) -- cgit