Exemplo n.º 1
0
 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()
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
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('-+-+-')
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
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()
Exemplo n.º 9
0
 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")
Exemplo n.º 10
0
 def _clear_menu(self):
     menu = self._make_menu(_decorate=False)
     ansi.write("\b"*len(menu)+" "*len(menu)+"\b"*len(menu))
Exemplo n.º 11
0
 def _print_menu(self, rewind):
     menu = self._make_menu()
     if rewind:
         menu = "\b"*len(self._make_menu(_decorate=False)) + menu
     ansi.write(menu)
Exemplo n.º 12
0
 def _print_menu(self):
     ansi.write(ansi.colorize(self.title + "\n", "white", bright=True))
     return self.parent._print_menu()