RabiRoshan / snake_game

Classic nokia snake game using web.
https://rabiroshan.github.io/snake_game/
MIT License
50 stars 33 forks source link

Food placed on snake #9

Open hansjakobli opened 7 months ago

hansjakobli commented 7 months ago

Hi, ...love the game! Food appears to be placed on the snake, this makes it quite difficult or even impossible to eat the food when the snake gets long. I fixed it as follows in the createFood() method:

// Create new food
  currentFoodPostion = Math.random();
  currentFoodPostion = Math.floor(
    currentFoodPostion * SQUARE_OF_GAME_PIXEL_COUNT
  );
  while (gameBoardPixels[currentFoodPostion].classList.contains("snakeBodyPixel")) {
    currentFoodPostion = Math.random();
    currentFoodPostion = Math.floor(
      currentFoodPostion * SQUARE_OF_GAME_PIXEL_COUNT
    );
  }

Sorry for not creating a proper PR. Cheers

RabiRoshan commented 7 months ago

Hi @hansjakobli , happy to hear that you loved the game. Great work in identifying and fixing the issue. Would love if you could raise a proper PR for this? 😄