def getch(self):
ch = self.win.getch()
- if ch == curses.KEY_LEFT:
+ if ch == curses.KEY_LEFT or ch == ord('h'):
if self.dir == Direction.Right:
print('\a', end='')
else:
self.dir = Direction.Left
- if ch == curses.KEY_RIGHT:
+ if ch == curses.KEY_RIGHT or ch == ord('l'):
if self.dir == Direction.Left:
print('\a', end='')
else:
self.dir = Direction.Right
- if ch == curses.KEY_UP:
+ if ch == curses.KEY_UP or ch == ord('k'):
if self.dir == Direction.Down:
print('\a', end='')
else:
self.dir = Direction.Up
- if ch == curses.KEY_DOWN:
+ if ch == curses.KEY_DOWN or ch == ord('j'):
if self.dir == Direction.Up:
print('\a', end='')
else:
self.dir = Direction.Down
- if ch == 27 or ch == ord('q'):
+ if ch == 27 or ch == ord('p'):
+ self.pause()
+ if ch == ord('q'):
curses.endwin()
sys.exit(0)
os.makedirs(os.path.dirname(self.highscore_file), exist_ok=True)
with open(self.highscore_file, 'w') as f:
f.write(f'{self.highscore}\n')
+
+ def pause(self):
+ self.paint()
+ height, width = self.win.getmaxyx()
+ self.win.addstr(height // 2, (width - 6) // 2, 'PAUSED')
+ self.win.refresh()
+ sleep(1)
+ self.win.nodelay(False)
+ while True:
+ ch = self.win.getch()
+ if ch == 27 or ch == ord('p'):
+ break
+ if ch == ord('q'):
+ curses.endwin()
+ sys.exit(0)
+ self.win.nodelay(True)
+ self.paint()
def game_over(self):
self.paint()