-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameplay.js
More file actions
40 lines (36 loc) · 785 Bytes
/
gameplay.js
File metadata and controls
40 lines (36 loc) · 785 Bytes
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
let moves = 0;
function updateOnMouse(cell) {
moves += 1;
if (arePartners()) {
found.push(show[0], show[1]);
status.html("You found a pair!");
}
if (moves >= 3) {
moves = 0;
show.splice(0, show.length);
hideAll();
}
if (found.length == (cols * rows)) {
status.html("You won!");
}
}
function arePartners() {
return show.length == 2 && show[0].partner == show[1];
}
function hideAll() {
for (let x = 0; x < grid.length; x++) {
for (let y = 0; y < grid[x].length; y++) {
grid[x][y].show = false;
}
}
for (let i = 0; i < found.length; i++) {
found[i].show = true;
}
}
function showAll() {
for (let x = 0; x < grid.length; x++) {
for (let y = 0; y < grid[x].length; y++) {
grid[x][y].show = true;
}
}
}