Example #1
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    stdscr.addstr("Hello World\n")
    curses.getch()
    curses.endwin()
    return 0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()

    curses.move(5, 0)
    stdscr.addstr("Hello World (move)")
    for i in range(50):
        stdscr.addstr(10, i, "Hello World")
        curses.getch()

    curses.endwin()
    return 0
Example #3
0
def game_main_loop():
    running = 1
    week = 1
    while (week < 10):
        curses.erase()
        curses.mvaddstr(1, 1, "Tervetuloa Manageri: ")
        curses.addstr(name)
        curses.mvaddstr(2, 1, "VIIKKO ")
        curses.addstr(week)
        curses.addstr("/50")
        week += 1

        curses.getch()
Example #4
0
File: snake1.py Project: mawunka/tz
def get_key(current_direction):

    # utility function to control snake with users input
    
    KEY = curses.getch()    
    if KEY == UP:
        if current_direction == DOWN:
            return DOWN
        else:
            return UP
    elif KEY == DOWN:
        if current_direction == UP:
            return UP
        else:
            return DOWN        
    elif KEY == RIGHT:
        if current_direction == LEFT:
            return LEFT
        else:
            return RIGHT
    elif KEY == LEFT:
        if current_direction == RIGHT:
            return RIGHT
        else:
            return LEFT
    elif KEY == 27:
        return 27
    else:
        return current_direction
Example #5
0
def checkUserExit():
    """Check if the user wants to quit the application."""

    key = unicurses.getch()
    if (key > 0 and chr(key) == "q"):
        return True
    return False
Example #6
0
def mainmenu():
    menu_x = 15
    menu_y = 5
    cursor_location = menu_y

    key = 0
    while (key != 10):
        curses.mvaddstr(menu_y, menu_x, "1. Uusi peli")
        curses.mvaddstr(menu_y + 2, menu_x, "2. Lataa peli")
        curses.mvaddstr(menu_y + 4, menu_x, "3. Poistu")
        curses.mvaddstr(cursor_location, menu_x - 4, "->")

        key = curses.getch()
        if (key == 258 and cursor_location < menu_y + 4):
            curses.mvaddstr(cursor_location, menu_x - 4, "  ")
            cursor_location += 2

        elif (key == 259 and cursor_location > menu_y):
            curses.mvaddstr(cursor_location, menu_x - 4, "  ")
            cursor_location -= 2

    if (cursor_location == 5):
        return 1
    elif (cursor_location == 7):
        return 2
    elif (cursor_location == 9):
        return 3
Example #7
0
 def kbhit():
     ch = getch()
     if ch != ERR:
         ungetch(ch)
         return True
     else:
         return False
Example #8
0
 def kbhit():
     ch = getch()
     if ch != ERR:
         ungetch(ch)
         return True
     else:
         return False
Example #9
0
def main():

    if not curses.has_colors():
        print("Your terminal emulator needs to have colors.")
        return 0

    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        curses.update_panels()
        curses.doupdate()

        while True:
            key = curses.getch()
            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Example #10
