Python/snake.py
def move():
    "Move snake forward one segment."
    head = snake[-1].copy()
    head.move(aim)
    if not inside(head) or head in snake:
        square(head.x, head.y, 9, 'red')
        update()
        return

    snake.append(head)

    if head == food:
        print('Snake:', len(snake))
        food.x = randrange(-15, 15) * 10
        food.y = randrange(-15, 15) * 10
    else:
        snake.pop(0)

    clear()

    for body in snake:
        square(body.x, body.y, 9, colorSnake) 

    square(food.x, food.y, 9, colorFood)
    update()
    ontimer(move, 100)
Move snake forward one segment.
Move snake forward one segment.
Move snake forward one segment .
def move():
    head = snake[-1].copy()
    head.move(aim)
    if not inside(head) or head in snake:
        square(head.x, head.y, 9, 'red')
        update()
        return
    snake.append(head)
    if head == food:
        print('Snake:', len(snake))
        food.x = randrange(-15, 15) * 10
        food.y = randrange(-15, 15) * 10
    else:
        snake.pop(0)
    clear()
    for body in snake:
        square(body.x, body.y, 9, colorSnake) 
    square(food.x, food.y, 9, colorFood)
    update()
    ontimer(move, 100)
def move ( ) : head = snake [ - 1 ] . copy ( ) head . move ( aim ) if not inside ( head ) or head in snake : square ( head . x , head . y , 9 , 'red' ) update ( ) return snake . append ( head ) if head == food : print ( 'Snake:' , len ( snake ) ) food . x = randrange ( - 15 , 15 ) * 10 food . y = randrange ( - 15 , 15 ) * 10 else : snake . pop ( 0 ) clear ( ) for body in snake : square ( body . x , body . y , 9 , colorSnake ) square ( food . x , food . y , 9 , colorFood ) update ( ) ontimer ( move , 100 )
Move snake forward one segment.
Move snake forward one segment .
"Move snake forward one segment."