You want to implement a teleporter. Therefore, once the snake is over the edge of the window, you will have to teleport to the other side. The size of your window is 1020×585. The snake is out of the window if x == -15, y == -15, x == 1020 or y == 585 Hence you have to do the following teleportations:
- if x = 1020 teleport to x = 0
- if x = -15 teleport to x = 1005
- if y = 585 teleport to y = 0
- if y = -15 teleport to y = 570
_pos = None
if snake[0][0] == -15:
_pos = (1005, snake[0][1])
elif snake[0][1] == -15:
_pos = (snake[0][0], 570)
elif snake[0][0] == 1020:
_pos = (0, snake[0][1])
elif snake[0][1] == 585:
_pos = (snake[0][0], 0)
if _pos:
snake = [_pos] + snake
del snake[-1]
CLICK HERE to find out more related problems solutions.