-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.js
82 lines (62 loc) · 1.97 KB
/
javascript.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
document.addEventListener("DOMContentLoaded", () => {
const grid = document.querySelector(".grid");
let squares = Array.from(document.querySelectorAll(".grid div")); //query selector functions exactly as getElementById in this program.
const ScoreDisplay = document.querySelector("#score");
const StartBtn = document.querySelector("#start-button");
const width = 10;
const lTetromino = [
[1, width+1, width*2+1, 2],
[width, width+1, width+2, width*2+2],
[1, width+1, width*2+1, width*2],
[width, width*2, width*2+1, width*2+1]
]
const oTetromino = [
[0, 1, width, width+1],
[0, 1, width,width+1],
[0, 1, width, width+1],
[0, 1, width, width+1]
]
const zTetromino = [
[0, width, width+1, width*2+1],
[width+1, width+2, width*2, width*2+1],
[0, width, width+1, width*2+1],
[width+1, width+2, width*2, width*2+1]
]
const tTetromino = [
[1, width, width+1, width+2],
[1, width+1, width+2, width* 2+1],
[width, width+1, width+2, width*2+1],
[1, width, width+1, width*2+1]
]
const iTetromino = [
[1, width+1, width*2+1, width*3+1],
[width, width+1, width+2, width+3],
[1, width+1, width*2 + 1, width*3+1],
[width, width+1, width+2, width+3]
]
const theTetrominoes = [lTetromino, zTetromino, tTetromino, oTetromino, iTetromino];
let currentPosition = 3;
let random = Math.floor(Math.random()*theTetrominoes.length);
console.log(random)
let current = theTetrominoes[0][0];
//Below adds the tetromino
function draw(){
current.forEach(index => {
squares[currentPosition + index].classList.add("tetromino")
});
}
//Below removes the tetromino
function undraw(){
current.forEach(index => {
squares[currentPosition + index].classList.remove("tetromino")
});
}
//Make the tetrominoes move down every second
timerId = setInterval(moveDown, 1000);
function moveDown(){
undraw();
currentPosition += width;
draw()
}
// ++EAJ++
})