def _print_menu(self): ansi.write("\r") for index, option in enumerate(self._get_window()): option = option.text option = self._adjust_width(option) ansi.write(self._decorate(option, **self._decorate_flags(index)) + "\n") ansi.clear_eol()
def _print_menu(self): self.parent._print_menu() for i in xrange(0, self.host.height - len(self.host.options)): ansi.clear_eol() ansi.write("\n") if self.text is not None: ansi.write("/" + "".join(self.text)) ansi.show_cursor() ansi.clear_eol()
def onCell(game, x1, y1, x2, y2, state): cursor.save() cursor.set(x2 * 2 + x1 * 7 + 1, y2 * 2 + y1 * 6 + 1) color.bg('black') if state == Player.P1: color.fg('blue') write('X') else: color.fg('yellow') write('O') color.reset() cursor.restore() flush()
def onTurn(game, player): global last color.bg('black') if last: color.fg('white') drawGrid(last[0], last[1]) last = game.nextGrid() if last: color.fg('green') drawGrid(last[0], last[1]) cursor.set(21, 1) color.reset() if player == Player.P1: color.fg('blue') else: color.fg('yellow') write(player.name + "'s turn") cursor.set(1, 18) flush()
def drawBoard(): screen.clear() color.bg('black') color.fg('white') for i in range(17): write(' \n') for i in range(3): for j in range(3): drawGrid(i, j) color.fg('magenta') for i in range(2): cursor.set(1, 6 * i + 6) write('=====##=====##=====') for i in range(3): for j in range(5): cursor.set(6, j + 6 * i + 1) write('||') cursor.set(13) write('||') color.reset() write('\n') flush()
def drawGrid(x, y): for i in range(3): cursor.set(x * 7 + 2, y * 6 + 2 * i + 1) write('|') cursor.set(x * 7 + 4) write('|') for i in range(2): cursor.set(x * 7 + 1, y * 6 + 2 * i + 2) write('-+-+-')
def onEnd(game, player): cursor.set(21, 2) color.reset() if player == Player.P1: color.fg('blue') write("P1 wins!") elif player == Player.P2: color.fg('yellow') write("P2 wins!") else: write("It's a draw") cursor.set(1, 18) color.reset() flush()
def onChanged(game, x, y, state): cursor.save() if state == Player.P1: color.bg('blue') elif state == Player.P2: color.bg('yellow') else: color.bg('white') for i in range(3): for j in range(3): cursor.set(i * 2 + x * 7 + 1, j * 2 + y * 6 + 1) color.fg('black') p = game.getCell(x, y, i, j) if p == Player.P1: write('X') elif p == Player.P2: write('O') else: write(' ') color.reset() cursor.restore() flush()
def show(self): import keyboard ansi.hide_cursor() self._print_menu(rewind=False) try: for key in keyboard.keyboard_listener(): if key == "enter": self._clear_menu() ansi.write(self.options[self.cursor]) return self.options[self.cursor] elif key == "esc": self._clear_menu() ansi.write("<esc>") return None elif key == "left": self.cursor = max(0, self.cursor - 1) elif key == "right": self.cursor = min(len(self.options) - 1, self.cursor + 1) self._print_menu(rewind=True) finally: ansi.show_cursor() ansi.write("\n")
def _clear_menu(self): menu = self._make_menu(_decorate=False) ansi.write("\b"*len(menu)+" "*len(menu)+"\b"*len(menu))
def _print_menu(self, rewind): menu = self._make_menu() if rewind: menu = "\b"*len(self._make_menu(_decorate=False)) + menu ansi.write(menu)
def _print_menu(self): ansi.write(ansi.colorize(self.title + "\n", "white", bright=True)) return self.parent._print_menu()