class GameArea:
def __init__(self, *, win: "curses window", highscore_file: str):
self.win = win
- height, width = win.getmaxyx()
+ self.height, self.width = win.getmaxyx()
self.tiles = [
- [TileContents.Wall for _ in range(width)],
- *[[TileContents.Wall] + [TileContents.Empty for _ in range(width - 2)] + [TileContents.Wall] for _ in range(height - 3)],
- [TileContents.Wall for _ in range(width)],
+ [TileContents.Wall for _ in range(self.width)],
+ *[[TileContents.Wall] + [TileContents.Empty for _ in range(self.width - 2)] + [TileContents.Wall] for _ in range(self.height - 3)],
+ [TileContents.Wall for _ in range(self.width)],
]
- self.snake = [(height // 2, width // 2)]
+ self.snake = [(self.height // 2, self.width // 2)]
self.fruit = []
self.tiles[self.snake[0][0]][self.snake[0][1]] = TileContents.Snake
self.dir = Direction.Right
def pause(self):
self.paint()
- height, width = self.win.getmaxyx()
- self.win.addstr(height // 2, (width - 6) // 2, 'PAUSED')
+ self.win.addstr(self.height // 2, (self.width - 6) // 2, 'PAUSED')
self.win.refresh()
sleep(1)
self.win.nodelay(False)
def game_over(self):
self.paint()
- height, width = self.win.getmaxyx()
- self.win.addstr(height // 2, (width - 9) // 2, 'GAME OVER')
+ self.win.addstr(self.height // 2, (self.width - 9) // 2, 'GAME OVER')
if self.score > self.orig_highscore:
- self.win.addstr(height // 2 + 2, (width - 10) // 2, 'HIGH SCORE')
+ self.win.addstr(self.height // 2 + 2, (self.width - 10) // 2, 'HIGH SCORE')
self.win.refresh()
self.win.nodelay(False)
while True: