summaryrefslogtreecommitdiff
path: root/oo.py
diff options
context:
space:
mode:
authorJoe Anderson <jandew+dev@gmail.com>2016-02-18 09:42:14 -0800
committerJoe Anderson <jandew+dev@gmail.com>2016-02-18 09:42:14 -0800
commit8d042354d445c569488eab274c4e21d745d776f0 (patch)
tree74f6dee6bbef7c25fed31a2fd8ae7adaab54f514 /oo.py
parent870c905ab720f3d4e9c7d64701da4d7f4a05aa61 (diff)
downloadoo-8d042354d445c569488eab274c4e21d745d776f0.tar.gz
oo-8d042354d445c569488eab274c4e21d745d776f0.zip
allow pieces to be fixed in place
Diffstat (limited to 'oo.py')
-rw-r--r--oo.py46
1 files changed, 39 insertions, 7 deletions
diff --git a/oo.py b/oo.py
index eef3549..d2c96e5 100644
--- a/oo.py
+++ b/oo.py
@@ -399,22 +399,43 @@ class ooPlay:
# set up colors
curses.start_color()
- curses.init_color(curses.COLOR_GREEN, 0, 300, 0)
- curses.init_color(curses.COLOR_BLUE, 0, 0, 300)
+ if curses.can_change_color():
+ curses.init_color(curses.COLOR_GREEN, 0, 300, 0)
+ curses.init_color(curses.COLOR_BLUE, 0, 0, 300)
+
+ # TODO: try to compactify this section
+ # If the first bit is on, use green background for checkering.
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_GREEN)
+
+ # If the second bit is on, use red text for error.
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_RED, curses.COLOR_GREEN)
+
+ # If third bit is on, use blue background for cursor.
curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(6, curses.COLOR_RED, curses.COLOR_BLUE)
curses.init_pair(7, curses.COLOR_RED, curses.COLOR_BLUE)
+ # If fourth bit is on, use yellow text for fixed.
+ curses.init_pair(8, curses.COLOR_YELLOW, curses.COLOR_BLACK)
+ curses.init_pair(9, curses.COLOR_YELLOW, curses.COLOR_GREEN)
+ curses.init_pair(10, curses.COLOR_YELLOW, curses.COLOR_BLACK)
+ curses.init_pair(11, curses.COLOR_YELLOW, curses.COLOR_GREEN)
+ curses.init_pair(12, curses.COLOR_YELLOW, curses.COLOR_BLUE)
+ curses.init_pair(13, curses.COLOR_YELLOW, curses.COLOR_BLUE)
+ curses.init_pair(14, curses.COLOR_YELLOW, curses.COLOR_BLUE)
+ curses.init_pair(15, curses.COLOR_YELLOW, curses.COLOR_BLUE)
+
# initialize flags
self.help_ind = 0
- self.show_errors = False
self.inverted = False
self.toroidal = False
self.extra_hard = False
+ self.show_errors = False
+ self.fixed = {}
+ for position in self.puzzle.pieces:
+ self.fixed[position] = False
# draw the board state and help area
self.screen.clear()
@@ -455,6 +476,11 @@ class ooPlay:
self.puzzle.set_pieces_from_game_id()
self.puzzle.random_orients()
+ # reset some flags
+ self.show_errors = False
+ for position in self.puzzle.pieces:
+ self.fixed[position] = False
+
# draw the board state and help area
self.screen.clear()
self.display()
@@ -482,9 +508,10 @@ class ooPlay:
is_error = False
if self.show_errors:
is_error = not self.puzzle.check_piece(x, y)
- color_val = (1*(x + y) % 2 +
- 2*is_error +
- 4*bool(cursor))
+ color_val = (1*(x + y) % 2 +
+ 2*is_error +
+ 4*bool(cursor) +
+ 8*self.fixed[x, y])
color = curses.color_pair(color_val)
self.screen.addstr(y, x, string, color)
if self.puzzle.toroidal and not recursing:
@@ -616,7 +643,7 @@ class ooPlay:
# parse character input
if 0 < inp < 256:
inp = chr(inp)
- if inp in " \n":
+ if inp in " \n" and not self.fixed[self.xpos, self.ypos]:
self.puzzle.rotate_cw(self.xpos, self.ypos)
self.display_pos(self.xpos, self.ypos)
if self.puzzle.is_solved():
@@ -627,6 +654,8 @@ class ooPlay:
return
elif inp in "Rr":
self.write("Randomize")
+ for position in self.fixed:
+ self.fixed[position] = False
self.puzzle.random_orients()
self.display()
self.write()
@@ -660,6 +689,9 @@ class ooPlay:
+ " be extra hard.")
self.extra_hard = not self.extra_hard
self.write()
+ elif inp in "Ff":
+ self.fixed[self.xpos, self.ypos] ^= True
+ self.display_pos(self.xpos, self.ypos)
# parse arrow/vi key input for motion
if inp in [curses.KEY_UP, "k"]: