-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
50 lines (41 loc) · 778 Bytes
/
main.js
File metadata and controls
50 lines (41 loc) · 778 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
41
42
43
44
45
46
47
48
49
50
'use strict';
var keys1 = {
39:'right',
37:'left',
38:'up',
40:'down'
};
var keys2 = {
68:'right',
65:'left',
87:'up',
83:'down'
}
var mySnake1 = new Snake(0, 0, keys1);
var mySnake2 = new Snake(BLOCK, BLOCK, keys2);
var mySnakes2 = [mySnake1, mySnake2];
var mySnakes1 = [mySnake1];
var myBoard;
function setBoard() {
if (check.checked) {
myBoard = new Board(mySnakes2);
}
else {
myBoard = new Board(mySnakes1);
}
};
function gameLoop(run) {
if(run) {
myBoard.clear();
myBoard.border();
myBoard.draw();
}
};
function initiateGame() {
setBoard();
myBoard.setFood();
myBoard.start();
isRun = true;
};
start.addEventListener('click', function(){ initiateGame() });
setInterval(function(){ gameLoop(isRun) }, SPEED);