0
def speed_menu():

    # main loop for speed menu

    global SPEED

    while True:
        reset_game()
        menu.draw_snake()
        menu.speed_menu()
        menu.speed_cursor(SPEED)

        KEY = curses.getch()

        if KEY == 27 or KEY == 10 or KEY == 459:
            break

        if KEY == RIGHT and SPEED > 1:
            SPEED -= 1
            menu.speed_menu()
            menu.speed_cursor(SPEED)

        if KEY == LEFT and SPEED < 10:
            SPEED += 1
            menu.speed_menu()
            menu.speed_cursor(SPEED)
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    try:
        max_y, max_x = curses.getmaxyx(stdscr)
        coords = str((max_y, max_x))
        stdscr.addstr(max_y // 2, max_x // 2 - len(coords) // 2, coords)
        curses.move(max_y - 1, max_x - 1)
        curses.getch()
    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        curses.getch()
    finally:

        curses.endwin()

    return 0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    try:
        while True:
            c = curses.getch()
            if c == 27:
                break

            stdscr.addstr(
                10, 0, "Keycode was %s and the key was %s" %
                (format(c, '>3'), chr(c)))
            curses.move(0, 0)
    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        curses.getch()
    finally:

        curses.endwin()

    return 0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        window = curses.newwin(3, 20, 5, 5)
        window.addstr(1, 1, "Hey there!")
        window.box()

        window2 = curses.newwin(3, 20, 4, 4)
        window2.addstr(1, 1, "Hey there, again!")
        window2.box()

        panel = curses.new_panel(window)
        panel2 = curses.new_panel(window2)

        #curses.move_panel(panel, 10, 30)

        curses.update_panels()
        curses.doupdate()

        top_p = None

        while True:
            key = curses.getch()
            if key == 27:
                break

            top_p = panel if top_p is panel2 else panel2
            curses.top_panel(top_p)

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Example #14
0
def newgame():
    global name
    curses.erase()
    curses.mvaddstr(1, 1, "UUSI PELI")
    curses.mvaddstr(3, 1, "Kirjoita nimesi:")
    curses.echo()
    curses.move(4, 1)
    name = curses.getstr().decode(encoding="utf-8")
    curses.noecho()

    curses.mvaddstr(12, 1, name)
    curses.mvaddstr(10, 1, "Onko tiedot oikein? (K/E)")
    while 1:
        key = curses.getch()
        if (check_key(key, "k") or key == 27):
            break
        elif (key == ord('e') or key == ord('E')):
            newgame()
Example #15
0
def main():

    if not curses.has_colors():
        print("Your terminal emulator needs to have colors.")
        return 0

    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        avatar = Player(stdscr, "@", curses.COLOR_RED, curses.COLOR_BLACK,
                        curses.A_BOLD)

        curses.attron(curses.color_pair(1))
        curses.vline("|", 10)
        curses.hline("-", 10)
        curses.attroff(curses.color_pair(1))

        while True:
            key = curses.getch()

            avatar.move(key)

            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_GREEN)
        curses.init_pair(2, curses.COLOR_RED, curses.COLOR_GREEN)

        dude = curses.newwin(1, 1, 10, 30)
        curses.waddstr(dude, "@", curses.color_pair(2) + curses.A_BOLD)
        dude_panel = curses.new_panel(dude)

        grass = curses.newwin(10, 50, 5, 5)
        grass.bkgd(" ", curses.color_pair(1))
        grass_panel = curses.new_panel(grass)

        curses.top_panel(dude_panel)

        curses.update_panels()
        curses.doupdate()

        while True:
            key = curses.getch()
            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Example #17
0
def get_key(current_direction):

    # utility function to control snake with users input
    # doctest for main functions
    #'''
    #>>> get_key(DOWN)
    #258
    #>>> get_key(UP)
    #259
    #>>> get_key(LEFT)
    #261
    #>>> get_key(RIGHT)
    #260
    #>>> get_key(27)
    #27
    #'''
    KEY = curses.getch()
    if KEY == UP:
        if current_direction == DOWN:
            return DOWN
        else:
            return UP
    elif KEY == DOWN:
        if current_direction == UP:
            return UP
        else:
            return DOWN
    elif KEY == RIGHT:
        if current_direction == LEFT:
            return LEFT
        else:
            return RIGHT
    elif KEY == LEFT:
        if current_direction == RIGHT:
            return RIGHT
        else:
            return LEFT
    elif KEY == 27:
        return 27
    else:
        return current_direction
Example #18
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()
Example #19
0
def main_menu():

    # main loop for main menu

    global CURSOR

    while True:
        curses.nodelay(stdscr, False)
        menu.draw_snake()
        menu.main_menu()
        menu.main_cursor(CURSOR)
        KEY = curses.getch()

        if KEY == UP and CURSOR > 0:
            CURSOR -= 1
        elif KEY == DOWN and CURSOR < 2:
            CURSOR += 1
        elif KEY == 27:
            reset_game()
            break

        elif KEY == 10 or KEY == 459:

            if CURSOR == 0:
                reset_game()
                curses.wborder(stdscr)
                game(SPEED)

            elif CURSOR == 1:
                reset_game()
                speed_menu()
                reset_game()

            elif CURSOR == 2:
                reset_game()
                break
Example #20
0
        # Add menubar to window's drawing order
        win.add_widget("menu", menu)

        textbox = Textbox(win, 0, 3, 5, win.maxx / 2, label="<Clicks>")
        # TODO: raise drawing error when win.maxy, 3
        textbox.add_line("Start")
        textbox.add_line("clicking")
        win.add_widget("textbox", textbox)

        # Main loop
        while True:
            # Draw window and child widgets
            win.draw()

            # Get keys
            c = uni.getch()

            # Quit
            if c in QUIT_KEYS:
                break

            # Open submenus with corresponding key
            if c in menu.menukeys.keys():
                # Clear any opened menus
                menu.reset()

                # Show submenu by keypress
                menu.show_submenu(c)

            if c == uni.KEY_MOUSE:
                click = Click()
