Beispiel #1
0
def write(scrid, text, ypos, xpos, color="white"):
    uni.setsyx(ypos, xpos)
    uni.waddstr(scrid, text)
    uni.setsyx(0, 0)
    uni.refresh()
    uni.update_panels()
    uni.doupdate()
Beispiel #2
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()
Beispiel #3
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()
Beispiel #4
0
 def draw(self):
     """Draw window and all child widgets."""
     uni.clrtobot()
     uni.refresh()
     # Requires all child widgets to have a show method
     [w.show() for w in self.widgets]
     uni.update_panels()
     uni.doupdate()
Beispiel #5
0
def reset_game():
    '''
    >>> reset_game()
    False
    '''

    curses.clear()
    curses.refresh()
    return False
Beispiel #6
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()
Beispiel #7
0
 def destroy(self, msg="", wait=2):
     """Clears and closes the window with optional message."""
     # Reset cursor position
     if msg:
         self.reset()
         uni.addstr(msg)
         uni.refresh()
         time.sleep(wait)
     uni.endwin()
     sys.exit(0)
Beispiel #8
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()
Beispiel #9
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()
Beispiel #10
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)        
Beispiel #11
0
    def show_submenu(self, key):
        self.open_submenu = self.menukeys[key]
        self.selection = self.open_submenu.panel
        self.selection.show()
        uni.update_panels()

        # Listen for keypress with submenu open
        while True:
            c = uni.wgetch(self.win)
            if c in QUIT_KEYS:
                self.reset()
                break
            elif c in self.open_submenu.actions:  # option_keys
                uni.mvaddstr(win.maxy, 0,
                             "DEBUG: Character pressed: {0}".format(c))
                uni.refresh()
                self.open_submenu.action(c)
Beispiel #12
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                           
Beispiel #13
0
    def __init__(self):  #, stdscreen):
        self.screen = uni.initscr()  #stdscreen
        uni.keypad(self.screen, True)
        uni.curs_set(0)
        uni.noecho()
        uni.cbreak()
        #menuwin = uni.subwin(self.screen, 23, 79, 0, 0)
        menuwin = uni.newwin(10, 40, 0, 0)
        #uni.box(menuwin, 0, 0)
        #uni.hline(2, 1)#, uni.ACS_HLINE, 77)
        #uni.mvwhline(menuwin, 2, 1, uni.ACS_HLINE, 40 - 2)
        uni.new_panel(menuwin)
        uni.refresh()

        submenu_items = [('beep', uni.beep), ('flash', uni.flash)]
        submenu = Menu(submenu_items, self.screen)

        main_menu_items = [('beep', uni.beep), ('flash', uni.flash),
                           ('submenu', submenu.display)]
        main_menu = Menu(main_menu_items, self.screen)
        main_menu.display()
Beispiel #14
0
    def display(self):
        #self.panel.top()
        uni.top_panel(self.panel)
        uni.show_panel(self.panel)
        #self.panel.show()
        uni.clear()  #self.window.clear()

        while True:
            uni.refresh()  #self.window.refresh()
            uni.doupdate()
            for index, item in enumerate(self.items):
                if index == self.position:
                    mode = uni.A_REVERSE
                else:
                    mode = uni.A_NORMAL

                msg = '%d. %s' % (index, item[0])
                uni.mvaddstr(1 + index, 1, msg, mode)

            key = uni.getch()

            if key in [uni.KEY_ENTER, ord('\n')]:
                if self.position == len(self.items) - 1:
                    break
                else:
                    self.items[self.position][1]()

            elif key == uni.KEY_UP:
                self.navigate(-1)

            elif key == uni.KEY_DOWN:
                self.navigate(1)

        uni.clear()  #self.window.clear()
        uni.hide_panel(self.panel)  #self.panel.hide()
        uni.update_panels()  #panel.update_panels()
        uni.doupdate()
    fourier = np.delete(fourier, len(fourier) - 1)
    # Find average 'amplitude' for specific frequency ranges in Hz
    power = np.abs(fourier)
    low = 0
    high = 156.25
    for i in range(8):
        matrix[i] = int(np.mean(power[piff(low) : piff(high) : 1]))
        low = high
        high *= 2
    # Tidy up column values for the LED matrix
    matrix = np.divide(np.multiply(matrix, weighting), 8000000 / height)
    # Set floor at 0 and ceiling at 8 for LED matrix
    matrix = matrix.clip(0, height)
    return matrix

