From 185b6b4aa1f503888077dc8356c3146ec7f106d7 Mon Sep 17 00:00:00 2001 From: Geoffrey Allott Date: Sat, 24 Dec 2022 13:33:22 +0000 Subject: [PATCH] make tile selection more clean --- snake.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/snake.py b/snake.py index 8d72131..79bdd2d 100644 --- 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() -- 2.34.1