def drawData(data, x, y): for i in range(len(data)): v = data[i] for j in range(height): c = ' ' if (j <= v - 1): c = '#' unicurses.mvaddstr(y + height - 1 - j, x + i, c)
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()
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)
def main(): stdscr = curses.initscr() curses.keypad(stdscr, True) curses.curs_set(False) curses.noecho() curses.start_color() select = mainmenu() curses.erase() if (select == 3): pass elif (select == 2): curses.mvaddstr(1, 1, "Lataa peli") elif (select == 1): newgame() create_game() game_main_loop() curses.endwin()
def timeStep(gameBoard): """Take one time step on the game of life board and return the game board in its next generation.""" newBoard = [[DEAD_STATE] * COLUMNS_WITH_PADDING for row in range(ROWS_WITH_PADDING)] for y in range(1, GAME_BOARD_ROWS+1): for x in range(1, GAME_BOARD_COLUMNS+1): aliveNeighbours = countLiveNeighbours((y, x), gameBoard) if gameBoard[y][x] == ALIVE_STATE: if aliveNeighbours < 2 or aliveNeighbours > 3: newBoard[y][x] = DEAD_STATE else: newBoard[y][x] = ALIVE_STATE else: if (aliveNeighbours == 3): newBoard[y][x] = ALIVE_STATE unicurses.mvaddstr((BOARD_FRAME_Y_OFFSET + y) - 1, (BOARD_FRAME_X_OFFSET + x) - 1, gameBoard[y][x]) return newBoard
def printGameBoardFrame(): """Draw a frame in the terminal which surrounds the game of life board.""" unicurses.init_pair(2, unicurses.COLOR_GREEN, unicurses.COLOR_BLACK) unicurses.attron(unicurses.COLOR_PAIR(2)) for frameWidthCoordinate in range(GAME_BOARD_COLUMNS+2): unicurses.mvaddstr(BOARD_FRAME_Y_OFFSET - 1, (frameWidthCoordinate + BOARD_FRAME_X_OFFSET) - 1, "@") unicurses.mvaddstr(BOARD_FRAME_Y_OFFSET + GAME_BOARD_ROWS, (frameWidthCoordinate + BOARD_FRAME_X_OFFSET) - 1, "@") for frameHeightCoordinate in range(GAME_BOARD_ROWS+2): unicurses.mvaddstr((BOARD_FRAME_Y_OFFSET - 1) + frameHeightCoordinate, BOARD_FRAME_X_OFFSET - 1, "@") unicurses.mvaddstr((BOARD_FRAME_Y_OFFSET -1) + frameHeightCoordinate, BOARD_FRAME_X_OFFSET + GAME_BOARD_COLUMNS, "@") unicurses.attroff(unicurses.COLOR_PAIR(2))
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()
def printHeaderMessage(): """Print the header message at the top of the terminal.""" unicurses.init_pair(1, unicurses.COLOR_RED, unicurses.COLOR_BLACK) unicurses.attron(unicurses.COLOR_PAIR(1)) unicurses.mvaddstr(1, 24, "Conway's game of life") unicurses.mvaddstr(4, 24, "Python implementation by: CodingBeagle") unicurses.mvaddstr(7, 24, "Press 'q' to terminate the application") unicurses.attroff(unicurses.COLOR_PAIR(1))
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()
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
return -1 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(
init_wins(my_wins, 3) 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() uni.attron(uni.COLOR_PAIR(4)) uni.mvaddstr(0, int(NCOLS / 2) - 2, "Use tab to browse through the windows (Q to Exit)") 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.mvwaddstr(menu_win, y, x, choices[i]) y += 1 uni.wrefresh(menu_win) 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, "Use arrow keys to go up and down, press ENTER to select a choice") uni.refresh() print_menu(menu_win, highlight) while True: keypress = uni.wgetch(menu_win) if keypress == uni.KEY_UP: if highlight == 1: highlight == n_choices else: highlight -= 1 elif keypress == uni.KEY_DOWN: if highlight == n_choices: highlight = 1 else: highlight += 1
# 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() if click.is_clicked: textbox.add_line(str(click.coords)) uni.mvaddstr(win.maxy, 0, "DEBUG: {0}".format(click.debug)) if c != 539: uni.mvaddstr(win.maxy, 0, "DEBUG: Character pressed: {0}".format(c)) uni.refresh() except Exception as e: raw_input(e) finally: # Quit win.destroy("Goodbye")