From e1fca872760bafd619a2e9863ceaa013e4ce7494 Mon Sep 17 00:00:00 2001 From: Fredrik Jensen Date: Tue, 5 Sep 2017 22:02:24 +0200 Subject: [PATCH] working example :tada: --- README.md | 6 +++++- src/index.js | 13 +++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 02579e0..09e2481 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,8 @@ A snake implementation with vanilla JavaScript -🚨 work in progress 🚨 \ No newline at end of file +🚨 work in progress 🚨 + +``` +yarn start +``` \ No newline at end of file diff --git a/src/index.js b/src/index.js index 9519d64..7c5ea2a 100644 --- a/src/index.js +++ b/src/index.js @@ -16,6 +16,7 @@ createDivElement('board', { height: `${unit * dimensions.height}px`, width: `${unit * dimensions.width}px`, position: 'relative', + fontSize: '0', }); /** @@ -41,7 +42,7 @@ const showSnake = () => { for(var i = 0; i < snake.body; i++) { const logEvent = snake.log[snake.log.length - (1 + i)]; - setDivCOlor( + setDivColor( 'yellow', (logEvent || {}).x, (logEvent || {}).y, @@ -53,7 +54,7 @@ const hideSnake = () => { for(var i = 0; i < snake.body; i++) { const logEvent = snake.log[snake.log.length - (1 + snake.body + i)]; - setDivCOlor( + setDivColor( '#000', (logEvent || {}).x, (logEvent || {}).y, @@ -148,6 +149,9 @@ const makeFood = () => { const x = random(1, config.dimensions.width); const y = random(1, config.dimensions.height); + const snakeLength = snake.log.length - 1; + const snakeBody = snake.log.slice((snakeLength - snake.body), snakeLength); + if (find(snakeBody, { x, y })) { console.log('food placed under the snake...'); /** @@ -160,10 +164,7 @@ const makeFood = () => { food.x = x; food.y = y; - const snakeLength = snake.log.length - 1; - const snakeBody = snake.log.slice((snakeLength - snake.body), snakeLength); - - setDivCOlor('red', x, y); + setDivColor('red', x, y); }; /**