Skip to content

Instantly share code, notes, and snippets.

@eamonnmcevoy
Last active September 11, 2018 18:42
Show Gist options
  • Save eamonnmcevoy/317af1f67ba25bfafd86e5c55da33ad4 to your computer and use it in GitHub Desktop.
Save eamonnmcevoy/317af1f67ba25bfafd86e5c55da33ad4 to your computer and use it in GitHub Desktop.
class Grid {
...
getFillStyle(state) {
switch (state) {
case 'on':
return 'green';
case 'off':
return 'lightgrey';
case 'food':
return 'purple';
default:
return 'lightgrey';
};
}
}
class Game {
constructor(grid, snake) {
...
this.food = null;
}
async run() {
setInterval(() => {
if (this.food === null) {
const x = Math.floor(Math.random() * (this.grid.width - 1 - 0)) + 0;
const y = Math.floor(Math.random() * (this.grid.height - 1 - 0)) + 0;
this.food = { x, y, isRendered: false };
}
}, 1000);
while (true) {
...
if (this.food) {
if(!this.food.isRendered)
grid.setPoint(this.food, 'food');
this.food.isRendered = true;
}
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment