diff options
| author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-10-26 12:52:34 +0200 |
|---|---|---|
| committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-10-26 12:52:34 +0200 |
| commit | 57f20a5ef761985b34817846d471a064b180e089 (patch) | |
| tree | 9d0029868b9e170bf07ffab9e0386b06b4189837 /Snake.py | |
| download | SnakePuzzle-57f20a5ef761985b34817846d471a064b180e089.tar.gz SnakePuzzle-57f20a5ef761985b34817846d471a064b180e089.zip | |
feat: implemented simple snake game
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] |
