Skip to content

Commit

Permalink
refactor: remove unused functions, use addch rather than addstr when …
Browse files Browse the repository at this point in the history
…appropriate
  • Loading branch information
mecaneer23 committed May 10, 2024
1 parent ab85c2e commit aaa3d69
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions snake.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(
self._body.append(Location(5, 3))

def display(self, stdscr: curses.window) -> None:
stdscr.addstr(
stdscr.addch(
self._head.get_y(),
self._head.get_x(),
self._head_char,
Expand Down Expand Up @@ -155,10 +155,6 @@ def __init__(self, char: str, rows: int, cols: int) -> None:
self._cols = cols
self._location = Location(rows // 2, cols // 2)

def get_char(self) -> str:
"""Return the character used to represent food"""
return self._char

def get_location(self) -> Location:
"""Return the food's current location"""
return self._location
Expand All @@ -176,7 +172,7 @@ def reroll(self, snake: Snake) -> None:
break

def display(self, stdscr: curses.window) -> None:
stdscr.addstr(
stdscr.addch(
self._location.get_y(),
self._location.get_x(),
self._char,
Expand All @@ -190,7 +186,7 @@ class Game:
def _init_board(self) -> None:
for y in range(self._board.get_rows()):
for x in range(self._board.get_cols()):
self._stdscr.addstr(
self._stdscr.addch(
y, x, self._board.get_background_char(), curses.color_pair(1)
)

Expand Down Expand Up @@ -227,14 +223,6 @@ def __init__(
for obj in (self._food, self._snake):
obj.display(self._stdscr)

def get_board(self) -> Board:
"""Return the board object"""
return self._board

def get_snake(self) -> Snake:
"""Return the snake object"""
return self._snake

def get_input(self) -> Direction:
"""
If a key has been pressed, change the
Expand Down Expand Up @@ -309,7 +297,7 @@ def run(self) -> str:
# best_score = update_best_score(score)
else:
new_bg = self._snake.pop()
self._stdscr.addstr(
self._stdscr.addch(
new_bg.get_y(),
new_bg.get_x(),
self._board.get_background_char(),
Expand Down

0 comments on commit aaa3d69

Please sign in to comment.