0
0
Fork 0

Add snake-example.py

This commit is contained in:
Oliver 2026-05-13 05:19:55 +00:00
parent a986ca0001
commit 8c24ed3a95

26
snake-example.py Normal file
View file

@ -0,0 +1,26 @@
# 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