Snake game by python code.
import turtle import random w = 500 h = 500 fs = 10 d = 100 # milliseconds offsets = { "up": (0, 20), "down": (0, -20), "left": (-20, 0), "right": (20, 0) } def r(): global saap, kata, khanaT, pen saap = [[0, 0], [0, 20], [0, 40], [0, 60], [0, 80]] kata = "up" khanaT = nun() food.goto(khanaT) hall() def hall(): global kata new_head = saap[-1].copy() new_head[0] = saap[-1][0] + offsets[kata][0] new_head[1] = saap[-1][1] + offsets[kata][1] if new_head in saap[:-1]: r() else: saap.append(new_head) if not khana(): saap.pop(0) if saap[-1][0] > w / 2: saap[-1][0] -= w elif saap[-1][0] < - w / 2: saap[-1][0] += w elif saap[-1][1] > h / 2: saap[-1][1] -= h elif saap[-1][1] < -h / 2: saap[-1][1] += h pen.clearstamps() #clears all the stamps