Moves the snake in the given direction. Args: direction (Direction): The direction to move the snake. Returns: Point: The new snake head position.
(self, direction)
| 19 | self.direction = Direction.RIGHT |
| 20 | |
| 21 | def move(self, direction): |
| 22 | """Moves the snake in the given direction. |
| 23 | |
| 24 | Args: |
| 25 | direction (Direction): The direction to move the snake. |
| 26 | |
| 27 | Returns: |
| 28 | Point: The new snake head position. |
| 29 | """ |
| 30 | x, y = self.head |
| 31 | if direction == Direction.RIGHT: |
| 32 | x += self.block_size |
| 33 | elif direction == Direction.LEFT: |
| 34 | x -= self.block_size |
| 35 | elif direction == Direction.DOWN: |
| 36 | y += self.block_size |
| 37 | elif direction == Direction.UP: |
| 38 | y -= self.block_size |
| 39 | self.head = Point(x, y) |
| 40 | self.blocks.insert(0, self.head) |
| 41 | return self.head |
| 42 | |
| 43 | def self_collision(self): |
| 44 | """Checks if the snake collides with itself. |