diff options
-rw-r--r-- | oo.py | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -417,6 +417,8 @@ class ooPlay: # start the main loop self.xpos, self.ypos = 0, 0 + self.max_xpos = self.puzzle.X - 1 + self.max_ypos = self.puzzle.Y - 1 self.keyloop() def new_game(self): @@ -445,6 +447,8 @@ class ooPlay: # return to the main loop self.xpos, self.ypos = 0, 0 + self.max_xpos = self.puzzle.X * (1 + self.toroidal) - 1 + self.max_ypos = self.puzzle.Y * (1 + self.toroidal) - 1 PIECE_ORIENT_TO_STRING = \ [" ", @@ -598,6 +602,7 @@ class ooPlay: self.display_pos(self.xpos, self.ypos) if self.puzzle.is_solved(): inp = self.success() + # if inp is changed by self.success, we catch it here if inp in "Qq": self.write("Quit") return @@ -632,23 +637,15 @@ class ooPlay: + " be toroidal.") self.toroidal = not self.toroidal self.write() - elif inp in "k" and self.ypos > 0: - self.ypos -= 1 - elif inp in "j" and self.ypos < self.puzzle.Y - 1: - self.ypos += 1 - elif inp in "h" and self.xpos > 0: - self.xpos -= 1 - elif inp in "l" and self.xpos < self.puzzle.X - 1: - self.xpos += 1 - - # parse arrow key input - elif inp == curses.KEY_UP and self.ypos > 0: + + # parse arrow/vi key input for motion + if inp in [curses.KEY_UP, "k"] and self.ypos > 0: self.ypos -= 1 - elif inp == curses.KEY_DOWN and self.ypos < self.puzzle.Y - 1: + elif inp in [curses.KEY_DOWN, "j"] and self.ypos < self.max_ypos: self.ypos += 1 - elif inp == curses.KEY_LEFT and self.xpos > 0: + elif inp in [curses.KEY_LEFT, "h"] and self.xpos > 0: self.xpos -= 1 - elif inp == curses.KEY_RIGHT and self.xpos < self.puzzle.X - 1: + elif inp in [curses.KEY_RIGHT, "l"] and self.xpos < self.max_xpos: self.xpos += 1 def main(): |