From 57f20a5ef761985b34817846d471a064b180e089 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 26 Oct 2025 12:52:34 +0200 Subject: feat: implemented simple snake game --- Snake.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Snake.py (limited to 'Snake.py') 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] -- cgit v1.2.3