From: Geoffrey Allott Date: Tue, 27 Dec 2022 09:06:41 +0000 (+0000) Subject: fix some display quirks X-Git-Url: https://git.pointlesshacks.com/?a=commitdiff_plain;h=58b4014f984858479975611930376407113a7bca;p=snake.git fix some display quirks --- diff --git a/snake.py b/snake.py index 2025c90..3ceca29 100644 --- a/snake.py +++ b/snake.py @@ -138,13 +138,10 @@ class SnakeTile(Tile): def action(self) -> Action: return DeathAction() -class DeadTile(Tile): +class DeadTile(SnakeTile): def char(self) -> str: return 'X' - def action(self) -> Action: - return DeathAction() - class FruitTile(Tile): def __init__(self, life): self.life = life @@ -355,25 +352,28 @@ class GameArea: if any(snake.segments[-1] == s.segments[-1] for s in actions if snake is not s): actions[snake] = DeathAction() for snake in actions: - r, c = snake.segments[-1] + if snake.turbo: + snake.turbo -= 1 + for snake in actions: action = actions[snake] - if action.is_turbo(): - snake.turbo = 100 if not action.is_score(): r0, c0 = snake.segments[0] self.tiles[r0][c0] = EmptyTile() snake.shrink() + for snake in actions: + r, c = snake.segments[-1] + action = actions[snake] self.tiles[r][c] = SnakeTile(snake) + if action.is_turbo(): + snake.turbo = 100 if action.is_teleport(): self.tiles[r][c] = EmptyTile() r, c = snake.segments[-1] = action.row, action.column if action.is_death(): - self.tiles[r][c] = DeadTile() + self.tiles[r][c] = DeadTile(snake) snake.alive = False if not any(snake.alive for snake in self.snakes): self.game_over() - if snake.turbo: - snake.turbo -= 1 if self.score() > self.highscore: self.highscore = self.score() self.write_highscore()