Created
September 9, 2018 18:44
-
-
Save eamonnmcevoy/c622f8b1b549044a67d762251b0048a3 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 Game { | |
constructor(grid, snake) { | |
this.grid = grid; | |
this.snake = snake; | |
} | |
async run() { | |
while (true) { | |
this.grid.render(); | |
const updates = this.snake.update(); | |
updates.forEach(x => { | |
this.grid.setPoint(x.point, x.state); | |
}); | |
await this.sleep(delay); | |
} | |
} | |
sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
} | |
... | |
const delay = 50; | |
const grid = new Grid(width, height, blockarea, margin, ctx); | |
const snake = new Snake({x:10, y:10}); | |
const game = new Game(grid, snake, delay); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment