From 870c905ab720f3d4e9c7d64701da4d7f4a05aa61 Mon Sep 17 00:00:00 2001 From: Joe Anderson Date: Wed, 17 Feb 2016 11:34:48 -0800 Subject: multi-cursor implemented --- oo.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/oo.py b/oo.py index 92213bf..eef3549 100644 --- a/oo.py +++ b/oo.py @@ -400,9 +400,14 @@ 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) curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_GREEN) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_RED, curses.COLOR_GREEN) + 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) # initialize flags self.help_ind = 0 @@ -415,6 +420,7 @@ class ooPlay: self.screen.clear() self.display() self.write() + curses.curs_set(0) # start the main loop self.xpos, self.ypos = 0, 0 @@ -467,7 +473,7 @@ class ooPlay: "┝┯┥┷", "┿┿┿┿"] - def display_subroutine(self, x, y, recursing=False): + def display_subroutine(self, x, y, recursing=False, cursor=None): """Update one position on the board.""" #TODO: use inverted_pieces and not_inverted_pieces # if self.inverted @@ -476,20 +482,23 @@ class ooPlay: is_error = False if self.show_errors: is_error = not self.puzzle.check_piece(x, y) - color = curses.color_pair((x + y) % 2 + 2*is_error) + color_val = (1*(x + y) % 2 + + 2*is_error + + 4*bool(cursor)) + color = curses.color_pair(color_val) self.screen.addstr(y, x, string, color) if self.puzzle.toroidal and not recursing: X, Y = self.puzzle.X, self.puzzle.Y x1 = (x + X) % (2*X) y1 = (y + Y) % (2*Y) - self.display_subroutine(x1, y , recursing=True) - self.display_subroutine(x , y1, recursing=True) - self.display_subroutine(x1, y1, recursing=True) + self.display_subroutine(x1, y , recursing=True, cursor=cursor) + self.display_subroutine(x , y1, recursing=True, cursor=cursor) + self.display_subroutine(x1, y1, recursing=True, cursor=cursor) - def display_pos(self, x, y): + def display_pos(self, x, y, cursor=None): """Update one position on the board, refresh screen.""" - self.display_subroutine(x, y) - if self.show_errors: + self.display_subroutine(x, y, cursor=cursor) + if self.show_errors or cursor: for direction in self.puzzle.DIRECTIONS: x1, y1 = self.puzzle.get_adj_pos(x, y, direction) self.display_subroutine(x1, y1) @@ -601,7 +610,7 @@ class ooPlay: def keyloop(self): """Wait for and parse keypress.""" while True: - self.screen.move(self.ypos, self.xpos) + self.display_pos(self.xpos, self.ypos, cursor=True) inp = self.screen.getch() # parse character input -- cgit v1.2.3-70-g09d2