Last active
September 11, 2018 18:42
-
-
Save eamonnmcevoy/317af1f67ba25bfafd86e5c55da33ad4 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 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