Add snake-example.py
This commit is contained in:
parent
a986ca0001
commit
8c24ed3a95
1 changed files with 26 additions and 0 deletions
26
snake-example.py
Normal file
26
snake-example.py
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue