MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / move

Function move

Python/snake.py:30–56  ·  view source on GitHub ↗

Move snake forward one segment.

()

Source from the content-addressed store, hash-verified

28
29
30def move():
31 """Move snake forward one segment."""
32 head = snake[-1].copy()
33 head.move(aim)
34
35 if not inside(head) or head in snake:
36 square(head.x, head.y, 9, 'red')
37 update()
38 return
39
40 snake.append(head)
41
42 if head == food:
43 print('Snake:', len(snake))
44 food.x = randrange(-15, 15) * 10
45 food.y = randrange(-15, 15) * 10
46 else:
47 snake.pop(0)
48
49 clear()
50
51 for body in snake:
52 square(body.x, body.y, 9, 'black')
53
54 square(food.x, food.y, 9, 'green')
55 update()
56 ontimer(move, 100)
57
58
59setup(420, 420, 370, 0)

Callers 2

countAndSayMethod · 0.85
snake.pyFile · 0.85

Calls 4

insideFunction · 0.85
updateFunction · 0.85
printFunction · 0.50
popMethod · 0.45

Tested by

no test coverage detected