From 8f37393fa64995a3aa500079081f5ead66c2a41c Mon Sep 17 00:00:00 2001 From: Joe Anderson Date: Tue, 16 Feb 2016 07:41:36 -0800 Subject: checkered background, colored help text --- oo.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'oo.py') diff --git a/oo.py b/oo.py index 850a620..8ee61a5 100644 --- a/oo.py +++ b/oo.py @@ -238,10 +238,15 @@ class ooPlay: self.puzzle.random_orients() self.screen.clear() + # set up colors + curses.start_color() + curses.init_color(curses.COLOR_GREEN, 0, 300, 0) + 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) + # draw the help area and board state self.help_ind = 0 - border_line = self.X * "═" - self.screen.addstr(self.Y - 2, 0, border_line) self.write() self.display() @@ -262,7 +267,8 @@ class ooPlay: piece = self.puzzle.pieces [x, y] orient = self.puzzle.orients[x, y] string = self.PIECE_ORIENT_TO_STRING[piece][orient] - self.screen.addstr(y, x, string) + color = curses.color_pair((x + y) % 2) + self.screen.addstr(y, x, string, color) self.screen.refresh() def display(self): @@ -272,7 +278,8 @@ class ooPlay: piece = self.puzzle.pieces [x, y] orient = self.puzzle.orients[x, y] string = self.PIECE_ORIENT_TO_STRING[piece][orient] - self.screen.addstr(y, x, string) + color = curses.color_pair((x + y) % 2) + self.screen.addstr(y, x, string, color) self.screen.refresh() pause_length = 80 @@ -298,12 +305,15 @@ class ooPlay: if pause == None: pause = True width = self.X - 1 + color = curses.color_pair(int(pause)) + border_line = self.X * "═" + self.screen.addstr(self.Y - 2, 0, border_line, color) # writing a string that fits in the width if len(string) <= width: centered_string = string.center(width, " ") - self.screen.addstr(self.Y - 1, 0, centered_string) + self.screen.addstr(self.Y - 1, 0, centered_string, color) self.screen.refresh() if pause: curses.napms(2 * self.pause_length * len(string)) curses.ungetch(0) # clear input @@ -312,11 +322,11 @@ class ooPlay: # scrolling through a wider string strings = [string[i:i + width] for i in range(len(string) - width + 1)] - self.screen.addstr(self.Y - 1, 0, strings[0]) + self.screen.addstr(self.Y - 1, 0, strings[0], color) self.screen.refresh() curses.napms(self.pause_length * width) for s in strings: - self.screen.addstr(self.Y - 1, 0, s) + self.screen.addstr(self.Y - 1, 0, s, color) self.screen.refresh() curses.napms(self.pause_length) if pause: curses.napms(self.pause_length * width) -- cgit v1.2.3-70-g09d2