summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Anderson <jandew+dev@gmail.com>2016-02-17 05:21:16 -0800
committerJoe Anderson <jandew+dev@gmail.com>2016-02-17 05:21:16 -0800
commit654226a79816c0401e0d9bfffe7ffcb593b0c6fa (patch)
tree4c14624cb5d29fbefb1aac9153c6c06310fa2ca0
parent1760a17b59c0209b19b9513522a499000aac1b15 (diff)
downloadoo-654226a79816c0401e0d9bfffe7ffcb593b0c6fa.tar.gz
oo-654226a79816c0401e0d9bfffe7ffcb593b0c6fa.zip
ooPlay.toroidal fully implemented
-rw-r--r--oo.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/oo.py b/oo.py
index 98f52e6..287b4a1 100644
--- a/oo.py
+++ b/oo.py
@@ -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():