figure out actions before moving snakes
authorGeoffrey Allott <geoffrey@allott.email>
Sun, 25 Dec 2022 19:42:34 +0000 (19:42 +0000)
committerGeoffrey Allott <geoffrey@allott.email>
Sun, 25 Dec 2022 19:42:34 +0000 (19:42 +0000)
snake.py

index c4cd0aa434e0cd1fd5ee053858acdd82eab151d0..bdad650f5a6e90c5c2502c0dfb44889121bbcd1f 100644 (file)
--- a/snake.py
+++ b/snake.py
@@ -337,12 +337,18 @@ class GameArea:
 
     def update(self):
         self.frame += 1
+        actions = {}
         for snake in self.snakes:
             if not snake.alive: continue
             if not snake.turbo and self.frame % 2 == 0: continue
             snake.slither()
             r, c = snake.segments[-1]
-            action = self.tiles[r][c].action()
+            actions[snake] = self.tiles[r][c].action()
+        for snake in self.snakes:
+            if not snake.alive: continue
+            if not snake.turbo and self.frame % 2 == 0: continue
+            r, c = snake.segments[-1]
+            action = actions[snake]
             if action.is_teleport():
                 self.tiles[r][c] = EmptyTile()
                 r, c = snake.segments[-1] = action.row, action.column