lastTime = time.clock()
frameTime = chunk / sampleRate

data = wavfile.readframes(chunk)
while data != '' and len(data) > 0:
    matrix = calculateLevels(data, chunk)
    drawData(matrix, 0, 0)
    data = wavfile.readframes(chunk)

    unicurses.refresh()
    #key = unicurses.getch()

    now = time.clock()
    time.sleep(max(frameTime - (now - lastTime), 0))
    lastTime = now
Beispiel #16
0
            else:
                return choice + 1
            break

stdscr = uni.initscr()
uni.clear()
uni.noecho()
uni.cbreak()
uni.curs_set(0)
startx = int((80 - WIDTH) / 2)
starty = int((24 - HEIGHT) / 2)

menu_win = uni.newwin(HEIGHT, WIDTH, starty, startx)
uni.keypad(menu_win, True)
uni.mvaddstr(0, 0, "Click on Exit to quit (works best in a virtual console)")
uni.refresh()
print_menu(menu_win, 1)
uni.mouseinterval(0)
uni.mousemask(uni.ALL_MOUSE_EVENTS)


msg = "MOUSE: {0}, {1}, {2}, Choice made is: {3}, Chosen string is: {4}"
while True:
    c = uni.wgetch(menu_win)
    if c == uni.KEY_MOUSE:
        id, x, y, z, bstate = uni.getmouse()
        if bstate & uni.BUTTON1_PRESSED:
            chosen = report_choice(x + 1, y + 1)
            if chosen is not None:
                uni.mvaddstr(23, 0, msg.format(
                    x, y, bstate, chosen, choices[chosen-1]))
Beispiel #17
0
    RED_WHITE = COLOR_PAIR(10)
    CYAN_RED = COLOR_PAIR(11)

    bkgd(COLOR_PAIR(2))

    game_interface = GameInterface()
    game_interface.refresh()
    game_interface.first_launch()

    def kbhit():
        ch = getch()
        if ch != ERR:
            ungetch(ch)
            return True
        else:
            return False

    while True:
        if kbhit():
            key = getch()
            game_interface.key_event(key)
            game_interface.refresh()
        else:
            game_interface.refresh()
        game_interface.draw_tick += 1
        game_interface.draw_tick %= 1000

    refresh()
    clear()
    endwin()
Beispiel #18
0
 def reset(self):
     if self.selection:
         self.selection.hide()
     uni.update_panels()
     uni.refresh()
Beispiel #19
0
    bkgd(COLOR_PAIR(2))

    game_interface = GameInterface()
    game_interface.refresh()
    game_interface.first_launch()


    def kbhit():
        ch = getch()
        if ch != ERR:
            ungetch(ch)
            return True
        else:
            return False


    while True:
        if kbhit():
            key = getch()
            game_interface.key_event(key)
            game_interface.refresh()
        else:
            game_interface.refresh()
        game_interface.draw_tick += 1
        game_interface.draw_tick %= 1000

    refresh()
    clear()
    endwin()
 def clear(self):
     uc.erase()
     uc.move(0, 0)
     uc.clrtobot()
     uc.refresh()
Beispiel #21
0
 def reset(self):
     """Clears the window and sets cursor to (0, 0)."""
     uni.setsyx(0, 0)
     uni.erase()
     uni.refresh()
Beispiel #22
0
def reset_game():
    curses.clear()
    curses.refresh()
    return False