-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.js
More file actions
59 lines (50 loc) · 1.12 KB
/
Copy pathgrid.js
File metadata and controls
59 lines (50 loc) · 1.12 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let gameState = 0;
let grid = [];
const gameScreen = document.getElementById("game")
const statuses = {
snake:"snake",
apple:"apple",
empty: "empty",
head: "head",
}
class Gridspace {
constructor(status,x,y,element){
this._x = x;
this._y = y;
this._status = status;
this._element = element;
this._element.className = status;
}
set x(x){
this._x = x;
}
get x(){
return this._x
}
set y(y){
this._y = y;
}
get y(){
return this._y
}
set status(status){
this._status = status;
this._element.className = status;
}
get status(){
return this._status
}
}
function createGrid(){
for (let y = 0; y < 40; y++){
let row = [];
for (let x = 0; x < 40; x++) {
const element = document.createElement("div");
gameScreen.appendChild(element);
tile = new Gridspace(statuses.empty,x,y,element)
row.push(tile)
}
grid.push(row)
}
}
createGrid()