diff options
Diffstat (limited to 'Snake.py')
| -rw-r--r-- | Snake.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Snake.py b/Snake.py new file mode 100644 index 0000000..81c3b0b --- /dev/null +++ b/Snake.py @@ -0,0 +1,23 @@ + +import Vec + +class Snake: + + cells = [] + heading = Vec.up + + def __init__(self, cells): + self.cells = cells + + def move(self): + self.cells.pop() + self.cells.insert(0, self.cells[0] + self.heading) + + def headInTail(self): + res = False + for i in range(1, len(self.cells)): + res = res or (self.cells[0] == self.cells[i]) + return res + + def head(self): + return self.cells[0] |
