diff options
-rw-r--r-- | oo.py | 39 |
1 files changed, 16 insertions, 23 deletions
@@ -403,29 +403,21 @@ class ooPlay: 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) + def color_pair(n): + fg = curses.COLOR_WHITE + bg = curses.COLOR_BLACK + n, bit = divmod(n, 2) + if bit: bg = curses.COLOR_GREEN # for checkering + n, bit = divmod(n, 2) + if bit: fg = curses.COLOR_RED # for showing errors + n, bit = divmod(n, 2) + if bit: bg = curses.COLOR_BLUE # for cursor + n, bit = divmod(n, 2) + if bit: fg = curses.COLOR_YELLOW # for fixed + return fg, bg + + for n in range(1, 2**4): + curses.init_pair(n, *color_pair(n)) # initialize flags self.help_ind = 0 @@ -466,6 +458,7 @@ class ooPlay: X = self.X Y = self.Y - 2 self.puzzle = ooPuzzle(X, Y, toroidal = self.toroidal) + #TODO: this implementation of extra_hard can be really slow if self.extra_hard: while True: for piece in self.puzzle.pieces.values(): |