-
Notifications
You must be signed in to change notification settings - Fork 0
/
others.js
35 lines (33 loc) · 894 Bytes
/
others.js
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
export const getGridData = () => {
const gridComputedStyle = window.getComputedStyle(
document.querySelector("#grid")
)
return {
rows: gridComputedStyle.getPropertyValue("grid-template-rows").split(" ")
.length,
cols: gridComputedStyle.getPropertyValue("grid-template-columns").split(" ")
.length,
}
}
export const controls = snek => {
window.addEventListener("keydown", event => {
switch (event.code) {
case "KeyS":
case "ArrowDown":
if (snek.move !== "up") snek.move = "down"
break
case "KeyW":
case "ArrowUp":
if (snek.move !== "down") snek.move = "up"
break
case "KeyA":
case "ArrowLeft":
if (snek.move !== "right") snek.move = "left"
break
case "KeyD":
case "ArrowRight":
if (snek.move !== "left") snek.move = "right"
break
}
})
}