How can i fix this?

u guys can try and paly it

, as u continue to go far the snake always changing the side like when the apple is so far the snake cant get the apple

i dont know where i go wrong but ithnk theres a problem between the height and widht of resolution of the game and snake but i dont know how i can fix that, the problem only occures when the was played in mobile phones

i really need help

this is the code i did in the snake movement

for the snake to repeat its place

my current resolution is 1600 in width and 700 for height