diff options
Diffstat (limited to 'oo.py')
| -rw-r--r-- | oo.py | 56 | 
1 files changed, 38 insertions, 18 deletions
| @@ -409,11 +409,11 @@ class ooPlay:              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 +            n, bit = divmod(n, 2) +            if bit: fg = curses.COLOR_RED    # for showing errors              return fg, bg          for n in range(1, 2**4): @@ -506,17 +506,33 @@ class ooPlay:          """Update one position on the board."""          #TODO: use inverted_pieces and not_inverted_pieces          #      if self.inverted + +        # compute string +          piece, orient = self.puzzle.get_piece_orient(x, y)          string = self.PIECE_ORIENT_TO_STRING[piece][orient] -        is_error = False + +        # compute color + +        is_checker = (x + y) % 2 +        is_cursor  = bool(cursor) +        is_fixed   = self.is_fixed(x, y) +        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)       + -                     8*self.is_fixed(x, y)) + +        color_val = (1*is_checker+ +                     2*is_cursor + +                     4*is_fixed  + +                     8*is_error  )          color = curses.color_pair(color_val) + +        # add string of color +          self.screen.addstr(y, x, string, color) + +        # recurse to equivalent toroidal positions if needed +          if self.puzzle.toroidal and not recursing:              X, Y = self.puzzle.X, self.puzzle.Y              x1 = (x + X) % (2*X) @@ -672,50 +688,54 @@ class ooPlay:              # parse character input              if 0 < inp < 256:                  inp = chr(inp) -                if inp in " \n" and not self.is_fixed(self.xpos, self.ypos): +                if inp in " \n": +                    if self.is_fixed(self.xpos, self.ypos): +                        self.write("fixed piece") +                        self.write() +                        continue                      self.puzzle.rotate_cw(self.xpos, self.ypos)                      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") +                    self.write("quit")                      return                  elif inp in "Rr": -                    self.write("Randomize") +                    self.write("randomize")                      for position in self.fixed:                          self.fixed[position] = False                      self.puzzle.random_orients()                      self.display()                      self.write()                  elif inp in "Nn": -                    self.write("New Game") +                    self.write("new game")                      self.new_game()                  elif inp in "H":                      self.write_help()                  elif inp in "Ss": -                    self.write("Do Not "*self.show_errors + "Show Errors") +                    self.write("do NOT "*self.show_errors + "show errors")                      self.show_errors = not self.show_errors                      self.display()                      self.write()                  #TODO: add in show solution, with undo option                  elif inp in "Ii": -                    self.write("Puzzle is now" +                    self.write("puzzle is now"                               + " NOT"*self.inverted -                             + " inverted.") +                             + " inverted")                      self.inverted = not self.inverted                      self.display()                      self.write()                  elif inp in "Tt": -                    self.write("Next new game will" +                    self.write("next new game will"                               + " NOT"*self.toroidal -                             + " be toroidal.") +                             + " be toroidal")                      self.toroidal = not self.toroidal                      self.write()                  elif inp in "Xx": -                    self.write("Next new game will" +                    self.write("next new game will"                               + " NOT"*self.extra_hard -                             + " be extra hard.") +                             + " be extra hard")                      self.extra_hard = not self.extra_hard                      self.write()                  elif inp in "Ff": | 
