-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
45 lines (34 loc) · 1.11 KB
/
sketch.js
File metadata and controls
45 lines (34 loc) · 1.11 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const rows = 16;
const cols = 16;
// const bombsAmount = Math.floor(rows * cols * 0.2);
const bombsAmount = 40;
let cellWidth = 30;
//display divs
let displayDiv;
const bombsLeftDiv = document.querySelector("#bombCount");
const restartB = document.querySelector("#restart");
const toggleAI = document.querySelector("#toggleAi");
const aiStep = document.querySelector("#aiStep");
restartB.addEventListener(
"click",
() => (board = new Board(cols, rows, bombsAmount))
);
toggleAI.addEventListener("click", () => (board.ai = !board.ai));
aiStep.addEventListener("click", () => aiMove(board));
let board = new Board(cols, rows, bombsAmount);
function mousePressed() {
const col = Math.floor(mouseY / (height / cols));
const row = Math.floor(mouseX / (width / rows));
// Out of bounds
if (col > cols - 1 || row > rows - 1 || col < 0 || row < 0) return false;
if (mouseButton === RIGHT) board.toggleDisable(col, row);
else board.reveal(col, row);
}
function setup() {
let canvas = createCanvas(rows * cellWidth, cols * cellWidth);
canvas.parent("canvas");
frameRate(10);
}
function draw() {
board.show();
}