0
0
Fork 0
gists/snake-example.py
2026-05-13 05:19:55 +00:00

26 lines
626 B
Python

# Disclaimer: this code is not complete, it is just an example
class Snake:
def __init__(self):
self.segments = []
self.last_direction = "UP"
self.current_head = (10, 10)
self.size = 3
def move(direction = None):
if direction is None: direction = self.last_direction
if self.current_head == food.location:
food.eat()
self.size += 1
# Draw the new segment, remove the old segment,
# change self.segments as required
self.last_direction = direction
class Food:
def __init__(self):
self.location = (5, 5)
def eat():
# change location, remove drawing, draw new
# location on the board
pass