Created
September 9, 2018 18:33
-
-
Save eamonnmcevoy/44caa60b6e55048a2aa8b84cc4324cad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Snake { | |
constructor(position) { | |
this.parts = [position]; | |
} | |
update() { | |
let updates = []; | |
updates.push({ | |
point: this.head, | |
state: 'on' | |
}); | |
return updates; | |
} | |
get head() { | |
return Object.assign({}, this.parts[0]); | |
} | |
} | |
... | |
const grid = new Grid(width, height, blockarea, margin, ctx); | |
const snake = new Snake({x:10, y:10}); | |
const updates = snake.update(); | |
updates.forEach(x => { | |
grid.setPoint(x.point, x.state); | |
}); | |
grid.render(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment