fix some display quirks master
authorGeoffrey Allott <geoffrey@allott.email>
Tue, 27 Dec 2022 09:06:41 +0000 (09:06 +0000)
committerGeoffrey Allott <geoffrey@allott.email>
Tue, 27 Dec 2022 09:06:41 +0000 (09:06 +0000)
snake.py

index 2025c9068198eb1d9a9a4d02b4f1cc7cf1bb82d9..3ceca29ac200ca95019199c795d357f3a489c327 100644 (file)
--- 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()