diff options
| author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-11-01 17:19:27 +0200 |
|---|---|---|
| committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-11-01 17:19:27 +0200 |
| commit | 394959f11cdf5493673d60df4cb7a98683fc6afc (patch) | |
| tree | eca0c9cee6c95ecc299270b5de519d3c28043e06 | |
| parent | ae319acbf4c29551be07c1406c434e129a84b51e (diff) | |
| download | SnakePuzzle-394959f11cdf5493673d60df4cb7a98683fc6afc.tar.gz SnakePuzzle-394959f11cdf5493673d60df4cb7a98683fc6afc.zip | |
fix: boxes pushable through tail
| -rw-r--r-- | Game.py | 6 | ||||
| -rw-r--r-- | Snake.py | 8 |
2 files changed, 7 insertions, 7 deletions
@@ -47,7 +47,7 @@ class Game: walls = None def __init__(self): - self.snake = Snake([Vec2(6, 6), Vec2(6, 7), Vec2(6,8), Vec2(7,8)], self) + self.snake = Snake([Vec2(6, 6), Vec2(6, 7), Vec2(6,8), Vec2(7,8), Vec2(8, 8), Vec2(9, 8)], self) _box1 = Box(Vec2(11, 4)) _box2 = Box(Vec2(3, 10)) self.boxes = [_box1, _box2] @@ -59,7 +59,7 @@ class Game: # # # h # # t # -# tt # +# tttt # # # # b # # ### # @@ -79,6 +79,8 @@ class Game: boxAt = next(filter(lambda box: box.pos == pos, self.boxes), None) if self.walls.wallAt(pos): return False + elif pos in self.snake.cells: + return False elif boxAt != None: if self.enter(pos + inDir, inDir): boxAt.pos = pos + inDir @@ -16,13 +16,11 @@ class Snake: def move(self): nextPos = self.cells[0] + self.heading + last = self.cells.pop() if self.game.enter(nextPos, self.heading): - if nextPos in self.cells[1:len(self.cells)-1]: - self.hasCollided = True - else: - self.cells.pop() - self.cells.insert(0, nextPos) + self.cells.insert(0, nextPos) else: + self.cells.append(last) self.hasCollided = True def head(self): |
