Skip to content

Commit

Permalink
added game over on self collision,issue iiitl#4
Browse files Browse the repository at this point in the history
  • Loading branch information
Karanagarwal12 committed Mar 14, 2024
1 parent 4dc72d0 commit e9e6781
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ function isCollide(snake) {
if (snake[0].x > 18 || snake[0].x < 0 || snake[0].y > 18 || snake[0].y < 0) {
return true;
}
for (let i = 1; i < snake.length; i++) {
if (snake[i].x === snake[0].x && snake[i].y === snake[0].y) {
return true;
}
}
}
function gameEngine() {
//part1: updating the snake array and food
Expand Down

0 comments on commit e9e6781

Please sign in to comment.