Пример #1
0
    def draw(self):
        if self.game_interface.game_initialized:
            self.field_data_pull = self.game_interface.game.game_map
            x = 1
            y = 1

            for line in self.field_data_pull:
                for cell in line:
                    if cell == ':':
                        mvwaddstr(self.game_field_window, y, x, cell, GREEN_YELLOW)
                    elif cell == '~':
                        mvwaddstr(self.game_field_window, y, x, cell, BLUE_WHITE)
                    elif cell == '#':
                        mvwaddstr(self.game_field_window, y, x, cell, BLACK_RED)
                    elif cell == 'C':
                        mvwaddstr(self.game_field_window, y, x, cell, BLUE_WHITE)
                    else:
                        mvwaddstr(self.game_field_window, y, x, cell, WHITE_BLACK)
                    x += 1
                x = 1
                y += 1
            wrefresh(self.game_field_window)
            if self.selector:
                self.selector.refresh_for_draw()
            update_panels()
            doupdate()
Пример #2
0
 def _activate(self):
     box(self.button_window)
     mvwaddstr(self.button_window, ((self.height + 1) // 2) - 1, (self.width - len(self.name)) // 2 + 1, self.name)
     wbkgd(self.button_window, BLUE_WHITE)
     wrefresh(self.button_window)
     update_panels()
     doupdate()
Пример #3
0
    def render(self, line=None):  # Overwrites existing
        if self.max_line_len > self.width:
            raise SizeError("Content is longer than box.")
        # New window
        self.win = uni.newwin(self.height, self.width, self.ypos, self.xpos)

        # Draw outline
        if self.outline:
            uni.box(self.win, 0, 0)
        # Draw label
        self.draw_label()

        # Make panel
        self.panel = uni.new_panel(self.win)

        # Track the line number currently written
        self.current_line = 0

        # Print content
        for line in self.lines:
            # Print line text on line number
            ix = list(self.lines).index(line)
            line_no = ix + self.ypad
            # Print lines according to the text's index in the list
            uni.mvwaddstr(self.win, line_no, self.xpad, " " * (self.width - 2))
            uni.mvwaddstr(self.win, line_no, self.xpad, line)
            self.current_line += 1
            uni.wrefresh(self.win)
Пример #4
0
    def draw(self):
        if self.game_interface.game_initialized:
            self.field_data_pull = self.game_interface.game.game_map
            x = 1
            y = 1

            for line in self.field_data_pull:
                for cell in line:
                    if cell == ':':
                        mvwaddstr(self.game_field_window, y, x, cell,
                                  GREEN_YELLOW)
                    elif cell == '~':
                        mvwaddstr(self.game_field_window, y, x, cell,
                                  BLUE_WHITE)
                    elif cell == '#':
                        mvwaddstr(self.game_field_window, y, x, cell,
                                  BLACK_RED)
                    elif cell == 'C':
                        mvwaddstr(self.game_field_window, y, x, cell,
                                  BLUE_WHITE)
                    else:
                        mvwaddstr(self.game_field_window, y, x, cell,
                                  WHITE_BLACK)
                    x += 1
                x = 1
                y += 1
            wrefresh(self.game_field_window)
            if self.selector:
                self.selector.refresh_for_draw()
            update_panels()
            doupdate()
Пример #5
0
 def _activate(self):
     box(self.button_window)
     mvwaddstr(self.button_window, ((self.height + 1) // 2) - 1,
               (self.width - len(self.name)) // 2 + 1, self.name)
     wbkgd(self.button_window, BLUE_WHITE)
     wrefresh(self.button_window)
     update_panels()
     doupdate()
Пример #6
0
    def draw_snake(self):

        # draws the snake ascii art

        for y, line in enumerate(asci.splitlines()):
            curses.mvwaddstr(stdscr, y, middlex - 20, line)
        curses.wborder(stdscr)
        curses.refresh()
Пример #7
0
    def speed_cursor(self, location):

        # draws the cursor in speed menu

        for i in range(10):
            curses.mvwaddstr(stdscr, 9, middlex - i + 3, '-')
        curses.mvwaddstr(stdscr, 9, middlex - 7 + location, '#')
        curses.refresh()
Пример #8
0
    def speed_menu(self):

        # draws the speed menu

        curses.mvwaddstr(stdscr, 8, middlex - 7, 'Choose speed')
        curses.mvwaddstr(stdscr, 9, middlex - 7, '<---------->')
        curses.wborder(stdscr)
        curses.refresh
Пример #9
0
    def delete(self, lenght):

        # delete the pixel from snake's tail

        try:
            curses.mvwaddstr(stdscr, *self.reg[self.count - self.lenght], ' ')
            del self.reg[self.count - self.lenght]
        except KeyError:
            pass
Пример #10
0
 def draw_label(self):
     """Draws widget label."""
     if not hasattr(self, "label"):
         raise AttributeError("Widget has no attribute 'label'")
     if (len(self.label) + 2) >= self.width:
         raise SizeError("Label is longer than box.")
     # TODO: label styles
     # if self.label_color_pair > 0:
     # uni.wattron(self.boxwin, uni.COLOR_PAIR(self.label_color_pair))
     uni.mvwaddstr(self.win, 0, self.label_indent, self.label)
Пример #11
0
def print_menu(menu_win, highlight):
    x = 2
    y = 2
    uni.box(menu_win, 0, 0)
    for i in range(0, n_choices):
        if (highlight == i + 1):
            uni.wattron(menu_win, uni.A_REVERSE)
            uni.mvwaddstr(menu_win, y, x, choices[i])
            uni.wattroff(menu_win, uni.A_REVERSE)
        else:
            uni.mvwaddstr(menu_win, y, x, choices[i])
        y += 1
    uni.wrefresh(menu_win)
Пример #12
0
def print_in_middle(win, starty, startx, width, string, color):
    if (win == None): win = stdscr
    y, x = uni.getyx(win)
    if (startx != 0): x = startx
    if (starty != 0): y = starty
    if (width == 0): width = 80
    length = len(string)
    temp = (width - length) / 2
    x = startx + int(temp)
    uni.wattron(win, color)
    uni.mvwaddstr(win, y, x, string)
    uni.wattroff(win, color)
    uni.refresh()
Пример #13
0
 def refresh(self):
     if self.enabled:
         x = 2
         y = 2
         box(self.game_stat_window, 0, 0)
         mvwaddstr(self.game_stat_window, y, x, " " * 127)
         if self.game_interface.game_initialized:
             for param in self.game_interface.game.player.strings_info:
                 wattron(self.game_stat_window, A_REVERSE)
                 mvwaddstr(self.game_stat_window, y, x, param, RED_WHITE)
                 wattroff(self.game_stat_window, A_REVERSE)
                 x += 5 + len(param)
         wrefresh(self.game_stat_window)
         update_panels()
         doupdate()
Пример #14
0
 def refresh(self):
     if self.enabled:
         x = 2
         y = 2
         box(self.game_stat_window, 0, 0)
         mvwaddstr(self.game_stat_window, y, x, " " * 127)
         if self.game_interface.game_initialized:
             for param in self.game_interface.game.player.strings_info:
                 wattron(self.game_stat_window, A_REVERSE)
                 mvwaddstr(self.game_stat_window, y, x, param, RED_WHITE)
                 wattroff(self.game_stat_window, A_REVERSE)
                 x += 5 + len(param)
         wrefresh(self.game_stat_window)
         update_panels()
         doupdate()
Пример #15
0
    def render(self):
        """Show the menubar."""
        #self.make_panels()
        # Box line
        uni.box(self.win, 0, 0)
        # Label
        self.draw_label()

        uni.doupdate()
        self.panel = uni.new_panel(self.win)
        uni.panel_above(self.panel)

        # Print submenu names
        self.update_section_atts()
        self.make_panels()
        for submenu in self.submenus:
            uni.mvwaddstr(self.win, 1, submenu.xpos, submenu.name)
Пример #16
0
 def draw(self, direction):
     
     # draw the pixel
     
     curses.mvwaddstr(stdscr, *self.dot, 'o')           
     if direction == UP:
         self.y -= 1
     if direction == DOWN:
         self.y += 1
     if direction == RIGHT:
         self.x -= 1
     if direction == LEFT:
         self.x += 1
         
     curses.mvwaddstr(stdscr, self.y ,self.x, '#')
     curses.refresh()        
     self.reg[self.count] = (self.y,self.x)   # a register of previous coords
     self.count +=1                           
Пример #17
0
    def render_player_panel(self):
        win, rows, cols = self._init_render_window("player")

        # Draw border.
        uc.box(win)

        self._render_text(win, 1, 2, self.state.get_currently_playing_track().track, cols-3, uc.A_BOLD)
        self._render_text(win, 2, 2, self.state.get_currently_playing_track().album, cols-3, uc.A_BOLD)
        self._render_text(win, 3, 2, self.state.get_currently_playing_track().artist, cols-3, uc.A_BOLD)

        device_info = "{} ({}%)".format(self.state.current_device, self.state.volume)
        self._render_text(win, 7, 2, device_info, cols-3, uc.A_NORMAL)

        for i, action in enumerate(self.state.main_menu["player"]):
            if (i == self.state.main_menu['player'].i) and self.is_active_window("player"):
                style = uc.A_BOLD | uc.A_STANDOUT
            else:
                style = uc.A_NORMAL
            uc.mvwaddstr(win, 5, 2 + i*4, action.title, style)
Пример #18
0
    def render(self):
        """Renders but does not show the widget."""
        # Draw the box line
        self.win = uni.newwin(self.height, self.width, self.ypos, self.xpos)
        if self.outline:
            uni.box(self.win, 0, 0)

        # Label
        self.draw_label()

        # Box fill
        # TODO: color fill

        # Write contents in order
        for line in self.content:
            ix = self.content.index(line) + 2
            uni.mvwaddstr(self.win, ix, 2, line)

        # Only create panel attribute on display
        self.panel = uni.new_panel(self.win)
Пример #19
0
    def close(self):
        prompt_start_x = self.max_x // 2 - 19
        prompt_start_y = self.max_y // 3

        if prompt_start_x < 1:
            prompt_start_x = 1
        if prompt_start_y < 1:
            prompt_start_y = 1

        win_prompt = uc.newwin(3, 38, prompt_start_y, prompt_start_x)
        uc.box(win_prompt, 0, 0)
        uc.mvwaddstr(win_prompt, 1, 1, 'Do you want to close the game? (y|n)')
        uc.wbkgd(win_prompt, uc.COLOR_PAIR(1))
        uc.wrefresh(win_prompt)

        answer = uc.wgetch(stdscr)
        if answer == ord('y') or answer == ord('Y'):
            uc.endwin()
            exit()
        else:
            uc.delwin(win_prompt)
Пример #20
0
    def draw_shipmenu(self):
        uc.wclear(self.win_shipmenu)

        offset_x = 2
        offset_y = 1

        uc.box(self.win_shipmenu, 0, 0)
        uc.wmove(self.win_shipmenu, offset_y, offset_x)
        uc.waddstr(self.win_shipmenu, 'ship menu:')
        offset_y += 2

        for ele in self.menu:
            if (self.on_menu and self.menu_hi == self.menu.index(ele)):
                uc.wattron(self.win_shipmenu, uc.A_REVERSE)
                uc.mvwaddstr(self.win_shipmenu, offset_y, offset_x, ele)
                uc.wattroff(self.win_shipmenu, uc.A_REVERSE)
                offset_y += 2
            else:
                uc.mvwaddstr(self.win_shipmenu, offset_y, offset_x, ele)
                offset_y += 2

        uc.wrefresh(self.win_shipmenu)
Пример #21
0
def game(speed):
    
    snake.food()
    
    # main loop for the game

    global KEY
    curses.nodelay(stdscr, True)
    
    while True:
        
        KEY = get_key(KEY)
        
        if snake.get_status() == 'dead' or KEY == 27:

            # game over
            
            
            curses.clear()
            curses.wborder(stdscr)
            curses.mvwaddstr(stdscr, middley-1, middlex-6, '--GAME OVER--')
            curses.mvwaddstr(stdscr, middley, middlex-8,'Your score is -')
            curses.mvwaddstr(stdscr, middley, middlex+8, snake.lenght - snake.starting_lenght-1)
            curses.mvwaddstr(stdscr, middley+1, middlex-8,'Press Esc to quit')
            
            KEY = choice([RIGHT, LEFT])
            snake.food()
            curses.refresh()
            curses.nodelay(stdscr, False)
            while get_key(KEY) != 27:
               pass 
            reset_game()
            snake.__init__()
            break
                
        
        if snake.get_status() == 'grow':

            # eaten food
            
            snake.food()
            

        
        snake.draw(KEY)
        snake.delete(snake.lenght)
        time.sleep(1/speed/2)        
Пример #22
0
    def main_menu(self):

        # draws the main menu

        curses.wborder(stdscr)
        curses.mvwaddstr(stdscr, 8, middlex - 5, 'New Game')
        curses.mvwaddstr(stdscr, 9, middlex - 5, 'Set Speed')
        curses.mvwaddstr(stdscr, 10, middlex - 5, 'Quit')
        curses.refresh()
Пример #23
0
def get_messages():
    old_messages = ''
    while True:
        if kill_thread:
            break
        time.sleep(0.05)
        while True:
            try:
                sock = socket.socket()
                sock.connect((HOST, PORT))
                sock.sendall(bytes(channel + chr(0) + chr(2), "utf-8"))
                recvd = sock.recv(1024).decode().split('||')
                count = recvd[0]
                users = recvd[1].split('|')
                ctypes.windll.kernel32.SetConsoleTitleA(bytes(channel + ": " + str(count) + " user(s) online", "utf-8"))
                u.wclear(people_win)
                u.box(people_win)
                i = 1
                u.mvwaddstr(people_win, i, 1, ' Users in #%s:' % channel)
                for user in users:
                    i += 1
                    u.mvwaddstr(people_win, i, 1, '  - ' + user)
                u.wrefresh(people_win)
                sock = socket.socket()
                sock.connect((HOST, PORT))
                break
            except (ConnectionRefusedError, ConnectionResetError):
                u.mvwaddstr(chat_win, 1, 1, "Can't connect.")
                time.sleep(1)
        sock.sendall(bytes(channel + chr(0) + chr(1), "utf-8"))
        incoming_messages = str(sock.recv(4096), "utf-8")
        if not incoming_messages == old_messages:
            i = 0
            u.wclear(chat_win)
            draw_boxes()
            for message in get_latest(incoming_messages.split('\n')):
                i += 1
                u.mvwaddstr(chat_win, i, 1, message[:78])
            u.wrefresh(chat_win)
            old_messages = incoming_messages
        time.sleep(0.1)
Пример #24
0
 def _refresh(self):
     x = 2
     y = 2
     box(self.menu_window, 0, 0)
     for i in range(0, len(self.topics)):
         if self.topics_pointer == i:
             wattron(self.menu_window, A_REVERSE)
             mvwaddstr(self.menu_window, y, x, self.topics[i])
             wattroff(self.menu_window, A_REVERSE)
         elif i in self.locked_topics:
             wattron(self.menu_window, A_UNDERLINE)
             mvwaddstr(self.menu_window, y, x, self.topics[i])
             wattroff(self.menu_window, A_UNDERLINE)
         else:
             mvwaddstr(self.menu_window, y, x, self.topics[i])
         y += 1
     wrefresh(self.menu_window)
     update_panels()
     doupdate()
Пример #25
0
 def _refresh(self):
     x = 2
     y = 2
     box(self.menu_window, 0, 0)
     for i in range(0, len(self.topics)):
         if self.topics_pointer == i:
             wattron(self.menu_window, A_REVERSE)
             mvwaddstr(self.menu_window, y, x, self.topics[i])
             wattroff(self.menu_window, A_REVERSE)
         elif i in self.locked_topics:
             wattron(self.menu_window, A_UNDERLINE)
             mvwaddstr(self.menu_window, y, x, self.topics[i])
             wattroff(self.menu_window, A_UNDERLINE)
         else:
             mvwaddstr(self.menu_window, y, x, self.topics[i])
         y += 1
     wrefresh(self.menu_window)
     update_panels()
     doupdate()
Пример #26
0
    def render_footer(self):
        if self.state.is_loading():
            percent = self.state.get_loading_progress()
            text = " " * int(self._cols * percent)
            uc.mvwaddstr(self.stdscr, self._rows-1, 0, text, uc.A_STANDOUT)

        elif self.state.is_adding_track_to_playlist():
            text = "Select a playlist to add this track"
            uc.mvwaddstr(self.stdscr, self._rows-1, 0, text, uc.A_BOLD)

        elif self.state.is_creating_command():
            start_col = 1
            text = "".join(self.state.get_command_query()) + " "
            uc.mvwaddstr(self.stdscr, self._rows-1, start_col, text)
            uc.mvwaddstr(self.stdscr,
                         self._rows-1, start_col+self.state.get_cursor_i(),
                         text[self.state.get_cursor_i()],
                         uc.A_STANDOUT)
        else:
            entry = self.state.current_menu.get_current_list_entry()
            if entry:
                ncols = self._cols-1
                short_str = entry.str(ncols)
                long_str = str(entry)

                # Check if we need to scroll or not.
                if "".join(short_str.split()) == "".join(long_str.split()):
                    uc.mvwaddstr(self.stdscr, self._rows-1, 0, short_str, uc.A_BOLD)
                    # This ensures that we always start form the same position
                    # when we go from a static footer to a long footer that needs rolling.
                    self._footer_roll_index = -200
                else:
                    self._footer_roll_index += 1
                    footer_roll_index = max(0, self._footer_roll_index)
                    footer_roll_index /= 10
                    # Double the string length so that we always uniformly roll
                    # even in the case the entire string length is less than the terminal width.
                    # Also, add a border to easily identify the end.
                    long_str = 2 * (long_str + " | ")
                    text = list(long_str)
                    for _ in xrange(footer_roll_index):
                        text.append(text.pop(0))
                    text = "".join(text)
                    text = text[0:ncols]
                    uc.mvwaddstr(self.stdscr, self._rows-1, 0, text, uc.A_BOLD)

        # Track progress bar
        progress = self.state.get_track_progress()
        if progress:
            percent = float(progress[0])/progress[1]
            text = "-"*int(self._cols*percent)
            self._render_text(self.stdscr, self._rows-2, 0, text, self._cols, uc.A_BOLD)
Пример #27
0
        sock.connect((HOST, PORT))
    except WindowsError:
        print("Can't connect: " + HOST + ':' + str(PORT))
        continue
    break
sock.sendall(bytes(channel + chr(0) + chr(3) + chr(0) + args.user, "utf-8"))
stdscr = u.initscr()
u.curs_set(0)
chat_win = u.newwin(25, 90, 0, 0)
input_win = u.newwin(5, 90, 25, 0)
people_win = u.newwin(30, 30, 0, 90)
message_refresh_thread.start()
while True:
    sock = socket.socket()
    u.wclear(input_win)
    u.mvwaddstr(input_win, 1, 1, '> ')
    refresh()
    u.flushinp()
    data = u.mvwgetstr(input_win, 1, 3)
    send = True
    # if len(data.split()) > 1:
    #     if data.split()[0] == ":send":
    #         file = data.split()[1]
    #         if os.path.exists(file) and not os.path.isdir(file):
    #             bdata = open(file, 'rb').read()
    #             sock.connect((HOST, PORT))
    #             sock.sendall(bytes(channel + chr(0) + chr(5) + chr(0) + file + chr(0) + str(bdata) + "\n", "utf-8"))
    #             sock.close()
    #             send = False
    if data in [":exit", "^C", ":quit", ":q"]:
        break
# Max coords of parent window
maxy, maxx = uni.getmaxyx(stdscr)
menu_height = 3
menu = uni.newwin(menu_height, maxx, 0, 0)
starty, startx = uni.getbegyx(menu)
height, width = uni.getmaxyx(menu)

# Box line
uni.box(menu, 0, 0)
#uni.bkgd(uni.COLOR_PAIR(1))

# Box label

#uni.wattron(menu, uni.COLOR_PAIR(0))
#uni.mvwaddstr(menu, 0, 2, "Garin")
uni.mvwaddstr(menu, 1, 1, "File")
uni.mvwaddstr(menu, 1, len("File") + 2, "Edit")
#uni.wattroff(menu, uni.COLOR_PAIR(0))
uni.refresh()

#uni.bkgd(uni.COLOR_PAIR(1))

#win_show(my_wins[0], label, 0)

panel = uni.new_panel(menu)
#uni.set_panel_userptr(panel, panel)
uni.update_panels()
uni.doupdate()

while True:
    keypress = uni.getch()
Пример #29
0
    def main_cursor(self, location):

        # draws the cursor in main menu

        curses.mvwaddstr(stdscr, 8, middlex - 7, ' ')
        curses.mvwaddstr(stdscr, 9, middlex - 7, ' ')
        curses.mvwaddstr(stdscr, 10, middlex - 7, ' ')

        if location == 0:
            curses.mvwaddstr(stdscr, 8, middlex - 7, '#')
        elif location == 1:
            curses.mvwaddstr(stdscr, 9, middlex - 7, '#')
        else:
            curses.mvwaddstr(stdscr, 10, middlex - 7, '#')
        curses.refresh()