-
Notifications
You must be signed in to change notification settings - Fork 2
/
drawing.js
39 lines (34 loc) · 811 Bytes
/
drawing.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
function drawGame(size) {
var game = $('#game');
for (var i = 0; i < size.x; i++) {
var row = $('<div class="row" />')
for (var j = 0; j < size.y; j++) {
row.append('<span class="cell" />')
}
game.append(row)
}
}
function fillCells(klass) {
var game = $('#game')
return function(ps) {
game.find('.cell').removeClass(klass)
for (var i in ps) {
game.find('.row:eq('+ps[i].y+')')
.find('.cell:eq('+ps[i].x+')')
.addClass(klass)
}
}
}
var drawApple = fillCells('apple')
var drawSnake = fillCells('snake')
function logRestart() {
console.log('press')
$('#log').html("Press 'r' to restart")
}
function logClear() {
$('#log').html('Press left/right to steer.')
}
$score = $('#score')
function setScore(score) {
$score.html(score)
}