26 lines
626 B
Python
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
|