make tile selection more clean
authorGeoffrey Allott <geoffrey@allott.email>
Sat, 24 Dec 2022 13:33:22 +0000 (13:33 +0000)
committerGeoffrey Allott <geoffrey@allott.email>
Sat, 24 Dec 2022 13:33:22 +0000 (13:33 +0000)
snake.py

index 8d72131f338eedd94f1abe15bb562eba516167b6..79bdd2d393606059fb8eec2a2254fba32a0015c2 100644 (file)
--- a/snake.py
+++ b/snake.py
@@ -20,13 +20,13 @@ class TileContents(Enum):
     PortalFruit = "PortalFruit"
     Dead = "Dead"
 
-    def __str__(self):
+    def char(self, *, turbo: bool):
         if self is TileContents.Empty:
             return ' '
         elif self is TileContents.Wall:
             return '#'
         elif self is TileContents.Snake:
-            return '§'
+            return '*' if turbo else '§'
         elif self is TileContents.Fruit:
             return '@'
         elif self is TileContents.TurboFruit:
@@ -79,10 +79,7 @@ class GameArea:
     def paint(self):
         for i, row in enumerate(self.tiles):
             for j, tile in enumerate(row):
-                if not self.turbo:
-                    self.win.addch(i, j, str(tile))
-                else:
-                    self.win.addch(i, j, str(tile).replace('§', '*'))
+                self.win.addch(i, j, tile.char(turbo=self.turbo))
         self.win.addstr(i + 1, 2, f'{self.highscore:04}')
         self.win.addstr(i + 1, j - 6, f'{self.score():04}')
         self.win.refresh()