blob: 5679d75c428a25da54b4e085e08c885ee505b90f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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", () => {})
|