-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.js
34 lines (33 loc) · 892 Bytes
/
graphics.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
function graphics_init() {
var container = document.getElementById('game');
var table = document.createElement('table');
table.style.borderCollapse = 'collapse';
container.appendChild(table);
for (y=0;y<Y_SIZE;y++) {
var row = document.createElement('tr');
for (x=0;x<X_SIZE;x++) {
var cell = document.createElement('td');
cell.id = 'cell-' + y + '-' + x;
cell.className = 'cell';
cell.style.width = '10px';
cell.style.height = '10px';
row.appendChild(cell);
}
table.appendChild(row);
}
graphics_loop(); //initialise board
}
function graphics_loop() {
for (y=0;y<Y_SIZE;y++) {
for (x=0;x<X_SIZE;x++) {
colour = board[y][x];
if (selfeat && board[y][x] == SNAKE) {
colour = SELFEAT;
}
else if (tarred && board[y][x] == SNAKE) {
colour = TAR;
}
document.getElementById('cell-' + y + '-' + x).style.backgroundColor = colour;
}
}
}