Example #21
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()
Example #22
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()
Example #23
0
def peekkey():
    key = curses.getch()
    curses.ungetch(key)
    #debug(key)
    return key_to_string(key)
Example #24
0
def getkey():
    """Retrieve input character from user as a readable string."""
    key = curses.getch()
    #debug(key)
    return key_to_string(key)
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()
    if keypress == 113:
        break
Example #26
0
    def __init__(self):
        self.turn =1
        
        #Create debugging display
        debug_win = uc.newwin(15, 30, 0, 0)
        uc.box(debug_win)
        uc.wmove(debug_win, 1, 1)
        uc.waddstr(debug_win, "Debug:")
        uc.wmove(debug_win, 2, 1)

        debug_pnl = uc.new_panel(debug_win)
        uc.move_panel(debug_pnl, glob.CAM_HEIGHT, 32)

        #Generate the world
        self.world = Map(glob.N_HEX_ROWS, glob.N_HEX_COLS, debug_win)

        #map_height: 3 + 2*(rows-1) + 2 for border
        #map_width: 5 + 4*cols + 2 for border
        map_win = uc.newwin(glob.CAM_HEIGHT, glob.CAM_WIDTH, 0, 0)


        self.painter = Painter(glob.N_HEX_ROWS, glob.N_HEX_COLS, map_win)
        self.painter.updateAllTiles(self.world)

        #Put world window into a panel
        map_pnl = uc.new_panel(map_win)
        uc.move_panel(map_pnl, 1, 1)

        uc.top_panel(debug_pnl)

        self.status_win = uc.newwin(10, 30, 0, 0)
        uc.box(self.status_win)
        uc.wmove(self.status_win, 1, 1)
        uc.waddstr(self.status_win, "Turn " + str(self.turn))

        status_pnl = uc.new_panel(self.status_win)
        uc.move_panel(status_pnl, glob.CAM_HEIGHT, 2)

        self.tile_window = TileWindow()

        self.painter.drawWindow()
        showChanges()

        
        
        #input loop
        while True:
            sys.stdout.flush()
            ch = uc.getch()
            uc.waddstr(debug_win, str(ch))
            #Exit Key
            if ch == Key.ESC:
                break
            #Movement Keys
            elif ch == Key.E:
                self.movePlayer(HexDir.UL)
            elif ch == Key.R:
                self.movePlayer(HexDir.UR)
            elif ch == Key.S:
                self.movePlayer(HexDir.L)
            elif ch == Key.G:
                self.movePlayer(HexDir.R)
            elif ch == Key.D:
                self.movePlayer(HexDir.DL)
            elif ch == Key.F:
                self.movePlayer(HexDir.DR)
            #End Turn Key
            elif ch == Key.SPACE:
                self.incrementTurn()
            #Camera Scrolling Keys
            #TBD: Remaining order checks
            elif ch == uc.KEY_UP:
                self.painter.moveCamera(0, -1*glob.CAM_SPEED)
            elif ch == uc.KEY_DOWN:
                self.painter.moveCamera(0, glob.CAM_SPEED)
            elif ch == uc.KEY_LEFT:
                self.painter.moveCamera(-1*glob.CAM_SPEED, 0)
            elif ch == uc.KEY_RIGHT:
                self.painter.moveCamera(glob.CAM_SPEED, 0)
            #Toggle drawing borders
            elif ch == Key.B:
                self.painter.draw_borders = not self.painter.draw_borders
                self.painter.updateAllTileBorders(self.world)
                self.painter.drawWindow()
my_panels[0] = uni.new_panel(my_wins[0])
#my_panels[1] = uni.new_panel(my_wins[1])
#my_panels[2] = uni.new_panel(my_wins[2])

uni.set_panel_userptr(my_panels[0], my_panels[1])
#uni.set_panel_userptr(my_panels[1], my_panels[2])
#uni.set_panel_userptr(my_panels[2], my_panels[0])

uni.update_panels()

# Turn on color text for header
#uni.attron(uni.COLOR_PAIR(4))
#uni.mvaddstr(0, int(NCOLS / 2) - 2, "Use tab to browse through the windows (Q to Exit)")
# Turn off
#uni.attroff(uni.COLOR_PAIR(4))
uni.doupdate()

top = my_panels[2]

ch = -1
while ((ch != uni.CCHAR('q')) and (ch != uni.CCHAR('Q'))):
    ch = uni.getch()
    if ch == 9:
        top = uni.panel_userptr(top)
        uni.top_panel(top)
    uni.update_panels()
    uni.doupdate()

uni.endwin()