Good days, I currently have some problem with my snake game food spawning location.
so the picture shows that the green square (snake food), spawned at the end of the right side of the canvas. That’s a section that I coded as a restricted area, where the player loses if they went in it (or should I say the whole first and last row and column are restricted areas). While stopping the snake and resetting the game wasn’t a problem, the snake food (green square) keeps spawning inside the restricted area although I’ve specified the range of its spawn coordinate.
my code :
this.x = (Math.floor(Math.random()*((rows - 1) + 1)) + 1) * box; this.y = (Math.floor(Math.random()*((columns - 1) + 1)) + 1) * box;
where rows = 30, columns = 30, and box=20
could anyone guide me where did I get wrong…thank you.